Amazon Interview Question for Software Engineer / Developers


Country: Canada
Interview Type: Phone Interview




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

Btw, map is a pair , one being key and other being value . It is an abstract data type whose implemntation varies from hash function to tree(BST)
Map can be implemented using hash function to find memory index , providing constant time lookups for value of a key. Or it can also be implemented using a special kind of tree BST for lgn time look ups.

However tree is concrete data structure having a node and children . It has different form regarding different use cases.

- krbchd July 09, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

to add to that: when you are constantly adding data to a hash you will incur a re-hash where a tree doesn't suffer from that.

- camelCase July 14, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Tree will store elements in an order. Map does not.

- var9ga July 09, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

@var9ga what do you mean by order? do you mean sorted?

- Prithvi July 09, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

tree

root
	   /    \
         /      \
        /        \
       /          \
node1           node2
      / \              /\
     /   \            /  \
    /     \          /    \
cond...

if you notice here nodes are trees too. the data structure may look something like

t: v [t[1], ..., t[k]]// t is tree, v is the value of the node, t[n] are childs

Map: are just key value pair.

key1 | value1
key2 |value 2

- Prithvi July 09, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Tree stores elements in sorted order.
Map stores key value pair and not in any sorted order.

- krish July 09, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

Not all trees store element in sorted order. Only ordered tress are.

An unordered tree is a tree in purely structural sense: given a node, there is no order for the children of that node.

- Prithvi July 09, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 4 vote

in c++ , map is internally stored as a balanced tree.so map is also eventually a tree but a balanced one. which is why it takes O(logn) to search in map.

- kishor July 09, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

What do you mean? lookup for a map is O(1), there's no sense of 'searching' in a map.

- camelCase July 14, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

The difference is that map is an "associative container" and it needs two abstract types Key/Value while tree is not an "associative container" and needs only one type Node with certain attributes/methods.

- celicom September 29, 2013 | 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