Re: [algogeeks] Frequency Sort Algo
steps: 1) use hash mapping to keep track of frequency of each and every element. 2)Then iterate hash table and store in 2D array with 1st column(element value) and 2nd column(frequency of element value). 3)sort the row according to second column(i.e frequency). 4)Then Print the element row wise.. . PRAVEEN RAJ DELHI COLLEGE OF ENGINEERING -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Frequency Sort Algo
isn't the solution is counting sort? Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Sat, Dec 24, 2011 at 11:48 PM, atul anand atul.87fri...@gmail.comwrote: first sort the given array , you will get 1,1,1,1,2,2,2,3,3,3,3,3,4,4,5 now count frequency of each number and insert it into min heap. each node contain 2 variable. 1) frequency 2) number now do extract min operation. and expand , for eg:- for node 5 frequency = 0 number =5; write 5 to the given array for node 4 frequency = 2 number =4 write 4,4 to array. for node 2 frequency = 3 number =2 write 2,2,2 to the given array... On Sat, Dec 24, 2011 at 10:57 PM, Ankur Garg ankurga...@gmail.com wrote: how can one do frequency sort . Suppose we have an integer array like 1,2,3,1,2,3,1,1,2,3,4,4,3,5,3 Then 1 is appearing 4 times 2 - 3 3- 5 4-2 5-1 Then if we sort by frequency we shud have this as result 5,4,4,2,2,2,1,1,1,1,3,3,3,3,3 How to do it -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Frequency Sort Algo
@Ashish : not exactly ... you can use counting sort 1st part where you find the frequency of each elements. now u have to select frequency in decreasing order to give the required output. On Tue, Dec 27, 2011 at 7:49 PM, Ashish Goel ashg...@gmail.com wrote: isn't the solution is counting sort? Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Sat, Dec 24, 2011 at 11:48 PM, atul anand atul.87fri...@gmail.comwrote: first sort the given array , you will get 1,1,1,1,2,2,2,3,3,3,3,3,4,4,5 now count frequency of each number and insert it into min heap. each node contain 2 variable. 1) frequency 2) number now do extract min operation. and expand , for eg:- for node 5 frequency = 0 number =5; write 5 to the given array for node 4 frequency = 2 number =4 write 4,4 to array. for node 2 frequency = 3 number =2 write 2,2,2 to the given array... On Sat, Dec 24, 2011 at 10:57 PM, Ankur Garg ankurga...@gmail.comwrote: how can one do frequency sort . Suppose we have an integer array like 1,2,3,1,2,3,1,1,2,3,4,4,3,5,3 Then 1 is appearing 4 times 2 - 3 3- 5 4-2 5-1 Then if we sort by frequency we shud have this as result 5,4,4,2,2,2,1,1,1,1,3,3,3,3,3 How to do it -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Frequency Sort Algo
how can one do frequency sort . Suppose we have an integer array like 1,2,3,1,2,3,1,1,2,3,4,4,3,5,3 Then 1 is appearing 4 times 2 - 3 3- 5 4-2 5-1 Then if we sort by frequency we shud have this as result 5,4,4,2,2,2,1,1,1,1,3,3,3,3,3 How to do it -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Frequency Sort Algo
MinHeap with frequency of data is constructed, then sorting it. But don't see with same frequency it maintains the order of the first appeared element Regards Surender On Sat, Dec 24, 2011 at 10:57 PM, Ankur Garg ankurga...@gmail.com wrote: how can one do frequency sort . Suppose we have an integer array like 1,2,3,1,2,3,1,1,2,3,4,4,3,5,3 Then 1 is appearing 4 times 2 - 3 3- 5 4-2 5-1 Then if we sort by frequency we shud have this as result 5,4,4,2,2,2,1,1,1,1,3,3,3,3,3 How to do it -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Frequency Sort Algo
first sort the given array , you will get 1,1,1,1,2,2,2,3,3,3,3,3,4,4,5 now count frequency of each number and insert it into min heap. each node contain 2 variable. 1) frequency 2) number now do extract min operation. and expand , for eg:- for node 5 frequency = 0 number =5; write 5 to the given array for node 4 frequency = 2 number =4 write 4,4 to array. for node 2 frequency = 3 number =2 write 2,2,2 to the given array... On Sat, Dec 24, 2011 at 10:57 PM, Ankur Garg ankurga...@gmail.com wrote: how can one do frequency sort . Suppose we have an integer array like 1,2,3,1,2,3,1,1,2,3,4,4,3,5,3 Then 1 is appearing 4 times 2 - 3 3- 5 4-2 5-1 Then if we sort by frequency we shud have this as result 5,4,4,2,2,2,1,1,1,1,3,3,3,3,3 How to do it -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Frequency of number
Infinite numbers are coming in a stream . how will you find the frequency of a given number ? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Frequency of number
If we are to find frequency of only one number let us say 35 in infinite coming numbers , do xor operation with coming numbers If the result is 0 increment the value of temp variable by 1 if not scan next input until all numbers are over. On Tue, Sep 27, 2011 at 10:22 PM, Ankuj Gupta ankuj2...@gmail.com wrote: Infinite numbers are coming in a stream . how will you find the frequency of a given number ? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Frequency of number
Take an array a[1000]input first 1000 values from the stream in it.. Here we are representing a unit time with help of space because 1000 elements in a stream will always come in constant time So just count the occurrence of a given number in that array... then divide the count with 1000 that will be frequency... For more accuracy just increase the array size upto what accuracy you want . .. On Tue, Sep 27, 2011 at 11:10 PM, teja bala pawanjalsa.t...@gmail.comwrote: If we are to find frequency of only one number let us say 35 in infinite coming numbers , do xor operation with coming numbers If the result is 0 increment the value of temp variable by 1 if not scan next input until all numbers are over. On Tue, Sep 27, 2011 at 10:22 PM, Ankuj Gupta ankuj2...@gmail.com wrote: Infinite numbers are coming in a stream . how will you find the frequency of a given number ? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] FREQUENCY COUNT FOR TIME
Calculate frequency count for time for the following. #includeiostream #includefstream using namespace std; int main() { ifstream filein; filein.open(datafile.dat,ios::in); int a[100]; int j,k=0,h; filein j; while (filein){ a[k]=j; k++; filein j; } filein.close(); system(pause); return 0; } explain the output plz -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] frequency
use binary tree and insert in it every character u come across. if the character is already present then increment its count. use this approach if u r nt sure that characters will be only 26 or no. if u r sure there r 26 char then u cn use hash.. plz correct me if i m wrong. thanks On 14 May 2010 08:50, sharad kumar aryansmit3...@gmail.com wrote: cant u use a hash map of O(K) where K is distinct elements in string.. On Thu, May 13, 2010 at 8:13 PM, jalaj jaiswal jalaj.jaiswa...@gmail.comwrote: input a character array from the user and output in the following way. example string is amazon.. then output should be a2m1z1o1n1 i did it taking a 26 size array... some better solution ?? -- With Regards, Jalaj Jaiswal +919026283397 B.TECH IT IIIT ALLAHABAD -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- yezhu malai vaasa venkataramana Govinda Govinda -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] frequency
Hi Friend Using HashMap in Java *** /* * input a character array from the user and output in the following way. example string is amazon.. then output should be a2m1z1o1n1 */ package questionaire; import java.util.Collection; import java.util.HashMap; import java.util.Iterator; import java.util.Set; import java.util.Map.Entry; public class Amazon1 { private String str; private HashMapCharacter, Integer checkMap; public Amazon1(String s) { this.str = s; checkMap = new HashMapCharacter, Integer(); } public void checkTheFrequency() { for (int i = 0; i str.length(); i++) { char key = str.charAt(i); if (checkMap.containsKey(key)!=false) { int value = checkMap.get(key); checkMap.put(key, ++value); } else { checkMap.put(key, 1); } } /* * VVI */ SetEntryCharacter,Integer entry = checkMap.entrySet(); IteratorEntryCharacter,Integer iter = entry.iterator(); while(iter.hasNext()) { Entry pair = iter.next(); System.out.print( +pair.getKey()+pair.getValue()+ ); } } public static void main(String[] args) { Amazon1 test = new Amazon1(amazon); test.checkTheFrequency(); } } *** Correct me if I am wrong. On Fri, May 14, 2010 at 3:30 PM, divya jain sweetdivya@gmail.comwrote: use binary tree and insert in it every character u come across. if the character is already present then increment its count. use this approach if u r nt sure that characters will be only 26 or no. if u r sure there r 26 char then u cn use hash.. plz correct me if i m wrong. thanks On 14 May 2010 08:50, sharad kumar aryansmit3...@gmail.com wrote: cant u use a hash map of O(K) where K is distinct elements in string.. On Thu, May 13, 2010 at 8:13 PM, jalaj jaiswal jalaj.jaiswa...@gmail.com wrote: input a character array from the user and output in the following way. example string is amazon.. then output should be a2m1z1o1n1 i did it taking a 26 size array... some better solution ?? -- With Regards, Jalaj Jaiswal +919026283397 B.TECH IT IIIT ALLAHABAD -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- yezhu malai vaasa venkataramana Govinda Govinda -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] frequency
input a character array from the user and output in the following way. example string is amazon.. then output should be a2m1z1o1n1 i did it taking a 26 size array... some better solution ?? -- With Regards, Jalaj Jaiswal +919026283397 B.TECH IT IIIT ALLAHABAD -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] frequency
cant u use a hash map of O(K) where K is distinct elements in string.. On Thu, May 13, 2010 at 8:13 PM, jalaj jaiswal jalaj.jaiswa...@gmail.comwrote: input a character array from the user and output in the following way. example string is amazon.. then output should be a2m1z1o1n1 i did it taking a 26 size array... some better solution ?? -- With Regards, Jalaj Jaiswal +919026283397 B.TECH IT IIIT ALLAHABAD -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- yezhu malai vaasa venkataramana Govinda Govinda -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.