2Y DSA2 Tutorial1 2
2Y DSA2 Tutorial1 2
Exercise 2
Using Induction, prove the following formulas:
a) ∑ ( )
b) ∑ (∑ )
( )
You can make use the formula: ∑
Exercise 3
Proof by Contradiction that For all integers n, if n3+5 is odd then n is even.
Exercise 4
Let Fi be the Fibonacci numbers defined as Fk+1=Fk+Fk-1 such that F0=1and F1=1
● ∑
● such that ( √ ) ( is known as the Golden Ratio )
Exercise 5
Evaluate the following sums:
∑
∑
∑
1/2
∑ (Home)
Exercise 6
Write a recursive algorithm that returns the number of ones in the binary
representation of N. Use the fact that this is equal to the number of 1 in the
representation of N/2 when N is even. If N is odd, there is an additional 1.
● What is the number of zeros for a given binary number?
Exercise 7
Given a decimal number (For instance: 34892), write a recursive function to flip
the number from right to left ( → 29843 ) ( Please, don’t use String functions).
Exercise 8 (Home)
Write a function for computing the Fibonacci number using both paradigms:
iterative and recursive.
Exercise 9 (Home)
For a vending machine to return the change to the customer, it must return a
minimal number of coins. Write a recursive function to determine the number
of each type of coin to give back to the customer as part of the change.
(For example: 290 → 1x200DA + 1x50DA + 2x20DA)
Exercise 10 (Home)
For a given string (Example, “ABC”), write a recursive function to print to the
console all possible permutations of the given string.
( → ABC ACB BAC BCA CBA CAB )
2/2