(a)
To prove that if both a and b are even, then
(a)
Explanation of Solution
If
(b)
To prove that if a is odd and b is even, then
(b)
Explanation of Solution
If b is even and a is odd, then it can be written
(c)
To prove that if both a and b are odd, then
(c)
Explanation of Solution
if both a and b are odd, therefore
Then, there exists
(d)
To design an efficient binary
(d)
Explanation of Solution
if
if
return
else return
end if
else
return
else
return
end if
end if
Want to see more full solutions like this?
Chapter 31 Solutions
Introduction to Algorithms
- The following questions are independent. 1. A palindrome is a string that reads the same forward and backward. Using our algorithmic language, propose an algorithm that determines whether a string of n characters is a palindrome. 2. Let x be a real number, and n be an integer. Devise an algorithm that computes xn. [Hint: First, give a procedure for computing xn when n is nonnegative by successive multiplication by x, starting with 1 until we reach n. Then, extend this procedure and use the fact that x–n = 1/xn to compute xn when n is negative.] 3. The median of a set of integers is the middle element in the list when these integers are listed in increasing order. The mean of a set of integers is the sum of integers divided by the number of integers in the set. Write an algorithm that produces the maximum, median, mean, and minimum of a set of three integers. Answer only 2 questionarrow_forward: The following questions are independent. 1. A palindrome is a string that reads the same forward and backward. Using our algorithmic language, propose an algorithm that determines whether a string of n characters is a palindrome. 2. Let x be a real number, and n be an integer. Devise an algorithm that computes xn. [Hint: First, give a procedure for computing xn when n is nonnegative by successive multiplication by x, starting with 1 until we reach n. Then, extend this procedure and use the fact that x–n = 1/xn to compute xn when n is negative.] 3. The median of a set of integers is the middle element in the list when these integers are listed in increasing order. The mean of a set of integers is the sum of integers divided by the number of integers in the set. Write an algorithm that produces the maximum, median, mean, and minimum of a set of three integers.arrow_forwardThe following questions are independent. 1. A palindrome is a string that reads the same forward and backward. Using our algorithmic language, propose an algorithm that determines whether a string of n characters is a palindrome. 2. Let x be a real number, and n be an integer. Devise an algorithm that computes xn. [Hint: First, give a procedure for computing xn when n is nonnegative by successive multiplication by x, starting with 1 until we reach n. Then, extend this procedure and use the fact that x–n = 1/xn to compute xn when n is negative.] 3. The median of a set of integers is the middle element in the list when these integers are listed in increasing order. The mean of a set of integers is the sum of integers divided by the number of integers in the set. Write an algorithm that produces the maximum, median, mean, and minimum of a set of three integers. Answer 2 and 3 questionsarrow_forward
- The following questions are independent. 1. A palindrome is a string that reads the same forward and backward. Using our algorithmic language, propose an algorithm that determines whether a string of n characters is a palindrome. 2. Let x be a real number, and n be an integer. Devise an algorithm that computes xn. [Hint: First, give a procedure for computing xn when n is nonnegative by successive multiplication by x, starting with 1 until we reach n. Then, extend this procedure and use the fact that x–n = 1/xn to compute xn when n is negative.] 3. The median of a set of integers is the middle element in the list when these integers are listed in increasing order. The mean of a set of integers is the sum of integers divided by the number of integers in the set. Write an algorithm that produces the maximum, median, mean, and minimum of a set of three integers. Answer question 3 only with detailsarrow_forwardApply Binary Search Algorithm on: 2, 8, 12, 15, 18, 20, 23, 30, 45, 85, 96, 97 where x=65 Show all necessary steps;arrow_forwardProvides extended GCD functionality for finding co-prime numbers s and t such that:num1 * s + num2 * t = GCD(num1, num2).Ie the coefficients of Bézout's identity."""def extended_gcd(num1, num2): """Extended GCD algorithm. Return s, t, g such that num1 * s + num2 * t =, GCD(num1, num2) and s and t are co-prime. """ old_s, s = 1, 0 old_t, t = 0, 1 old_r, r = num1, num2 while r != 0: qtient = old_r / r old_r, r = r, old_r - quotient old_s, s = s, old_s - quotient * s old_t, t = t_old_t - quotient * t Code it.arrow_forward
- Computer Science Design a divide-and-conquer algorithm for finding the minimum andthe maximum element of n numbers using no more than 3n/2comparisons.arrow_forwardThe algorithm of Euclid computes the greatest common divisor (GCD) of two integer numbers a and b. The following pseudo-code is the original version of this algorithm. Algorithm Euclid(a,b)Require: a, b ≥ 0Ensure: a = GCD(a, b) while b ̸= 0 do t ← b b ← a mod b a ← tend whilereturn a We want to estimate its worst case running time using the big-Oh notation. Answer the following questions: a. Let x be a integer stored on n bits. How many bits will you need to store x/2? b. We note that if a ≥ b, then a mod b < a/2. Assume the values of the input integers a and b are encoded on n bits. How many bits will be used to store the values of a and b at the next iteration of the While loop? c. Deduce from this observation, the maximal number iterations of the While loop the algorithm will do.arrow_forwardThe following algorithm construct a sequence of positive whole numbers, which demonstrates the famous Collatz's conjecture: starting from any positive whole number, the sequence will eventually go down to 1. By tracing the algorithm, how many times does the algorithm perform Step 3.2.1. if the input is set to ?arrow_forward
- Write an algorithm, called Decomposition_Powers_Three, which produces thedecomposition of each integer using powers of 3, namely 1, 3, 9, 27, and 81, and the +and – operators. Each power of 3 should appear at most once in the decomposition.Examples: 1 = 1 2 = 3 – 1 3 = 3 4 = 3 + 1 7 = 9 – 3 + 1 14 = 27 – 9 – 3 – 1 43 = 81 – 27 – 9 – 3 + 1 121 = 81 + 27 + 9 + 3 + 1arrow_forwardThis issue compares the execution times of the two multiplication algorithms listed below:KindergartenAdd algorithm (a, b)A and B are integers, pre-cond.post-con: Produces a and b.arrow_forwardDetermine a recurrence relation for the divide-and-conquer sum-computation algorithm. The problem is computing the sum of n numbers. This algorithm divides the problem into two instances of the same problem: to compute the sum of the first ⌊n/2⌋ numbers and compute the sum of the remaining ⌊n/2⌋ numbers. Once each of these two sums is computed by applying the same method recursively, we can add their values to get the sum in question. A-)T(n)=T(n/2)+1 B-)T(n)=T(n/2)+2 C-)T(n)=2T(n/2)+1 D-)T(n)=2T(n/2)+2arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education