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.


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?

Need assignment help for this question?

If you need assistance with writing your essay, we are ready to help you!






Why Choose Us: Cost-efficiency, Plagiarism free, Money Back Guarantee, On-time Delivery, Total Сonfidentiality, 24/7 Support, 100% originality

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply