Algorithm Used:
- Read the file from server line by line using fopen() function
- using ' '(Space) as a delimiter segregatted words from the file
- Using hashmap to create (key,value) pair for each unique words ie key = unique words , value = count of those words
- sorted the hashmap according to the value;
- print the top n values among them
Note: for a dynamic file use of heap data structure would have been the best option since it is a static i have used hashmap + sorting technique.
The file is hosted in my domain : http://islamquiz.in/input.php
Go to the above website for real demo.