Amazon Interview Question for Software Engineer / Developers






Comment hidden because of low score. Click to expand.
2
of 2 vote

@shar3oob: rightly pointed out! Read the following for more,

#
The most important difference (besides hash tables being faster)
between hash tables and btrees is that hash tables only find on
equality searches.
Btrees can do range searches with things like <, >, <=, >=, between,...

#Binary search tree has worst case seek of O(n) if elements are inserted in order.

Hash table has worst case seek of O(n) if every element hashes to the same value.

Assuming you have a good hash functions, a hash table will be very close to O(1) for both inserts and look-ups.

If you balance your btree, you will end up with O(lg n) lookups.

For the same number of elements, a btree will usually be more compact.

However, a good hash table is notoriously hard to implement where as a good binary tree is, even balanced, is fairly straight forward. Hash functions are very subtle and finicky so picking a good one for your data set will take some work.

- Saga Yao August 20, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Hashtable
Advantage: retreival and insertion in O(1) time
Disadvantage: Space complexity can increase if size of input is not known.
Use: when lot of retreival of values or keys are required.
Binary Tree
Advantage: Space complexity is O(n)
Disadvantage: Time complexity is O(logn) for retrieval and O(nlogn) to create.
Use: when lot of traversal and comparison is required.

- Anonymous October 21, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

what you said is BST ,not normal binary tree

- anonymous November 17, 2008 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I think BST is implied....
Are there any advantages of a binary tree ?

- abhimanipal April 14, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

bTrees define an order on the elements, so you can traverse them and print them out sorted, for example. Hashtables do not.

- Shar3oob May 26, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

We can print nodes in a BST in order (thru in-order or reverse-in-order) but hash table is never sorted.

Hash table works on the principle of a complex hash function. BSTs dont anything like that.

- Helper December 15, 2009 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More