This program compares three different approaches to identify common characters shared between the two character vectors.
- In the project directory, run
maketo generate the file 'main' in the same directory. - Run
./mainto run the program. - The program will request two relative paths to text documents. Please note that example text documents are provided as 'example1.txt' and 'example2.txt'.
- After supplying the two relative paths, the two text documents will be read into vectors.
- Three different approaches as outlined in the "Intersection approaches" section will be executed to assess the common characters shared between both vectors. Execution time in seconds will be outputted.
- A text document with the common characters will be outputted in the project directory called 'common_characters.txt'.
- In the project directory, run
make testto generate the file 'test' in the same directory. - Run
./testto run units tests. - Each unit test will be executed one by one and will output "Success" + the unit test method name if no assertion errors are encountered.
- bruteForceIntersection - Linearly iterates through one vector. The vector present at a given index will then be linear searched in the second vector. Values shared between both vectors will be inserted into a hash set and will be returned upon completion of this method. This is the ineffecient approach we discussed during the interview.
- multiThreadedIntersection - Linearly iterates through one vector. The vector present at a given index will then be searched in the second vector using 3 threads (defaulted to 3 for demonstration purposes). Specifically, the second vector will be split into search ranges and each of the 3 threads will be assigned to one of those ranges. Values shared between both vectors will be inserted into a hash set and will be returned upon completion of this method.
- binaryIntersection - This assumes that the second vector is sorted. Initially, the first vector is iterated through. The vector present at a given index will then be binary searched. Values shared between both vectors will be inserted into a hash set and will be returned upon completion of this method.
makefor building executable 'main' programmake testfor building executable unit test program 'test'make cleancleans up all object and executable files