Question: Below is a bubble_up function that takes 3 parameters: the list, a start index, and an end index, and bubbles the items in that range.

Below is a bubble_up function that takes 3 parameters: the list, a start index, and an end index, and bubbles the items in that range. We have started a function called bubble_down that takes the same 3 parameters but bubbles in the opposite direction. Complete function bubble_down.

 

1

def bubble_up(L: list, start: int, end: int) -> None:

2

 """Bubble up through L[start:end], swapping items that are out of order.

3

 

4

 >>> L = [4, 3, 2, 1, 0]

5

 >>> bubble_up(L, 0, 3)

6

 >>> L

7

 [3, 2, 1, 4, 0]

8

 >>> L = [4, 3, 2, 1, 0]

9

 >>> bubble_up(L, 2, 4)

10

 >>> L

11

 [4, 3, 1, 0, 2]

12

 """

13

 

14

 for i in range(start, end):

15

 if L[i] > L[i + 1]:

16

 L[i], L[i + 1] = L[i + 1], L[i]

def bubble_down(L: list, start: int, end: int) -> None: """Bubble down through L from indexes end through start, swapping items that are out of place.

>>> L = [4, 3, 2, 1, 0]

>>> bubble_down(L, 1, 3)

>>> L [4, 1, 3, 2, 0] """

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!