a) Suppose we have a recursive function defined on a binary tree. The function takes as...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
a) Suppose we have a recursive function defined on a binary tree. The function takes as input a node in the tree, calls another function BAR that performs some work on the node and then makes a recursive call on its parent, provided it has one. 1: def FOO(u) 2: BAR(u) 3: 4: if u.parent is not empty then FOO(u.parent) Suppose BAR(u) takes O(log n) time to execute. Analyze the time complexity of running Foo from a leaf of a tree with n nodes. b) Solve the following recursion: T(n): = c) We have a set S of line segments on the real line (all having distinct length) and we want to pick a set TCS of these line segments such that every segment s; in S is covered by the union of the segments in T. In other words, T is a covering of S if the union of all segments in T is the union of all segments in S. Example: 4: 5: 6: 7: In the example above, we have three line segments: $₁ = [0,4], $2 = [0,2], and $3 [3,4]. The smallest cover T contains only $₁. Picking s₁ and any other line segment is still a cover, but not the smallest one. Not picking s₁ results in T not covering every line segment in S, since s₁ is not fully covered. [T(n) = 4T(n/2) +0(n) for n >1 (0(1) for n = 1 $1 Construct a counterexample to show that the following algorithm doesn't com- pute the smallest set T: Sort the line segments in S by their length in decreasing order. For every segment si, if s; isn't covered by T, we add s; to T. 1: def SMALLESTCOVER(S) 2: 3: for i T← [] Sort S by the length of the segments in decreasing order and renum- ber such that |s1| ≥ |$2| ≥ ... ≥ |Sn| 1; i a) Suppose we have a recursive function defined on a binary tree. The function takes as input a node in the tree, calls another function BAR that performs some work on the node and then makes a recursive call on its parent, provided it has one. 1: def FOO(u) 2: BAR(u) 3: 4: if u.parent is not empty then FOO(u.parent) Suppose BAR(u) takes O(log n) time to execute. Analyze the time complexity of running Foo from a leaf of a tree with n nodes. b) Solve the following recursion: T(n): = c) We have a set S of line segments on the real line (all having distinct length) and we want to pick a set TCS of these line segments such that every segment s; in S is covered by the union of the segments in T. In other words, T is a covering of S if the union of all segments in T is the union of all segments in S. Example: 4: 5: 6: 7: In the example above, we have three line segments: $₁ = [0,4], $2 = [0,2], and $3 [3,4]. The smallest cover T contains only $₁. Picking s₁ and any other line segment is still a cover, but not the smallest one. Not picking s₁ results in T not covering every line segment in S, since s₁ is not fully covered. [T(n) = 4T(n/2) +0(n) for n >1 (0(1) for n = 1 $1 Construct a counterexample to show that the following algorithm doesn't com- pute the smallest set T: Sort the line segments in S by their length in decreasing order. For every segment si, if s; isn't covered by T, we add s; to T. 1: def SMALLESTCOVER(S) 2: 3: for i T← [] Sort S by the length of the segments in decreasing order and renum- ber such that |s1| ≥ |$2| ≥ ... ≥ |Sn| 1; i
Expert Answer:
Answer rating: 100% (QA)
solution Ansa def Foo u Bar u then is not emply then uparent is not empty Foo uparent urual game Xa... View the full answer
Related Book For
Data Structures and Algorithm Analysis in Java
ISBN: 978-0132576277
3rd edition
Authors: Mark A. Weiss
Posted Date:
Students also viewed these electrical engineering questions
-
Suppose we use a hash function h to hash n distinct keys into an array T of length m, assuming simple uniform hashing, what is the expected number of collisions? More precisely, what is the expected...
-
A node in a tree is called terminating if it has only one edge. Repeat the preceding exercise when all terminating nodes except for the top one are grounded. (i) (ii) (iii) (iv) (v) ww
-
A plank with a bar placed on it performs horizontal harmonic oscillations with amplitude a = 10 cm. Find the coefficient of friction between the bar and the plank if the former starts sliding along...
-
In the figure below, which compares different DNA extraction kits (e.g, MO BIO and PSP), which one of the two trees shows the co-occurrence of microbial taxa? Proportion of max 0 0.2 0.4 0.6 0.8...
-
List and explain the three reasons the aggregate demand curve is downward sloping.
-
For a complex exponential signal x(t) =2e j2t (a) Suppose y(t) = e jt , would the sum of these signals z(t) = x(t) + y(t) be also periodic? If so, what is the fundamental period of z(t)? (b) Suppose...
-
The account balances for Great Gadget, Inc., for the year ended December 31, 2010, are presented next in random order: Requirements 1. Prepare Great Gadgets single-step income statement. 2. Would you...
-
Multiple Choice Questions Select the best answer for each of the following questions. Explain the reason for your selection. a. Which of the following would be least likely to be considered an...
-
The width, in feet, measured at 100 foot intervals along the fairway of a golf course is given in the diagram below. If one pound of fertilizer covers 200 square feet, estimate the amount of...
-
The Fly-Right Airplane Company builds small jet airplanes to sell to corporations for the use of their executives. To meet the needs of these executives, the companys customers sometimes order a...
-
For the topic: How Coronavirus affects tourism? please, propose solutions to these 5 environmental problems , 1- Tourism is entering a major crisis due to the worldwide panic of the Corona Virus,...
-
Why is the concept of time value of money important in the corporate context? Justify your answer. A complete post includes an explanation supported by examples and a minimum of 2 research sources....
-
charles bought a table for $ 6 5 and sold it for $ 8 4 . 5 0 . what was his percentage of profit?
-
Your client is purchasing, a 50, 000 square foot retail strip center in Orange, CT. There is a 30,000 square foot grocery anchor and eight 2,500 square foot retail stores. Two units are vacant. The...
-
if a share of stock costing $ 4 5 . 0 0 lost 3 / 8 % of its value, how much is it now worth?
-
How much work (in J) is done by the boy pulling his sister 21 m in a wagon as shown below? Assume no friction acts on the wagon. ] F = 60 N 34 d = 21 m
-
Two trains on separate tracks move toward each other. Train A has a speed of 116 km/h. Train B has a speed of 67.0 km/h. Train B blows its hom emitting a frequency of 500 Hz. (THIS IS AN EXAM...
-
A stock has had returns of 8 percent, 26 percent, 14 percent, 17 percent, 31 percent, and 1 percent over the last six years. What are the arithmetic and geometric average returns for the stock?
-
Find all the articulation points in the graph in Figure 9.85. Show the depth-first spanning tree and the values of Num and Low for each vertex. K
-
Determine the running time of mergesort for a. Sorted input b. Reverse-ordered input c. Random input
-
a. Propose a data structure that supports the stack push and pop operations and a third operation findMin, which returns the smallest element in the data structure, all in O(1) worst-case time. b....
-
The fly balls of spring loaded governor of Hartnell type running at 600 rpm have a radius of rotation of 80 mm with sleeve in mid-position and ball arms vertical. The ball arms and sleeve arms are of...
-
The height of Watt's governor is proportional to (a) speed (N) (b) \(\mathrm{N}^{2}\) (c) \(1 / \mathrm{N}\) (d) \(1 / \mathrm{N}^{2}\).
-
What is the main function of a governor? How does it differ from that of a flywheel?
Study smarter with the SolutionInn App