Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Python Consider the incomplete function below: def selection_sort(data): for num_iterations in range(len(data) - 1, 0, -1): position_largest = 0 Complete the selection_sort() function above so
Python
Consider the incomplete function below: def selection_sort(data): for num_iterations in range(len(data) - 1, 0, -1): position_largest = 0 Complete the selection_sort() function above so that it returns the total number of elements and the total number of updates of the position of the largest element in the list to sort the numbers list. (1.e. when the function finds a new largest element, the function updates the position of the largest element in the list of a current pass.) The function must return these 2 values as a tuple. Note: You are not allowed to use the sort() or sorted or reverse() or reversed() or the slicing trick "[::-1)" anywhere in your solution. Consider the following unsorted list: numbers = [54, 48, 70, 79] The number of updates for the position_largest in the first pass is 2. (i.e position_largest: 0 --> 2 --> 3) The number of updates for the position_largest in the second pass is 1. (i.e position_largest: 0 --> 2) The number of updates for the position_largest in the third pass is 0. As a result, the total number of updates is 3. For example: Test Result (5, 4) numbers = [2, 16, 7, 11, 1] data = selection_sort(numbers) print(data) numbers = [29, 10, 14, 37, 13] (5, 2) data = selection_sort (numbers) print(data)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
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