2. Given the following recursive algorithm: procedure sum(x, y) Input: x: nonnegative integer, y: nonnegative integer Output: x+y: nonnegative integer if y--0 then return x else return sum(x, y-1) + 1 Prove that sum(x, y) returns x+y for any nonnegative integers x and y.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Question 2 only please.

2. Given the following recursive algorithm:
procedure sum(x, y)
Input: x: nonnegative integer, y: nonnegative integer
Output: x+y: nonnegative integer
if y==0 then return x
else return sum(x, y-1) + 1
Prove that sum(x, y) returns x+y for any nonnegative integers x and y.
Transcribed Image Text:2. Given the following recursive algorithm: procedure sum(x, y) Input: x: nonnegative integer, y: nonnegative integer Output: x+y: nonnegative integer if y==0 then return x else return sum(x, y-1) + 1 Prove that sum(x, y) returns x+y for any nonnegative integers x and y.
Part I: Induction
Prove each of the following statements using induction, strong induction,
or structural induction. For each statement, answer the following questions.
а.
Complete the basis step of the proof.
b.
What is the inductive hypothesis?
C.
What do you need to show in the inductive step of the proof?
d.
Complete the inductive step of the proof.
1. Let S be the set of perfect binary trees, defined as:
• Basic step: a single vertex with no edges is a perfect binary tree T,.
• Recursive step: if T1 and T2 are perfect binary trees of the same height, then a new
perfect binary tree T' can be constructed by taking T1 and T2, adding a new vertex
v, and adding edges between v and the roots of T, and T2.
Prove that h(T) = log2(n(T) + 1) – 1 for any perfect binary tree T, where n(T) is the number
of vertices of T and h(T) is the height of T.
Hint: Remember that h(T,) = h(T2) and n(T,) = n(T,). Also remember that h(T') = h(T,) + 1 and
n(T') = n(T,) + n(T2) + 1.
Transcribed Image Text:Part I: Induction Prove each of the following statements using induction, strong induction, or structural induction. For each statement, answer the following questions. а. Complete the basis step of the proof. b. What is the inductive hypothesis? C. What do you need to show in the inductive step of the proof? d. Complete the inductive step of the proof. 1. Let S be the set of perfect binary trees, defined as: • Basic step: a single vertex with no edges is a perfect binary tree T,. • Recursive step: if T1 and T2 are perfect binary trees of the same height, then a new perfect binary tree T' can be constructed by taking T1 and T2, adding a new vertex v, and adding edges between v and the roots of T, and T2. Prove that h(T) = log2(n(T) + 1) – 1 for any perfect binary tree T, where n(T) is the number of vertices of T and h(T) is the height of T. Hint: Remember that h(T,) = h(T2) and n(T,) = n(T,). Also remember that h(T') = h(T,) + 1 and n(T') = n(T,) + n(T2) + 1.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 3 images

Blurred answer
Knowledge Booster
Computational Systems
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education