Python
complete questions only 1- 3
Projects
1. A sequential search of a sorted list can halt when the target is less than a given element in the list. Define a modified version of this algorithm, and state the computational complexity, using big-0 notation, of its best-, worst-, and average-case performances.
2. The list method reverse reverses the elements in the list. Define a function amed reverse that reverses the elements in its list argument . Try to make this function as efficient as possible, and state its computational complexity using big-0 notation.
3. Python’s pow function returns the result of raising a number to a given power. Define a function expo that performs this task, and state its computational complexity using big-0 notation. The first argument of this function is the number, and the second argument is the exponent. You may use either a loop or a recursive function in your implementation. Caution: do not use Python’s ** operator or pow function in this exercise!
4. An alternative strategy for the expo function uses the following recursive definition:
expo
= 1, when exponent
= 0 = number * expo(number, exponent – 1), when exponent is odd
= 2, when exponent is even
Define a recursive function expo that uses this strategy, and state its computational complexity using big-0 notation.
5. Python’s 1 i st method sort includes the keyword argument reverse, whose default value is False. The programmer can override this value to sort a list in descending order. Modify the selection Sort function discussed in this chapter so that it allows the programmer to supply this additional argument to redirect the sort.
Define a modified version of this algorithm, and state the computational complexity, using big-0 notation, of its best-, worst-, and average-case performances.
Share :
Latest News
Discover your perfect program in our courses.