Trees and Graphs Interview Questions
- 1of 1 vote
AnswersQ:
Given a binary tree with nodes that have left, right pointers pointing to the left and right children respoectively. It also has a neighbor pointer that currently Points to null.
Write a function to make it point to its neighbor.
E.g1 2 3 4 5 6 7
1.sibling should point to null
- JSDUDE April 27, 2013 in United States
2.sibling should point to 3
3.sibling should point to null
4.sibling should point to 5
5.sibling should point to 6
6.sibling should point to 7
7.sibling should point to null
Iteration and Recursion both| Report Duplicate | Flag | PURGE
Microsoft SDE1 Trees and Graphs - 0of 0 votes
Answershow to find lowest common ancestor of a binary tree
- xxx February 22, 2013 in United States
??
not BST| Report Duplicate | Flag | PURGE
Amazon Intern Trees and Graphs - 2of 4 votes
AnswersGiven a binary tree return the level with maximum number of nodes
- ruddermechanic February 07, 2013 in United States1 / \ 2 3 /\ /\ 4 5 6 7 / \ 8 9
| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Trees and Graphs - 0of 0 votes
AnswersFind max depth of a binary tree
- andrew February 05, 2013 in United States| Report Duplicate | Flag | PURGE
Bloomberg LP Financial Software Developer Trees and Graphs - 0of 0 votes
Answers1. Write a program to return a max BST within a given B-tree
- A February 01, 2013 in United States| Report Duplicate | Flag | PURGE
Intern Trees and Graphs - 1of 1 vote
AnswersGiven a binary tree, find a binary search tree which is a subtree of the given binary tree and has the largest size?
- Ashish January 31, 2013 in India
Note : Here size means the no. of nodes and the binary tree can have more than one B.S.T. as its subtree.| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Trees and Graphs - 0of 0 votes
AnswersFind the 2nd largest element in a binary search tree
- v.shah7689 January 23, 2013 in United States| Report Duplicate | Flag | PURGE
Trees and Graphs - 0of 0 votes
AnswersChange the structure of a Tree node to hold a pointer for the next in-order element (sucessor).
- rodrigoreis22 January 22, 2013 in United States
Given a Binary Search Tree.. transform it on a LinkedList by setting the next pointer described above.
Maybe this is a duplicate question.| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Trees and Graphs - 0of 0 votes
Answersgiven a binary tree and a leaf node.
- geekykid January 20, 2013 in India
holding that leaf node and whole tree falls down such that it is the new root of the tree.
return the modified tree.| Report Duplicate | Flag | PURGE
Walmart Labs Software Engineer / Developer Trees and Graphs - 1of 1 vote
AnswersFind if the given two trees can be joined leaf to leaf?
- beginner99 January 20, 2013 in India| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm Trees and Graphs - 0of 2 votes
AnswersRound 3 :
- sonesh January 03, 2013 in India
Q 6 : You are given a ternary tree (a tree with 3 children at max with left, middle, right pointer at each node), create a singly linked list from it without using extra space ?| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Algorithm Data Structures Linked Lists Trees and Graphs - 3of 3 votes
AnswersRound 3 :
- sonesh January 03, 2013 in India
Q 5 : You are given a binary search tree, and a value(data item), you need to tell the left most right cousin in as minimum time and as minimum space ?(need to minimize actual time complexity, he need minimum order of complexity as well as number of node access should be minimum)| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Algorithm Data Structures Trees and Graphs - -1of 1 vote
AnswersRound 2 :
- sonesh January 03, 2013 in India
Q 3 : you are given some nodes, and for each node a probability is given which will tell its importance, you need to design an efficient data structure such that the expected search time as minimum as possible. (Hint : Use dynamic programming + binary tree).| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Algorithm Dynamic Programming Trees and Graphs - 0of 0 votes
AnswersRound 2 :
- sonesh January 03, 2013 in India
Q 2 : You are given finitely many intervals in 1D, you have to design a data structure an efficient data structure which can answer queries of the form “In how many intervals the point P belong ?”, P is an input point, and all intervals are closed. I answer B tree(think why) which is most efficient.| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Algorithm Data Structures Dynamic Programming Probability Trees and Graphs - 0of 0 votes
AnswersRound 1 :
- sonesh January 03, 2013 in India
Q 1 : When you visit on your friend’s Facebook profile, there is a mutual friend section where common friends are listed, now let’s assume that your friend do the same thing, he/she visit his/her friend other then you, now the people other than common are connected to you by distance of two. Similarly think you are given two people on Facebook, how do you find this connectivity?. (Please give appropriate solution),
Now let’s think that some important people are given some weight(any), now do the same thing ?
Now calculate the most influential person? (Not an easy question, because of weights) ?| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Algorithm Data Mining Data Structures Trees and Graphs - 0of 0 votes
AnswersIn a BST, write a function to find two nodes whose sum is equal to a given integer 'k'.
- Nitin December 13, 2012 in India| Report Duplicate | Flag | PURGE
Ibibo Software Engineer / Developer Trees and Graphs - 0of 0 votes
AnswersTree with black and white nodes is given. Find a longest path of white nodes in the given tree.
- cynic.vader December 10, 2012 in United States| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Trees and Graphs - 0of 0 votes
AnswersJust came from interview. The interviewer asked me this question: copy tree with unlimited number of children with breadth fist search...
- Laasssfvfd December 04, 2012 in United States| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm Trees and Graphs - 0of 0 votes
AnswersPrint Level order traversal of a binary tree in reverse way.
- Muqthi December 02, 2012 in India
If tree is 1
/ \
2 3
/ \ / \
4 5 6 7
Output will be 4 5 6 7 2 3 1| Report Duplicate | Flag | PURGE
Groupon Software Engineer / Developer Trees and Graphs - 0of 0 votes
AnswersGive a BST and a number. we need to find next bigger number in BST.
- Harsh123 November 04, 2012 in India for Kindle| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm Data Structures Trees and Graphs - 0of 0 votes
AnswersIf a key has to be inserted in binary tree, say the value of root as well as the key to be inserted as same. Will the key becomes left child or right child of Root? Can binary tree have duplicate values? If yes, why, If no why?
- sivaji8 November 03, 2012 in United States| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Trees and Graphs - 0of 0 votes
AnswersWrite an algorithm to print out how many extra duplicates there are in a binary search tree.
- sjs3 November 01, 2012 in United States for amazon local
input 1:
2
/ \
1 2
output 1:
2 1
input 2:
3
/ \
2 3
/ \ \
1 2 4
/ \
3 4
\
5
\
5
output 2:
2 1
3 2
4 1
5 1
Given:
Node {
int value;
Node left;
Node right;
}| Report Duplicate | Flag | PURGE
Amazon Trees and Graphs - 0of 0 votes
AnswersLongest posibble path in a tree, you had to return the end leaf nodes.
- kingKode October 12, 2012 in United States
geeksforgeeks(dot)org/diameter-of-a-binary-tree/| Report Duplicate | Flag | PURGE
Walmart Labs Software Engineer / Developer Trees and Graphs - 0of 0 votes
AnswersPrint a binary tree in vertical.
- kaushikdev9 October 11, 2012 in India
e.g.,
1
/ \
2 3
/ /
4 5
\
6
o/p: 4 2 1 5 3 6| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Trees and Graphs - 0of 0 votes
AnswersWrite the recursive implementation of DFS and BFS for an n-ary tree. Tree node has an int data item, and a linked list "children" of nodes.
- CartmanIncarnate October 07, 2012 in United States| Report Duplicate | Flag | PURGE
Salesforce Software Engineer / Developer Trees and Graphs - 0of 0 votes
AnswersFind the first common ancestor of two nodes in a binary tree (note not a BST).
- singhSahab October 06, 2012 in India| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Trees and Graphs - 0of 0 votes
AnswersFind the k'th shortest path between two given nodes of a graph
- anandaroop.acharia September 25, 2012 in India| Report Duplicate | Flag | PURGE
Software Engineer / Developer Trees and Graphs - 0of 0 votes
AnswersWrite a non-recursive function to delete an entire binary tree.
- william.buss343 September 19, 2012 in United States| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Trees and Graphs - 0of 0 votes
AnswersGiven a binary tree:
- william.buss343 September 19, 2012 in United States
1
/ \
2 6
/ \ \
3 4 7
/
5
Given the pre-order, in-order traversals of the tree, reconstruct the tree.| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Trees and Graphs