Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jan 9th, 2008, 6:07 PM   #11
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 824
Rep Power: 4 The Dark is on a distinguished road
Re: Hashing In C

I don't think your wasting your time writing your own hashing, its a great learning experience and, as you said, more tailored algorithms can be a lot faster than a generic stl one. That may be critical if the running time is tight.

However, during the contest you are likely to be under time pressure for yourself as well as the code, so maybe using the stl would help you concentrate on the parts of the problem than can't be so easily solved.
The Dark is offline   Reply With Quote
Old Jan 9th, 2008, 6:22 PM   #12
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Posts: 1,827
Rep Power: 5 Sane will become famous soon enough
Re: Hashing In C

Yes, and I'm considering my research time valuable too. Where is it better spent? Learning C++'s STL (when I don't know C++...)? Or researching and learning about different data structures?

It's a tough call, because the time is very limited for the competition. But so is my knowledge of obscure data structures...

My thought right now is that the STL is not powerful enough to cut down implementation time enough, and still be worth the resulting execution time. Will someone challenge that statement? I'd like to hear arguments for both sides here.
Sane is offline   Reply With Quote
Old Feb 11th, 2008, 11:45 PM   #13
rhish.franks
Programmer
 
Join Date: Feb 2008
Location: India
Posts: 58
Rep Power: 1 rhish.franks is on a distinguished road
Re: Hashing In C

Just want to ask, whether dynamic hashing is needed and linear probing has to be used?
rhish.franks is offline   Reply With Quote
Old Feb 21st, 2008, 3:06 AM   #14
Game_Ender
Professional Programmer
 
Game_Ender's Avatar
 
Join Date: May 2006
Location: Maryland, USA
Posts: 306
Rep Power: 3 Game_Ender is on a distinguished road
Re: Hashing In C

This uses the fastest possible associative data structure: an array. That is all you need in this case because you are only dealing with numbers. It could use more memory than the map depending on the ratio of n to the max value of x. It runs in 40% the time of the STL map based version. (Both compiled with -O3)
c Syntax (Toggle Plain Text)
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #define MAX_VAL 10000000
  5.  
  6. int main() {
  7. unsigned int n, x, size, mode=0;
  8. unsigned int* counts = calloc(MAX_VAL, sizeof(unsigned int));
  9.  
  10. freopen("mode.in", "rt", stdin);
  11. scanf("%d\n", &n);
  12.  
  13. while (n--) {
  14. scanf("%d\n", &x);
  15. if (( size = ++counts[x]) > mode) mode = size;
  16. }
  17. printf("%d\n", mode);
  18.  
  19. return 0;
  20. }

Just up and learn the STL it will save you a *ton* of time. It will give you tested, debugged, and optimized data structures and algorithms. That is what you want when you are working under pressure. You don't want to lose because you made a stupid error in your linked list or binary tree, you want to be solving the problem. You can find plenty of STL tutorials on google.
__________________
Robotics @ Maryland AUV Team - Software Lead

Last edited by Game_Ender; Feb 21st, 2008 at 3:18 AM.
Game_Ender is offline   Reply With Quote
Old Feb 21st, 2008, 4:47 AM   #15
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Posts: 1,827
Rep Power: 5 Sane will become famous soon enough
Re: Hashing In C

Well I've found that these years, the problems focus more on Dynamic Programming and Graph Theory than on Data Structures. In which case, the STL will do very little for me. I managed to do last year's Stage 1 competition, in Pure C, with about 40 lines of code for each question. So it's not as needy for standard libraries and pre-written code as I first thought. If I mess up a linked list, I shouldn't be writing the competition at all.
Sane is offline   Reply With Quote
Old Feb 21st, 2008, 10:00 PM   #16
Game_Ender
Professional Programmer
 
Game_Ender's Avatar
 
Join Date: May 2006
Location: Maryland, USA
Posts: 306
Rep Power: 3 Game_Ender is on a distinguished road
Re: Hashing In C

Well nobody is perfect and a line of code you don't have to write is a line of code you don't have to debug.
__________________
Robotics @ Maryland AUV Team - Software Lead
Game_Ender is offline   Reply With Quote
Old Feb 22nd, 2008, 3:49 AM   #17
Kentski
IM A N00B but WILL RISE!
 
Join Date: Feb 2008
Location: Philippines
Posts: 1
Rep Power: 0 Kentski is on a distinguished road
Send a message via MSN to Kentski Send a message via Yahoo to Kentski
Re: Hashing In C

hmmm im just new around the forums and still studying on programming.
so pls dont be bugged if il be asking some terms your using.

i hope everyone will be patient with me here. i just want to learn programming that much to give my grades a boost.

so what is STL by the way?
__________________
IM JUST AN ORDINARY GUY WHO WANTS TO LEARN PROGRAMMING BUT NEEDS HELP FROM OTHER PROGRAMMERS TO MAKE ME ONE OF THE BEST!
Kentski is offline   Reply With Quote
Old Feb 22nd, 2008, 6:04 AM   #18
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Re: Hashing In C

The STL is C++'s Standard Template Library - a collection of lightweight but useful classes, templates, objects and functions you can use in your own programs. The beauty of it is that you can assume any C++ compiler will automatically have access to it.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom Hashing Algorithms Sane C 21 Oct 16th, 2006 9:05 PM
MD5 hashing... Un4given C++ 3 May 31st, 2005 6:51 PM
Hashing Collashing mtanti Coder's Corner Lounge 0 Apr 10th, 2005 11:29 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:37 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC