Recall that the height of a node u in a binary search tree (BST) T equals...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Recall that the height of a node u in a binary search tree (BST) T equals the number of edges in the longest path from u to a leaf of the subtree rooted at u. (Leaves have height 0.) Define the radius of u to equal the number of edges in the shortest path from u to a leaf of the subtree rooted at u. We define a new notion of a balanced BST: a BST T is 2-balanced if, for every node u of T, height (u) 2 radius(u), where height(u) is the height of u in T, and radius(u) is the radius of u in T. Give a linear time algorithm that determines if a BST T is 2-balanced, according to the definition above. The algorithm's input is a pointer to the root of T, where each node u has the following fields: an integer u. key, and pointers u. lchild and u. rchild to the left and right child of u, respectively. (If u has no left or right child, the corresponding pointer is set to NIL.) There is no height or radius information already stored in any node. The algorithm's output is TRUE if T is 2-balanced, and FALSE otherwise. The worst-case running time of your algorithm must be O(n) where n is the number of nodes in T. Describe your algorithm by giving its pseudo-code, and explain why its worst-case running time is O(n). You do not need to prove that the algorithm is correct. Recall that the height of a node u in a binary search tree (BST) T equals the number of edges in the longest path from u to a leaf of the subtree rooted at u. (Leaves have height 0.) Define the radius of u to equal the number of edges in the shortest path from u to a leaf of the subtree rooted at u. We define a new notion of a balanced BST: a BST T is 2-balanced if, for every node u of T, height (u) 2 radius(u), where height(u) is the height of u in T, and radius(u) is the radius of u in T. Give a linear time algorithm that determines if a BST T is 2-balanced, according to the definition above. The algorithm's input is a pointer to the root of T, where each node u has the following fields: an integer u. key, and pointers u. lchild and u. rchild to the left and right child of u, respectively. (If u has no left or right child, the corresponding pointer is set to NIL.) There is no height or radius information already stored in any node. The algorithm's output is TRUE if T is 2-balanced, and FALSE otherwise. The worst-case running time of your algorithm must be O(n) where n is the number of nodes in T. Describe your algorithm by giving its pseudo-code, and explain why its worst-case running time is O(n). You do not need to prove that the algorithm is correct.
Expert Answer:
Answer rating: 100% (QA)
To determine if a Binary Search Tree BST T is 2balanced we can traverse the tree in a depthfirst man... View the full answer
Related Book For
Introduction to Algorithms
ISBN: 978-0262033848
3rd edition
Authors: Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest
Posted Date:
Students also viewed these programming questions
-
Q1. You have identified a market opportunity for home media players that would cater for older members of the population. Many older people have difficulty in understanding the operating principles...
-
Voguish Couches is a small company which makes sofas. The company is owned by the couple Lennox and Stewart. You are an intern working at Voguish Couches. For the sake of simplicity, this assignment...
-
Obtain from your library a copy of the following article: "Robert S. Kaplan and David P. Norton, "Mastering the Management System," Harvard Business Review (January 2008), pp. 63-77. The authors of...
-
Two cars, A and B, move along the x-axis. Figure E2.32 is a graph of the positions of A and B versus time. Figure E2.32 (a) In motion diagrams (like Figs. 2.13b and 2.14b), show the position,...
-
What is Parseval's formula?
-
Steelcase Inc. is one of the largest manufacturers of office furniture in the United States. In Grand Rapids, Michigan, it produces filing cabinets in two departments: Fabrication and Trim Assembly....
-
Since 1900, many new theories in physics have changed the way that physicists view the world. Create a presentation that will explain to middle school students why Quantum Mechanics is important, how...
-
1. What is the difference between the two formulas below? f'(a) = lim h0 f(a+h)-f(a) h f'(x) = lim h0 f(x+h)-f(x) h
-
Indicate whether each of the following statements is true or false by writing T or F in t he a nswer c olumn. Burning to defraud is a special category of crime committed by persons who burn their own...
-
Indicate whether each of the following statements is true or false by writing T or F in t he a nswer c olumn. Contracts do not need to be stated in legal language.
-
Indicate whether each of the following statements is true or false by writing T or F in t he a nswer c olumn. White-collar crime, as distinguished from other types of crime, generally does not...
-
Indicate whether each of the following statements is true or false by writing T or F in t he a nswer c olumn. Entire contracts are those composed of several related parts.
-
When personal taxes on interest income and bankruptcy costs are considered, the general expression for the value of a levered firm in a world in which the tax rate on equity distributions equals zero...
-
We discussed risk aversion as being descriptive of investor behavior. Can you think of any real-world behavior that you might consider to be evidence of the existence of risk preferrers?
-
A regular deposit of $100 is made at the beginning of each year for 20 years. Simple interest is calculated at i% per year for the 20 years. At the end of the 20-year period, the total interest in...
-
Show how to extend the Rabin-Karp method to handle the problem of looking for a given m m pattern in an n n array of characters. (The pattern may be shifted vertically and horizontally, but it may...
-
Professor Stewart is consulting for the president of a corporation that is planning a company party. The company has a hierarchical structure, that is, the supervisor relation forms a tree rooted at...
-
Describe a procedure that takes as input two integers a and b such that 0 < a < b and, using fair coin flips, produces as output heads with probability a/b and tails with probability (b a)/b. Give a...
-
List each of the six branches of AI and briefly explain each one.
-
What are the three components of an Expert System (ES) program? Explain what each component does.
-
When training a machine learning application, developers can use one of three different approaches: supervised learning, unsupervised learning, and reinforcement learning. Describe each strategy and...
Study smarter with the SolutionInn App