How many lines, as a function of n (in () form), does the following program print Write | StudySoup

Textbook Solutions for Algorithms

Chapter 2 Problem 2.12

Question

How many lines, as a function of n \(\text { (in } \Theta(\cdot)\) form), does the following program print? Write a recurrence and solve it. You may assume n is a power of 2.

function f(n)

if n > 1:

print line(“still going'')

f(n/2)

f(n/2)

Solution

Problem 2.12

How many lines, as a function of n (in  form), does the following program print? Write a recurrence and solve it. You may assume n is a power of 2.

function f(n)

    if n > 1:

       print_line (still going)

       f(n/2)

       f(n/2)

                                                               Step by Step Solution

Step 1 of 3

By considering function of n (in Theta(.) form), the question has solved as following:

This program prints one line and then splits into two subprograms with half of the input size each.

Subscribe to view the
full solution

Title Algorithms  1 
Author Sanjoy Dasgupta Algorithms, Christos H. Papadimitriou Algorithms, Umesh Vazirani Algorithms
ISBN 9780073523408

How many lines, as a function of n (in () form), does the following program print Write

Chapter 2 textbook questions

×

Login

Organize all study tools for free

Or continue with
×

Register

Sign up for access to all content on our site!

Or continue with

Or login if you already have an account

×

Reset password

If you have an active account we’ll send you an e-mail for password recovery

Or login if you have your password back