P.D
BAN USER
Appreciate the comments eugene
I did consider the number of files. I did think through of what the conventional wisdom would say (to combine DS).
I wanted to persist the frequency of words o(1) so it can work for any K input and printing top K will be o(n) leveraging file system sort etc..
Coming back to comments
1. OS will create files as long as disk can accomodate, OS doesnt have any upper limit on file counts (why would OS be overwhelmed, unless Andrew Tanenbaum has a technical explanation of whats the limitation ;-)).
2. Empty *.txt files wont take lot of disk space
3. This solutions just creates files in disk, not even suggesting any IO. I didn't suggest to use file system as Key, value pair.
Tries - How to get word frequency any fancy implementation ? Besides tries will take a lot of memory thats why they came with a variation called Burst tries.
Did the question poster actually meant a MAX-HEAP with word frequency count being the key value? Can you please explain the min-heap plus list approach ?
Inorder traversal and Inversion count is the right
answer !!
But assuming to swap only adjacent nodes may not be a good.
Simply improvise the inversion count algorithm to do a divide and conquer approach with a midpoint for the inorder array and figure out all the swaps required not just adjacent.
Something like this ?
- P.D May 20, 2014