hw4 - very little additional space other than the array...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CprE 310 Theoretical Foundations of Computer Engg, Spring 08 Homework 4 Due: 21 Feb 2008, in class Topics: Recursive De±nitions, Proofs Reading: Sections 4.3, 4.4 Problem 4.1 Prove that for any n 6, an equilateral triangle can be partitioned into n equilateral triangles. Problem 4.2 A palindrome is any string that reads the same from the left to right as it does from the right to the left. For example, 010 and 0110110 are palin- dromes, while 01010101 is not. Give a recursive de±nition of the set of all bit strings of length 100 that are palindromes. Problem 4.3 Examine the following sequence: 1 2 , 2 2 - 1 2 , 3 2 - 2 2 +1 2 , 4 2 - 3 2 +2 2 - 1 2 , 5 2 - 4 2 + 3 2 - 2 2 + 1 2 , . . . , and guess an expression for the sum n 2 - ( n - 1) 2 + ( n - 2) 2 - ... +( - 1) n 1 2 . Prove that your guess is correct using mathematical induction. Problem 4.4 Design a recursive algorithm for reversing a bit string in place. Assume that the input is available to your algorithm as an array A , and the size of the array is also available as a parameter n . By reversing a bit string “in place”, we mean that the algorithm should use
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: very little additional space other than the array itself. For example, you can use an additional variable variable or two, but you cannot use an additional array of storage. State any assumptions you make. CprE 310 Homework 4 21 Feb 2008, in class Problem 4.5 Give a recursive algorithm that counts the number of ones in a bit array. Assume that the inputs to the algorithm are the bit array B , and its length n . You can assume that the array B is indexed from 0 to n-1. Problem 4.6 For the Towers of Hanoi problem described in class, give a recursive algo-rithm that moves n disks ( n is an integer greater than 0) from tower A to tower C using tower B as a buer. Analyze the number of moves taken by the algorithm to move n disks, and prove your result (for the number of moves) using mathematical induction. 2...
View Full Document

Page1 / 2

hw4 - very little additional space other than the array...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online