Which of the following data structures is on average the
fastest for retrieving data:




1) Binary Tree


2) Hash Table


3) Stack

Answer Posted / jbo5112

It depends on what you're looking for. If you want to find
what you just inserted, then a stack would be best. If you
have some sort of key that you're using to search through
the data, then it depends.

A hash table will generally be better, like Shruti said, but
if your container has few values and your key is large, then
doing a binary search might be faster than computing a hash
value for your key. That, of course, requires your Binary
Tree to be sorted and at least somewhat optimized (not all
branching the same direction). If your data is mostly
ordered, it's also possible to optimize your binary tree
search based on your previous search, but that will slow
down random data. I personally use hash tables or...

A fourth option (if memory permits) is to convert your key
to an integer and use an array. This one is quite easy to
implement (Boost even has one that is STL compliant, w/o
vector's overhead), and unless memory cache sizes come
heavily into play, this one is unbeatable. An example would
be looking up a state's name by the two letter abbreviation.
An array of 32768 char*'s isn't much, and on most computers
(including any x86/x86_64) you can simply look it up by
array[*(int*)"NY"].

Is This Answer Correct ?    21 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain c preprocessor?

678


What are the general description for loop statement and available loop types in c?

683


How many types of operator or there in c?

597


write a program in C that prompts the user for today's date,tomorrow's date and display the results.Use structures for today's date,tomorrow's date and an array to hold the days for each month of the year.

4981


In C programming, how do you insert quote characters (‘ and “) into the output screen?

888






write a program to concatenation the string using switch case?

1553


What is the size of empty structure in c?

589


Explain Basic concepts of C language?

640


Explain what’s a signal? Explain what do I use signals for?

606


What is unary operator?

656


Can a pointer be volatile in c?

531


What is zero based addressing?

707


What are the basic data types associated with c?

811


typedef struct{ char *; nodeptr next; } * nodeptr ; What does nodeptr stand for?

1066


In c programming typeing to occupy the variables in memory space. if not useing the variable the memory space is wasted.ok, how to avoid the situation..? (the variable is used & notused)

1631