Answered step by step
Verified Expert Solution
Link Copied!

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:
Q1. 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?
Q2. Describe, in pseudo-code, a non-recursive algorithm for performing an inorder traversal of a binary tree in linear time.
Q3. Two trees, T1 and T2, are isomorphic if T1 can be transformed into T2 by swapping left and right children of (some of the) nodes in T1. 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.
Q4. 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 2 times the values stored at the next level of the tree plus 3 times the values stored at the next level of the tree and so on. What is the running time of your algorithm? Q5. 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 y>x. Note that x may or may not be in T. Explain why your algorithm has the running time it does.
Q6. 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 non-recursive 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design And Relational Theory Normal Forms And All That Jazz

Authors: Chris Date

1st Edition

1449328016, 978-1449328016

More Books

Students also viewed these Databases questions