Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David M. Kroenke

1st Edition

0130086509, 978-0130086501

More Books

Students also viewed these Databases questions

Question

7. List behaviors to improve effective leadership in meetings

Answered: 1 week ago

Question

6. Explain the six-step group decision process

Answered: 1 week ago