No, time complexity for 1st is O(n). for 2nd, a quick solution is to make one pass through the array to store the frequency of 1,2,3,4,5. Then using this information, a second pass to fill the array based on freq.
On Wed, Jun 1, 2011 at 10:53 PM, Abhishek Goswami <zeal.gosw...@gmail.com>wrote: > for second question explanation. > > if you have array for 100 element a[100]. and you can enter element into > array from 1 to 5 range upto a[100].So you have array > a[100] which contain number from 1 to 5. what will be efficient algorithm > for arranging number in ascending order.. > ex 1 2 5 5 5 3 4 1 1 upto a[100] > > output : 1 1 1 2 3 4 5 5 5 > > @First question. > What will be time complexity. I believe it will be o(n^2) can it be > implemented in more efficient way.. > > > > > On Wed, Jun 1, 2011 at 10:27 PM, Harshal <hc4...@gmail.com> wrote: > >> the simplest way is to use a hashmap, or an array arr[10000] and keep >> track of the number seen so far, eg. by making arr[num]=1, and checking >> while inserting new elements. >> second question is a bit unclear >> >> >> On Wed, Jun 1, 2011 at 10:04 PM, Abhishek Goswami <zeal.gosw...@gmail.com >> > wrote: >> >>> I am sure this question has come already but can anyone point me answer >>> again. >>> >>> 1.if user enter number 0 to 10000. than what will we algorithum to >>> determine duplicate number (Note : user can not enter more than >>> 10000 number) >>> >>> 2. if we have a number in the range of [1...5] than we insert number >>> randomly into array. how will we arrange element in sorted order. >>> >>> Ex. 1 1 2 4 5 5 5 3 4 >>> >>> 1 1 2 3 4 4 5 5 >>> >>> -- >>> 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. >>> >> >> >> >> -- >> Harshal Choudhary, >> III Year B.Tech CSE, >> NIT Surathkal, Karnataka, India. >> >> >> -- >> 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. > -- Harshal Choudhary, III Year B.Tech CSE, NIT Surathkal, Karnataka, India. -- 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.