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
What does c value mean?
Write a program to generate random numbers in c?
Can two or more operators such as and be combined in a single line of program code?
What is structure padding and packing in c?
What is the difference between declaring a variable by constant keyword and #define ing that variable?
7-Given an index k, return the kth row of the Pascal's triangle. For example, when k = 3, the row is [1,3,3,1]. For reference look at the following standard pascal’s triangle.
Do you know null pointer?
Can you explain what keyboard debouncing is, and where and why we us it? please give some examples
PROGRAM TO WRITE CONTENTS OF 1 FILE IN REVERSE TO ANOTHER FILE,PROGRAM TO COPY 1 FILE TO ANOTHER BY SPECIFYING FILE NAMES AS COMMAND LINE
What is LINKED LIST? How can you access the last element in a linked list?
What does sizeof return c?
Explain the array representation of a binary tree in C.
Write a code to remove duplicates in a string.
Is c compiled or interpreted?
PLS U SENS ME INTERVIEW O. MY EMAIL ADD, SOFIYA.SINGH@GMAIL.COM