Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

a) Suppose we have a recursive function defined on a binary tree. The function takes as input a node in the tree, calls another

image

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

Step by Step Solution

3.48 Rating (151 Votes )

There are 3 Steps involved in it

Step: 1

solution Ansa def Foo u Bar u then is not emply then uparent is not empty Foo uparent urual game Xa... 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_2

Step: 3

blur-text-image_3

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

Data Structures and Algorithm Analysis in Java

Authors: Mark A. Weiss

3rd edition

132576279, 978-0132576277

More Books

Students also viewed these Electrical Engineering questions

Question

Brief the importance of span of control and its concepts.

Answered: 1 week ago

Question

What is meant by decentralisation?

Answered: 1 week ago

Question

Write down the Limitation of Beer - Lamberts law?

Answered: 1 week ago

Question

Discuss the Hawthorne experiments in detail

Answered: 1 week ago