Given a server with 4 cpu\'s, and no databases write a pseudocode to search for the word camera in 100,000 html documents.

Showing Answers 1 - 3 of 3 Answers

samiksc

  • Jan 12th, 2006
 

Start 4 threads which do the following task:

  1. Opens every nth file (first thread will open 0th, 4th, 8th, 12th file, second thread will open 1st, 5th, 9th and so on)
  2. Scans the file for occurrences of word 'camera' and notes down line numbers (possibly in a hash table -- the key would be the file name with complete path and value will be an array / arraylist containing line numbers)

  Was this answer useful?  Yes

samiksc

  • Jan 12th, 2006
 

The program would be as follows:

  1. start threads scanning every nth file -- 0-4-8-12; 1-5-9-13 etc.
  2. Scan the file for word 'camera' and note down line numbers in a hash table -- the key would be file path and values would be the line numbers.

  Was this answer useful?  Yes

labrynth

  • Mar 13th, 2006
 

but why nth file ? Why not simply divide 100,000 into four groups and have each thread run on a group ..

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions