@XYZ: There are up to n numbers to put into the heap, and an insertion into a heap of size k is O(log k).
Dave On Aug 17, 10:42 pm, XYZ <yourarunb...@gmail.com> wrote: > @Dave > > How did you get the complexity as O(n log k) > > On Aug 18, 8:14 am, Dave <dave_and_da...@juno.com> wrote: > > > > > @Aditi: Form a max-heap of the first 100 numbers. Then as you read the > > remaining numbers, if a number is less than the root of the max-heap, > > replace the root with it and restore the heap condition. When you > > reach the end of the million numbers, the heap will contain the > > smallest 100 numbers. > > > If there are n numbers and you want the smallest k, this algorithm is > > O(n log k). > > > Dave > > > On Aug 17, 10:05 pm, aditi garg <aditi.garg.6...@gmail.com> wrote: > > > > How to find the set of smallest 100 numbers out of 1 million numbers... -- 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.