Chapter 2: Q2E (page 83)
Show that for any positive integers n and any base b , there must some power of b lying in the range .
Short Answer
To show that some power of b falls in the range of
/*! This file is auto-generated */ .wp-block-button__link{color:#fff;background-color:#32373c;border-radius:9999px;box-shadow:none;text-decoration:none;padding:calc(.667em + 2px) calc(1.333em + 2px);font-size:1.125em}.wp-block-file__button{background:#32373c;color:#fff;text-decoration:none}
Learning Materials
Features
Discover
Chapter 2: Q2E (page 83)
Show that for any positive integers n and any base b , there must some power of b lying in the range .
To show that some power of b falls in the range of
All the tools & learning materials you need for study success - in one app.
Get started for free
In Section 1.2.3, we studied Euclid’s algorithm for computing the greatest common divisor (gcd) of two positive integers: the largest integer which divides them both. Here we will look at an alternative algorithm based on divide-and-conquer.
(a) Show that the following rule is true.
(b) Give an efficient divide-and-conquer algorithm for greatest common divisor.
(c) How does the efficiency of your algorithm compare to Euclid’s algorithm if a and b are n-bit -bit integers? (In particular, since n might be large you cannot assume that basic arithmetic operations like addition take constant time.)
Suppose you are choosing between the following three algorithms: • Algorithm A solves problems by dividing them into five sub-problems of half the size, recursively solving each sub-problem, and then combining the solutions in linear time. •
Algorithm B solves problems of size n by recursively solving two sub-problems of size and then combining the solutions in constant time. • Algorithm C solves problems of size n by dividing them into nine sub-problems of size , recursively solving each sub-problem, and then combining the solutions in time.
What are the running times of each of these algorithms (in big- O notation), and which would you choose?
In Section 2.1 we described an algorithm that multiplies two n-bit binary integers x and y in time , where . Call this procedure fast multiply (x,y).
(a) We want to convert the decimal integer (a 1 followed by n zeros) into binary. Here is the algorithm (assume n is a power of 2):
function pwr2bin(n)
if n = 1: return
else:
z= ???
return fastmultiply(z,z)
Fill in the missing details. Then give a recurrence relation for the running time of the algorithm, and solve the recurrence.
(b) Next, we want to convert any decimal integer x with n digits (where n is a power of 2) into binary. The algorithm is the following:
function dec2bin(x)
if n=1: return binary [ x ]
else:
split x into two decimal numbers with n/2 digits each
return ???
Here binary [.] is a vector that contains the binary representation of all one-digit integers. That is, binary role="math" localid="1659333641173" , binary , up to binary . Assume that a lookup in binary takes 0(1) time. Fill in the missing details. Once again, give a recurrence for the running time of the algorithm, and solve it.
Question: You are given an infinite array in which the first n cells contain integers in sorted order and the rest of the cells are filled with . You are not given the value of n. Describe an algorithm that takes an integer x as input and finds a position in the array containing x, if such a position exists, in O(log n) time. (If you are disturbed by the fact that the array A has infinite length, assume instead that it is of length n, but that you don’t know this length, and that the implementation of the array data type in your programming language returns the error message whenever elements are accessed.)
A binary tree is full if all of its vertices have either zero or two children. Let denote the number of full binary trees with n vertices. (a)By drawing out all full binary trees with 3, 5, or 7 vertices, determine the exact values of , , and . Why have we left out even numbers of vertices, like ?
(b) For general n, derive a recurrence relation for .
(c) Show by induction that is .
What do you think about this solution?
We value your feedback to improve our textbook solutions.