Saturday, May 10, 2008

Finding occurence count

Given a Integer array, we have to print the occurence count for each Integer. What will be the optimal solution.


best solution is to build a binary search tree...if while searching u come across a NULL ...insert that node there....if while searching u find that element increase the count...Then print each element in the tree by traversing it.

3 comments:

Akash said...

I think that hash Table is a better solution with less complexity. But it needs some space.

Akash said...

I think that Hash Table implementation is a better algo on the cost of space.

Unknown said...

Hash table implementation is suitable when the integers are falling into a certain range say 0 to 100. We can take an array of 100 and the implementation is straight forward.
But say an array which contains only one element 100000. We can not take that much array size. Even if we take a smaller array and implement the hash algo there is always be a chance of collisions.