Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In pseudocode please: Q 1 . Let T be a tree with n nodes. Define the lowest common ancestor ( LCA ) between two nodes
In pseudocode please:
Q Let T be a tree with n nodes. Define the lowest common ancestor LCA between two nodes v and w as the lowest node in T that has both v and w as descendants where we allow a node to be a descendent of itself Given two nodes v and w describe in pseudocode an efficient algorithm for finding the LCA of v and w What is the running time of your algorithm?
Q Describe, in pseudocode, a nonrecursive algorithm for performing an inorder traversal of a binary tree in linear time.
Q Two trees, T and T are isomorphic if T can be transformed into T by swapping left and right children of some of the nodes in T For instance, the two trees below are isomorphic because they are the same if the children of A B and G but not the other nodes, are swapped. Give a polynomial time algorithm described in pseudocode to decide if the two trees are isomorphic.
Q Describe in pseudocode an algorithm that returns the sum of the values stored in a binary tree of integers weighted by the depth of each value. You should return the value at the root plus times the values stored at the next level of the tree plus times the values stored at the next level of the tree and so on What is the running time of your algorithm? Q Let T be a binary search tree, and let x be a key. Give an efficient algorithm for finding the smallest key y in T such that yx Note that x may or may not be in T Explain why your algorithm has the running time it does.
Q Two binary trees are said to be equivalent if and only if they have the same structure and the same values at corresponding nodes. Describe in pseudocode a nonrecursive algorithm to determine whether two trees are equivalent. What is the running time of your algorithm?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started