CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 2009
    Posts
    5

    Finding maximum in a Hashtable

    Given an Hashtable, is there a way of finding the maximum element in the hashtable in less than O(n) in the worst case where n is the total number of elements in the Hashtable? In other words, is there a way of finding such an element by means other than doing a linear search?

    HM
    Last edited by humor_me; June 16th, 2009 at 05:44 AM.

  2. #2
    Join Date
    Jul 2005
    Location
    Netherlands
    Posts
    2,042

    Re: Finding maximum in a Hashtable

    A hashtable is unordered, so there is no way to do it faster than O(n).
    Cheers, D Drmmr

    Please put [code][/code] tags around your code to preserve indentation and make it more readable.

    As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky

  3. #3
    Join Date
    Jul 2009
    Posts
    3

    Re: Finding maximum in a Hashtable

    Depends on the function used for hashing. Also depends on the no of digits of the integers we are using. Typically - a radix sort uses this. Worst case is still O(kN) but think of the best case.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured