Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!