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.

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter2: Problem Solving Using C++using
Section2.4: Arithmetic Operations
Problem 6E
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.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning