Attempt by: Monday, February 12
Due by: Thursday, February 15
*** Deadline extended to Monday, February 19 ***
Reread Chapter 3 of the textbook.
The following problems will give you extra practice with algorithms, and are strongly recommended, but you don't need to turn them in. Solutions are given on page 687, but don't look at the answers until you have tried working through them on your own.
From the textbook, Chapter 3:
Consider the following algorithm:
Input a list of n values V1, V2, ... Vn Set i to 1 While i < n and Vi < Vn do Set i to i + 1 (End of loop) Set x to Vn Set j to n While j > i do Set Vj to Vj-1 Set j to j - 1 (End of loop) Set Vi to x
Show what this algorithm does given the following input list:
3, 5, 24, 7, 9 (n = 5)
How many set instructions are executed in the best and worst case, in terms of n?
What is this algorithm's order of magnitude worst-case complexity?