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



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

Answer / shruti

hash table

Is This Answer Correct ?    26 Yes 4 No

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

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

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

Answer / k.kavitha

3)stack

Is This Answer Correct ?    8 Yes 23 No

Post New Answer

More C Interview Questions

Can a file other than a .h file be included with #include?

0 Answers   Aspire, Infogain,


Write a function stroverlap that takes (at least) two strings, and concatenates them, but does not duplicate any overlap. You only need to worry about overlaps between the end of the first string and the beginning of the second string. Examples: batman, manonthemoon = batmanonthemoon batmmamaman, mamamanonthemoon = batmmamamanonthemoon bat, man = batman batman, batman = batman batman, menonthemoon = batmanmenonthemoon

0 Answers   HCL,


Can we initialize extern variable in c?

0 Answers  


List the difference between a While & Do While loops?

0 Answers   Accenture,


write a program that will read the temperature in Celsius and convert that into Fahrenheit.

1 Answers  






At a shop of marbles, packs of marbles are prepared. Packets are named A, B, C, D, E …….. All packets are kept in a VERTICAL SHELF in random order. Any numbers of packets with these names could be kept in that shelf as in this example: bottom of shelf ---> [AAAJKRDFDEWAAYFYYKK]-----Top of shelf. All these packets are to be loaded on cars. The cars are lined in order, so that the packet could be loaded on them. The cars are also named [A, B, C, D, E,………….]. Each Car will load the packet with the same alphabet. So, for example, car ‘A’ will load all the packets with name ‘A’. Each particular car will come at the loading point only once. The cars will come at the loading point in alphabetical order. So, car ‘B’ will come and take all the packets with name ‘B’ from the shelf, then car ‘C’ will come. No matter how deep in the shelf any packet ‘B’ is, all of the ‘B’ packets will be displaced before the ‘C’ car arrives. For that purpose, some additional shelves are provided. The packets which are after the packet B, are kept in those shelves. Any one of these shelves contains only packets, having the same name. For example, if any particular shelf is used and if a packet with name X is in it, then only the packets having names X will be kept in it. That shelf will look like [XXXXXXX]. If any shelf is used once, then it could be used again only if it is vacant. Packets from the initial shelf could be unloaded from top only. Write a program that finds the minimum total number of shelves, including the initial one required for this loading process.

0 Answers   Infosys,


What is header file in c?

0 Answers  


find the sum of two matrices and WAP for it.

0 Answers   Huawei,


What is indirection in c?

0 Answers  


Write a program that will read the input of any number of digits n in a row of shafh showing the breakdown of the printing and printing figures by the recursive function.

0 Answers  


What is context in c?

0 Answers  


What is an volatile variable?

15 Answers   HP,


Categories