Which of the following data structures is on average the
fastest for retrieving data:
1) Binary Tree
2) Hash Table
3) Stack
Answers were Sorted based on User's Feedback
Answer / 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 |
Do you know pointer in c?
Is reference used in C?
What is a pragma?
write a program for fibonaci series by using while loop in c?
Can you please explain the difference between syntax vs logical error?
What are pragmas and what are they good for?
in b=6.6/a+(2*a+(3*c)/a*d)/(2/n); which operation will be performed first a) 6.6/a b) 2*a c) 3*c d) 2/n
1)which of following operator can't be overloaded. a)== b)++ c)?! d)<=
Given below are three different ways to print the character for ASCII code 88. Which is the correct way1) char c = 88; cout << c << " ";2) cout.put(88);3) cout << char(88) << " "; a) 1 b) 2 c) 3 d) constant
plz answer....A program that takes 3 variables e.g a,b,c in as seperate parameters and rotates the values stored so that value goes a to b, b to c and c to a .
where are auto variables stored? What are the characteristics of an auto variable?
Why do u use # before include in a C Progam?