You are on page 1of 3

TDS1191, Tutorial 4

Subject: Session:

Discrete Structures 2 2006/2007

Tutorial 4
Part A: Induction
1. Prove that P ( n ) : 1 + 2 + + n =
2 2 2

n( n + 1)( 2n + 1) for all positive integers n. 6

2. 3.

!) + 2( 2!) + + n( n!) = ( n +1)!1 for all n 1. Prove that 1(1


Prove that

1 2 + 22 23 + ... + ( 1) n 2 n =

2n +1 (1) n + 1 for all positive integers n. 3

4. Prove that n( n +1) is even for every positive integer n. 5. 6. 7. Show that 1 + 2 n 3 n for all n 1. Show that n 3 > n 2 + 3 for all n 2. Show that (1 + x ) 1 + nx for all n 1, where x is any real number greater than -1.
n

8. Prove that you can make any postage of more than 4 cents by using only 2-cent and 5-cent stamps.

Part B: Recursion
9. Give a recursive definition with initial condition(s) of the following problems: i. Function f (n) = 2n, n = 1, 2, 3, .... ii. Function f (n) = 5n + 2, n = 1, 2, 3, .... iii. Sequence a1 = 16, a2 = 13, a3 = 10, a4 = 7, . iv. All positive integer multiples of 5. 10. Define recursively all palindroms (Palindroms are strings that can be read from front and behind giving the same word.). 11. Define the length of a string recursively. 12. We say that two strings are friends if they share a common substring. Define this notion mathematically. (Note: You have to define the meaning of substring first.)

-1-

TDS1191, Tutorial 4 13. Define #(s :: string, a :: char) int giving the number of occurrence of a in s recursively. 14. Define substitute(s :: string, old :: char, new :: char) which results in a new string based on s having all occurrence of old replaced by new. 15. Find a formula of p n = a

b b p n 1 . To simplify the notation, set s = . k k

16. The set S is defined recursively by 2 S and s + t S whenever s S and t S. Find S.

Part C: Algorithms
17. Use the Euclidean algorithm to find the gcd of each of the following pair of integers: (i) (72, 390) (ii) (825, 315) 18. Write a recursive algorithm that reverses a finite sequence. 19. Give a recursive algorithm to find n! mod m whenever n and m are positive integers. 20. Prove that: i. If f = O(g) and g = O(h) then also f = O(h). ii. If f=O(h) and g=O(h), then f+g=O(h). 21. Prove that the following functions are in O(xn) f ( x ) = 2 x 3 + x 2 log x , n=3 (i)

(ii)

f ( x) =

( x 3 + 2 x) , n=2 (2 x + 1)

22. Find the time function for the following code fragments: (i) for i := 1 to n do for j := 1 to n/2 do x := x + 1 (ii) for i := 1 to n do { int j = 1; while j < i do { j++; print(Hello.) } }

23. Find a theta notation in terms of n for the number of times the statement x = x + 1 is executed.

-2-

TDS1191, Tutorial 4 j=n while (j 1) { for i = 1 to j x=x+1 j=j/2 } - END -

-3-

You might also like