Hash tables

This is a discussion on Hash tables within the C Programming forums, part of the General Programming Boards category; I have a task... And idea- and don't know how to implement it. So, we need to create a set ...

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    2

    Wink Hash tables

    I have a task... And idea- and don't know how to implement it.

    So, we need to create a set of integers of 100 000 elements (keys) and a range of 50 000 integers (hash-table). The keys are natural numbers from 1 to 100 thousand. Make your own hash function. The idea of the task is suitable for placing the keys in the hash table until it has a place, and then it stops putting the keys, where the index element in the hash table determines the hash function. If you want to take the place of either the collision. This collision is necessary to calculate and print them on the screen as the only output data. The best hash function = minimum number "crashing"

    My idea for Hash table is:

    Code:
    int hash (int x)
     {
        return (x - 1) % 50000;
     }


    And have a problem to write this in the arrear of code... Can anyone solve my problem and write it?

    Thanx a lot,

    Marie

  2. #2
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,566
    Many people here can solve and write your problem for you, however, nobody here will. Read the following, try it yourself, and come back with your attempt. Then we will help you find your problems. Nobody here wants to do your homework for you (unless perhaps you pay us...but we're professional programmers, expect consulting rates around $100/hour).

    C Board - Announcements in Forum : C Programming
    C Board - Announcements in Forum : General Programming Boards

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
    int hash( void ) { return rand() % 50000; }
    Good enough for who it's for.


    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    Registered User
    Join Date
    Oct 2010
    Posts
    2
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    
    int Unos(long a[], long broj)
    {
    int h, broj1 = broj;
    int br=0;
    int test = 0;
    long N=50000;
    do
    {
    h = broj1;
    if (a[h] < 1)
    {
    a[h] = broj;
    test = 1;
    break;
    }
    else
    {
         broj1++;
         br++;
    }
    } while (broj1 < (broj + N) && test!=0);
    
    
    
    return (br);
    }
    int main()
    {
    long niz[100000],i,a[50000];
    int br=0;
    for(i=0;i<100000;i++)
    niz[i]=i;
    for(i=0;i<50000;i++)
    a[i]=0;
    for(i=0;i<100000;i++)
    
    br=Unos(a,niz[i]);
    br=br+br;
    printf("br =%d",br);
    for(i=0;i<50000;i++)
    printf("%d",a[i]);
    printf("%d",a[0]);
    printf("\n\nbr =%d",br);
        return 0;
    }
    this is what i wrote but don't know how to write hash :S

  5. #5
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,308
    Fix your indentation or I'm not looking at it, and many others will feel the same way.

    Help us, to help you.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. developing hash tables in the C Programming language
    By w108dab in forum C Programming
    Replies: 1
    Last Post: 05-20-2008, 11:20 AM
  2. need help with hash tables with direct chaining
    By agentsmith in forum C Programming
    Replies: 4
    Last Post: 01-05-2008, 03:19 AM
  3. Group Project Help/Volunteer
    By DarkDot in forum C++ Programming
    Replies: 3
    Last Post: 04-24-2007, 11:36 PM
  4. Problems with Hash Tables
    By Zildjian in forum C Programming
    Replies: 6
    Last Post: 11-06-2003, 07:53 PM
  5. Help with beginning hash tables, please.
    By Will in forum C++ Programming
    Replies: 8
    Last Post: 11-17-2002, 08:51 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21