CS 173 [A]: Discrete Structures, Fall 2012 Homework 8 Solutions

Similar documents
This chapter covers recursive definition, including finding closed forms.

CSE 332 Spring 2013: Midterm Exam (closed book, closed notes, no calculators)

Solutions. (a) Claim: A d-ary tree of height h has at most 1 + d +...

Complexity, Induction, and Recurrence Relations. CSE 373 Help Session 4/7/2016

CS 506, Sect 002 Homework 5 Dr. David Nassimi Foundations of CS Due: Week 11, Mon. Apr. 7 Spring 2014

Discrete Structures. Fall Homework3

CS1800 Discrete Structures Final Version A

Recursively Defined Functions

CPS 102: Discrete Mathematics. Quiz 3 Date: Wednesday November 30, Instructor: Bruce Maggs NAME: Prob # Score. Total 60

Recursion and Structural Induction

CMPS 2200 Fall Dynamic Programming. Carola Wenk. Slides courtesy of Charles Leiserson with changes and additions by Carola Wenk

Plotting run-time graphically. Plotting run-time graphically. CS241 Algorithmics - week 1 review. Prefix Averages - Algorithm #1

Lecture 3.4: Recursive Algorithms

It is important that you show your work. There are 134 points available on this test.

CSE 332 Autumn 2013: Midterm Exam (closed book, closed notes, no calculators)

1KOd17RMoURxjn2 CSE 20 DISCRETE MATH Fall

Graph Algorithms. Chromatic Polynomials. Graph Algorithms

How much space does this routine use in the worst case for a given n? public static void use_space(int n) { int b; int [] A;

CSE Winter 2015 Quiz 1 Solutions

Recursion defining an object (or function, algorithm, etc.) in terms of itself. Recursion can be used to define sequences

CSE 332 Spring 2014: Midterm Exam (closed book, closed notes, no calculators)

Agenda. The worst algorithm in the history of humanity. Asymptotic notations: Big-O, Big-Omega, Theta. An iterative solution

Inference rule for Induction

Recursive definition of sets and structural induction

The divide and conquer strategy has three basic parts. For a given problem of size n,

Assignment 1 (concept): Solutions

CPSC 121: Models of Computation Assignment #5

HOMEWORK FILE SOLUTIONS

Searching Algorithms/Time Analysis

University of Toronto Department of Electrical and Computer Engineering. Midterm Examination. ECE 345 Algorithms and Data Structures Fall 2010

ICS 311, Fall 2017, Problem Set 04, Topics 7 & 8

Time Analysis of Sorting and Searching Algorithms

Computer Science Foundation Exam. March 3, Section I A. No Calculators! Name: SSN: In this section of the exam, there are three (3) problems.

PROGRAM EFFICIENCY & COMPLEXITY ANALYSIS

Binary Tree. Preview. Binary Tree. Binary Tree. Binary Search Tree 10/2/2017. Binary Tree

MAT 243 Test 2 SOLUTIONS, FORM A

Recursive Definitions Structural Induction Recursive Algorithms

THE PRINCIPLE OF INDUCTION. MARK FLANAGAN School of Electrical, Electronic and Communications Engineering University College Dublin

How many leaves on the decision tree? There are n! leaves, because every permutation appears at least once.

CPS 231 Exam 2 SOLUTIONS

CS 3512, Spring Instructor: Doug Dunham. Textbook: James L. Hein, Discrete Structures, Logic, and Computability, 3rd Ed. Jones and Barlett, 2010

COMP 250 Fall Midterm examination

Assignment 8 CSCE 156/156H/RAIK 184H Spring 2017

COMP171 Data Structures and Algorithms Fall 2006 Midterm Examination

UNIT 1 BASICS OF AN ALGORITHM

Test 1 Review Questions with Solutions

CS 4800: Algorithms & Data. Lecture 1 January 10, 2017

Solutions to the Second Midterm Exam

COMP 250 Fall Homework #4

CMSC351 - Fall 2014, Homework #2

Here is a recursive algorithm that solves this problem, given a pointer to the root of T : MaxWtSubtree [r]

DO NOT RE-DISTRIBUTE THIS SOLUTION FILE

CSE5311 Design and Analysis of Algorithms. Administrivia Introduction Review of Basics IMPORTANT

Framework for Design of Dynamic Programming Algorithms

Exercise 1. D-ary Tree

Midterm solutions. n f 3 (n) = 3

3. According to universal addressing, what is the address of vertex d? 4. According to universal addressing, what is the address of vertex f?

Algorithms (IX) Guoqiang Li. School of Software, Shanghai Jiao Tong University

Sample Questions for Midterm Exam 2

ANS:

Faculty of Science FINAL EXAMINATION COMP-250 A Introduction to Computer Science School of Computer Science, McGill University

ASSIGNMENT 4 SOLUTIONS

9/10/2018 Algorithms & Data Structures Analysis of Algorithms. Siyuan Jiang, Sept

2009 HMMT Team Round. Writing proofs. Misha Lavrov. ARML Practice 3/2/2014

10/9/17. Using recursion to define objects. CS 220: Discrete Structures and their Applications

CS 173, Running Time Analysis, Counting, and Dynamic Programming. Tandy Warnow

CS60020: Foundations of Algorithm Design and Machine Learning. Sourangshu Bhattacharya

Announcements. CS243: Discrete Structures. Strong Induction and Recursively Defined Structures. Review. Example (review) Example (review), cont.

ECE G205 Fundamentals of Computer Engineering Fall Exercises in Preparation to the Midterm

Fundamental mathematical techniques reviewed: Mathematical induction Recursion. Typically taught in courses such as Calculus and Discrete Mathematics.

Recursion and Induction

0.1 Welcome. 0.2 Insertion sort. Jessica Su (some portions copied from CLRS)

Midterm CSE 21 Spring 2012

COT 5407: Introduction to Algorithms. Giri Narasimhan. ECS 254A; Phone: x3748

Part 1: Multiple Choice Circle only ONE answer. Each multiple choice question is worth 3.5 marks.

Proving Properties of Recursive Functions and Data Structures. CS 270 Math Foundations of CS Jeremy Johnson

Binary Search to find item in sorted array

1. Find f(1), f(2), f(3), and f(4) if f(n) is defined recursively by f(0) = 1 and for n = 0, 1, 2,

CSC 321: Data Structures. Fall 2012

Solution to Graded Problem Set 4

CSE 20 DISCRETE MATH WINTER

Lecture 15 : Review DRAFT

CS583 Lecture 01. Jana Kosecka. some materials here are based on Profs. E. Demaine, D. Luebke A.Shehu, J-M. Lien and Prof. Wang s past lecture notes

Lamé s Theorem. Strings. Recursively Defined Sets and Structures. Recursively Defined Sets and Structures

CS1800 Discrete Structures Fall 2016 Profs. Aslam, Gold, Ossowski, Pavlu, & Sprague December 16, CS1800 Discrete Structures Final

What does this print?

ANALYSIS OF ALGORITHMS

Induction and Recursion. CMPS/MATH 2170: Discrete Mathematics

Introduction to Automata Theory. BİL405 - Automata Theory and Formal Languages 1

Recursion defining an object (or function, algorithm, etc.) in terms of itself. Recursion can be used to define sequences

University of Toronto Department of Electrical and Computer Engineering. Midterm Examination. ECE 345 Algorithms and Data Structures Fall 2012

Discrete mathematics , Fall Instructor: prof. János Pach

5.3 Recursive definitions and structural induction

Solutions for Algorithm Design Exercises and Tests

CS 220: Discrete Structures and their Applications. Recursive objects and structural induction in zybooks

EECS 477: Introduction to algorithms. Lecture 6

Recursion (Part 3) 1

CS1800 Discrete Structures Fall 2016 Profs. Aslam, Gold, Ossowski, Pavlu, & Sprague December 16, CS1800 Discrete Structures Final

ECE250: Algorithms and Data Structures Midterm Review

CS1800 Discrete Structures Spring 2017 Profs. Gold & Schnyder April 28, CS1800 Discrete Structures Final

Transcription:

CS 173 [A]: Discrete Structures, Fall 01 Homework 8 Solutions This homework contains 4 problems worth a total of 35 points. It is due on Wednesday, November 14th, at 5pm. 1 Induction Proofs With Inequalities 10 points) Claim: For all positive integers n, 4 n < n)!. Prove the above claim by induction on n. Base Case: When n =, 4 n = 4 = 16 and n)! = 4! = 4, so the inequality holds for this value of n. Induction: Suppose that 4 k < k)! holds for all k =, 3,..., n. We need to show that 4 n+1 < n + )!. First, observe that by the inductive hypothesis, 4 n < n)!, so 4 n+1 = 4 4 n < 4 n)! = n)!. Since n, it follows that n + ) > and n + 1) >, so 4 n)! = n)! < n)!n + 1)n + ) = n + )!. Putting these equations together gives that 4 n+1 < n + )!, which is what we needed to show. Running Times of Tree Algorithms 8 points) Suppose that the structure of a node in a 3 ary tree that stores positive) integer values is defined by the following pseudocode: TreeNode { integer value; TreeNode left_child; TreeNode middle_child; TreeNode right_child; Let s use NIL as the symbol for a TreeNode that s not present. Consider next the following pseudocode for the function computet) that takes a TreeNode structure T as input. integer computetreenode tn) { 1

iftn is NIL) return 0; else return tn.value + computetn.left_child) + computetn.middle_child) + computetn.right_child); Part a): Suppose that T represents the root node of a 3 ary tree. In words, what does the function computet) do? The function computes the sum of all elements stored in the tree. Part b): Suppose that T represents the root node of a full, complete 3 ary tree of height h. What is the running time of computet) as a function of h? Express your answer using Big O notation. The function compute runs in constant time each time it is called. The function is called once on every node in the tree and once for each NIL node not present at height h + 1 in the tree. This means that compute is called h+1 3 i = 3h+ 1 times. So the running time of computet) is O3 h ). 3 Pseudocode Running Time 9 points) Suppose that a call to the function f1n) takes On) time and that a call to fn) takes O n ) time. Let the functions function1n), functionn), and function3n) be defined by the following pseudocode where n is a non negative integer. function1integer n) { for i = 0, 1,..., n: f1i);

functioninteger n) { for i = 0, 1,..., n: fi); function3integer n) { function1n); functionn); Part a): Suppose that n is a non negative integer. What is the running time of a call to function1n)? Express your answer as a simplified function of n using Big O notation. The total running time of the call to function1n) is ) ) nn + 1) Oi) = O i = O = On ). Part b): Suppose that n is a non negative integer. What is the running time of a call to functionn)? Express your answer as a simplified function of n using Big O notation. The total running time of the call to functionn) is ) O i ) = O i = O n+1 1 ) = O n ). An alternate solution can be obtained by taking the sum O n ) = On n ). 3

Part c): Suppose that n is a non negative integer. Using your answers for parts a) and b), find the running time of a call to function3n)? Express your answer as a simplified function of n using Big O notation. Hint: Which of the running times from parts a) and b) dominates the running time of the function? The total running time of the call to function3n) is the sum of the running times of function1n) and functionn). In this case, On ) + O n ) = O n ) or On ) + On n ) = On n ), depending on the form of the solution from part b). 4 Recursive Definition of Running Time 10 points) Consider the following pseudocode for the function functiongn) that takes a non negative integer n as input. integer functionginteger n) { ifn <= 0) return 0; integer count = 0; for i = 1,,..., n: count = count + 1; return count + functiongn-1) + functiongn-1) + functiongn-1); Part a): What is the return value of functiongn) for n = 0, 1,, 3, 4? functiong0) = 0 functiong1) = 1 functiong) = 5 functiong3) = 18 functiong4) = 58 4

Part b): Give a recursive definition, gn), for the running time of functiongn) where n is a non negative integer. Be sure to include a base case or cases. The running time is given by g0) = c 0 and for n 1 where c 0, c 1, c are constants. Part c): gn) = 3gn 1) + c 1 n + c Give a closed form formula for the recursive definition of gn) from part b) as a function of n. Obtain the closed form using unrolling or a similar method. Only state the formula for gn) it is not necessary to prove that the formula is correct by induction). The solution to the recurrence from part b) can be solved exactly using Mathematica or Wolfram Alpha as gn) = 1 4 4c0 3 n + c 1 n + 3 n+1 3 ) + c 3 n 1) ). This gives that the running time is exponential as O3 n ). 5