Design an algorithm that will take a list of numbers and partially reverse it, without making use of a second list variable. Starting at each
Design an algorithm that will take a list of numbers and partially reverse it, without making use of a second list variable. Starting at each end, the alternating entries of the list should be swapped. (Your solution may not use python's reverse function or slicing.)
Example of the algorithm:
Input = [1, 2, 3, 4, 5, 6, 7, 8]
Output = [8, 2, 6, 4, 5, 3, 7, 1]
----------------------------------------------------
Input = [1, 2, 3, 4, 5, 6, 7, 8, 9]
Output = [9, 2, 7, 4, 5, 6, 3, 8,1]
----------------------------------------------------
Input = [1, 2]
Output = [2 ,1]
----------------------------------------------------
Input = [1 , 2 , 3]
Output = [3 , 2 ,1]
----------------------------------------------------
i. Work out the steps to figure out a concrete example and briefly explain your work and thinking
ii. Find and describe a pattern and attempt to generalize
iii. Investigate and explain all special cases to see if the pattern holds up
iv. Come up with a solution and write your own python function rearrange_list(my_list: list) that rearranges the list as described above
- The function should return the altered list (not a new or different list variable).
- Call your function with various lists to test it, print the list before and after the call to test it.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started