Q1. Given a Binary Search Tree and a node, modify the Binary Search Tree to make the given node as the root.
Q2. Given a Binary Tree, find two nodes which are at the farthest distance.
Hint: Duke's CS
Q3. Given a Binary Tree, print the nodes in vertical order.
Example:
Order the nodes by the number we get for each of them.
Q4. Given a sorted array, design a method to find out how many Binary Search Trees can be created for the sorted array.
Q5. Given two Binary Search Tree, discuss and algorithm to generate a unified sorted list.
Q6. Given a Binary Tree, give a method to obtain the sum of all the nodes.
Q7. Given a Binary Search Tree, find the in-order successor of each of the nodes.
Q8. Given a Binary Search Tree, replace the value of each node with the sum of all its in-order successors.
Q9. Given a binary tree, design a method to find its depth.
Hint: Depth(T)= 1+ max( depth(T.left), depth(T.right))
Q10. Given a binary tree and a sum S, design a method to verify if there is a path from root to any of the nodes whose sum is equal to S.
Hint: verify(node, sum)
{
Sum = sum - node.value;
if(sum == 0) {
print result
Exit
}
else{
if(sum.left != null) verify(sum.left, Sum);
if(sum.right != null) verify(sum.right, Sum)
}
}
Q2. Given a Binary Tree, find two nodes which are at the farthest distance.
Hint: Duke's CS
Q3. Given a Binary Tree, print the nodes in vertical order.
Example:
Hint:
Order the nodes by the number we get for each of them.
Q4. Given a sorted array, design a method to find out how many Binary Search Trees can be created for the sorted array.
Q5. Given two Binary Search Tree, discuss and algorithm to generate a unified sorted list.
Q6. Given a Binary Tree, give a method to obtain the sum of all the nodes.
Q7. Given a Binary Search Tree, find the in-order successor of each of the nodes.
Q8. Given a Binary Search Tree, replace the value of each node with the sum of all its in-order successors.
Q9. Given a binary tree, design a method to find its depth.
Hint: Depth(T)= 1+ max( depth(T.left), depth(T.right))
Q10. Given a binary tree and a sum S, design a method to verify if there is a path from root to any of the nodes whose sum is equal to S.
Hint: verify(node, sum)
{
Sum = sum - node.value;
if(sum == 0) {
print result
Exit
}
else{
if(sum.left != null) verify(sum.left, Sum);
if(sum.right != null) verify(sum.right, Sum)
}
}
No comments:
Post a Comment