# Towers of Hanoi algorithm

5. When we analyzed the Towers of Hanoi algorithm, we counted the number of moves of individual rings, implicitly assuming that this operation takes constant time. Suppose instead that the time it takes to move a single ring is proportional to the size of the ring, meaning that the ith-smallest ring takes Θ(i) time to move, for each 1 ≤ i ≤ n. Write the resulting recurrence for the running time of the algorithm, and solve that recurrence.

Get Your Custom Essay Written From Scratch
Are You Overwhelmed With Writing Assignments?
Give yourself a break and turn to our top writers. They’ll follow all the requirements to compose a premium-quality piece for you.

6. The best case running time for insertion sort is when the input array is pre-sorted, like (1, 2, . . . , n). In this case, insertion sort performs zero swaps and runs in Θ(n) time; even with no swaps, it still performs n iterations of its outer for loop. Suppose that we “cut” that array like a deck of cards to get the input array (i + 1, i + 2, . . . , n, 1, 2, . . . , i) for some i ∈ {1, . . . , n}. In terms of i and n, exactly how many swaps does insertion sort perform on this input, and what is its asymptotic (big-Θ) running time?