0% found this document useful (0 votes)
11 views1 page

Computer Algorithms - Homework Assignment 3

The document outlines a homework assignment focused on computer algorithms, including tasks related to Fibonacci sequence generation, counting ways a child can ascend stairs, solving the Towers of Hanoi puzzle, and analyzing the Closest Pair of Points and Counting Inversions problems. Each task requires the design of both recursive and dynamic programming algorithms, along with asymptotic analysis of recursive calls and running times. The assignment emphasizes understanding algorithm design and analysis through practical problem-solving.

Uploaded by

s112701018.mg12
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views1 page

Computer Algorithms - Homework Assignment 3

The document outlines a homework assignment focused on computer algorithms, including tasks related to Fibonacci sequence generation, counting ways a child can ascend stairs, solving the Towers of Hanoi puzzle, and analyzing the Closest Pair of Points and Counting Inversions problems. Each task requires the design of both recursive and dynamic programming algorithms, along with asymptotic analysis of recursive calls and running times. The assignment emphasizes understanding algorithm design and analysis through practical problem-solving.

Uploaded by

s112701018.mg12
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Computer Algorithms – Homework Assignment 3

1. (10%) Design a recursive algorithm without memorization to output the nth


integer in Fibonacci sequence (1, 1, 2, 3, 5, 8, ...). (5%) What is the number of
recursive calls asymptotically?
(10%) Design a dynamic programming algorithm to do the same thing.
2. A child is running up the staircase with n steps and can hop either 1 step, 2
steps, or 3 steps at a time. (10%) Design a recursive algorithm without
memorization to count how many possible ways that the child can run up the
stairs. (5%) What is the number of recursive calls asymptotically?
For example, when n= 3, the answer is 4 and the 4 possible ways are:
● 1, 1, 1
● 2, 1
● 1, 2
● 3
(10%) Design a dynamic programming algorithm to count how many possible
ways that the child can run up the stairs. (5%) What is the running time of this
dynamic programming algorithm in terms of n asymptotically?
(5%) Do you get the same answer in these two approaches?
3. The puzzle called the Towers of Hanoi consists of three pegs, one of which
contains several rings stacked in order of descending diameter from bottom to
top. The problem is to move the stack of rings to another peg. You are allowed
to move only one ring at a time, and at no time is a ring to be placed on top of
a smaller one. Observe that if the puzzle involved only one ring, it would be
extremely easy. Moreover, when faced with the problem of moving several
rings, if you could move all but the largest ring to another peg, the largest ring
could then be placed on the third peg, and then the problem would be to move
the remaining rings on top of it.
Using this observation, develop a recursive algorithm for solving the Towers of
Hanoi puzzle for an arbitrary number of rings, given a source peg where all
the rings initially reside in and a destination peg where all the rings end up in.
(i) (10%) Display every move in details, i.e., which ring moved from which peg
to which peg for each move. Note that the rings, which begin on one of the
pegs, are numbered 1, 2, 3, and so on, starting with the smallest ring being 1.
(ii) (10%) Output the total number of moves in the end.
4. (10%) For Closest Pair of Points, on p.32 of the slides for Divide and Conquer,
show that no two points lie in the same δ/2-by-δ/2 box (Hint: proof by
contradiction).
5. (5%+5%) For Counting Inversions, on p.18, if the sublist in blue and that in
green are sorted, write down the number of inversions for each value in the
sublist in blue against the sublist in green, and also write down exactly all the
inversions cross the two sublists in the order of running the “linear” approach
on p.19.

You might also like