We have a string of characters and we want to find characters with second highest frequency in the string. Suggest different algorithms for this?
-
e.g. string = abaabc output = b (since a is appearing 3 times which is highest and b is appearing 2 times which is 2nd highest) e.g string = ababcacad output = b,c need algorithm/logic which is easy to implement for beginner. I don 't want to use hash or other kind of data structure. and so we are not concerned about space/time complexity . looking for simple array/iterative algorithm. My approach: step1 : make a structure with two member (char and int)=(character and frequency) step2: sort structure by frequency in descending order(and of-course sort corresponding characters ). step3: start printing from second index of structure if the frequency of this is not equal to 1st's frequency. ...... and so on .
-
Answer:
Make a hash function and store the frequency of alphabets in a hash table[26] ; then just go through the table to find the second highest !!
Mukul Dilwaria at Quora Visit the source
Related Q & A:
- How to count number of occurrences of pattern within a string?Best solution by Stack Overflow
- How to replace a string inside of a Word Document?Best solution by Stack Overflow
- How can I convert a string number to a number in Perl?Best solution by Stack Overflow
- If you want to find fossils, what kind of rock (igneous,sedimentary, metamorphic) should you look for? why?Best solution by Ask.com old
- I want to find a friend who moved address..... how can i do it.Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.