Amazon Interview Question for Software Engineer / Developers






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

hashtable is better as it adds/searches elements in O(1) time, provided hashfunction uses a good algorithm to distribute elements in different buckets.
In bst, add/search is of order O(logN) and in tree its O(n), whereas in hashtable its O(1), hence hashtable is better here.
In hashtable, we keep elements in array, hence we use extra space and thus in terms of space complexity, tree is better.

- Vaibhav March 20, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

BST can perform operations like sorting in constant time as opposed to hash table

- abhimanipal April 07, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Not sure what you mean here. There is no such thing as sorting in constant time.

- Anonymous June 28, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

In a BST we follow a particular pattern while inserting data. Hence we print the BST "in order" sorted data gets printed in O(n).

But you are right its not constant time

- abhimanipal June 30, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

In addition to the points already made binary search trees can produce an ordered traversals of elements by key. Hash tables, on the other hand, do not inherently have this capability.

- Anonymous June 28, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Tree Vs Hashes.
1.hashing cannot help in range queries.. while b trees or bst trees can help in range queries.
2.tree is a more compact and flexible when it comes to growing and shrinking in size. Hashing would waste a lot of space.
Hash Vs trees
1.tree does help in sorting but the use of map in c can also help in sorting.
2.Merging of two trees is difficult unless they are leftist trees( O(logn) merging), while merging two hashes is simpler.
3.insertion and deletion in tree logn , while the load factor governs the actual insertion or deletion time.

- Anonymous October 31, 2011 | 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