CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2011
    Posts
    2

    Talking expalin hash table

    hi ever one , can explain hashtable ,how can use it, what is the better (linkedlist or hash table)

  2. #2
    Join Date
    May 2009
    Posts
    2,413

    Re: expalin hash table

    Quote Originally Posted by bady1985 View Post
    hi ever one , can explain hashtable ,how can use it, what is the better (linkedlist or hash table)
    What's better - a hammer or a saw? That depends on what you want to do.

    Same here and there's no shortcut really. You simply have to bite the bullet and open a textbook (for example on Java and data structures, or Java and the collections).

    I found this quite good. It covers generics in the first part and the collections in the second. They kind of go hand in hand.

    http://www.amazon.com/Java-Generics-...34602&sr=8-3#_

  3. #3
    Join Date
    Dec 2011
    Posts
    2

    Re: expalin hash table

    can you explain it ,is it kind of tree or like linkedlist?

  4. #4
    Join Date
    May 2009
    Posts
    2,413

    Re: expalin hash table

    Quote Originally Posted by bady1985 View Post
    can you explain it ,is it kind of tree or like linkedlist?
    It's more like an array actually. In an array you get the element at a certain index position in just one access and accesses to a hash table is almost as fast.

    The idea behind a hash table is that the value of an element determines the position of that element in the table. A hash function is used to define the mapping between the value and the position, like

    index_position = hash_function(element_value)

    Java has two major hash based data structures, the HashSet and the HashMap. The details of the hash function is hidden but you still have to supply part of it by overriding the hashCode() and equals() methods for the classes you want to store. But if you stick to standard types such as Integer and String you don't even have to do that because it's done for you already.

    So you can think of a hash table as a kind of array. It has very fast accesses independent of how many elements are stored just like an array. It's called O(1). Accesses to a tree is slower. They're proportional to the logarithm of how many elements are stored, called O(log N)). Accesses to a linked list is slower still. They're proportional to the number of elements, called O(N).

    These are some of the differences but as I recommended get a textbook because there's a lot more to it and a thorough understanding is very important. Picking the wrong data structures is a sure way to inefficient and slow code.
    Last edited by nuzzle; December 26th, 2011 at 02:20 AM.

Tags for this Thread

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