Question

PYTHON Fill in 3 numbers to complete the following 'list', as shown: 35 62 ___ 40...

PYTHON

Fill in 3 numbers to complete the following 'list', as shown:

35 62 ___ 40 ___ 18 ___ 1 55 28

add the month, day, and year you were born in the 3 spaces shown (in that order). (Use a 4-digit year.)

Using the list of numbers above, write 4 different sort trace tables like those produced by the practice program linked above:

  1. Sort using the BubbleSort algorithm in ascending order.
  2. Sort using the BubbleSort algorithm in descending order.
  3. Sort using the Selection Sort algorithm in ascending order.
  4. Sort using the Selection Sort algorithm in descending order.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

thanks for the question, here are the 4 functions, and the complete code.

==================================================================

def bubblesortAscendingOrder(nums):
    for i in range(0, len(nums)):
        for j in range(0, len(nums) - 1 - i):
            if nums[j] > nums[j + 1]: nums[j], nums[j + 1] = nums[j + 1], nums[j]


def bubblesortDescendingOrder(nums):
    for i in range(0, len(nums)):
        for j in range(0, len(nums) - 1 - i):
            if nums[j] < nums[j + 1]: nums[j], nums[j + 1] = nums[j + 1], nums[j]


def selectionsortAscendingOrder(nums):
    for i in range(len(nums)):
        min_index=i
        for j in range(i+1,len(nums)):
            if nums[min_index]>nums[j]:min_index=j
        nums[min_index],nums[i]=nums[i],nums[min_index]

def selectionsortDescendingOrder(nums):
    for i in range(len(nums)):
        max_index=i
        for j in range(i+1,len(nums)):
            if nums[max_index]<nums[j]:max_index=j
      nums[max_index],nums[i]=nums[i],nums[max_index]


def main():

    nums = [36,62,11,40,19,18,1990,155,28]
    bubblesortAscendingOrder(nums)
    print('Bubble Sort ascending order     : ',nums)

    nums = [36,62,11,40,19,18,1990,155,28]
    bubblesortDescendingOrder(nums)
    print('Bubble Sort descending order    : ',nums)

    nums = [36,62,11,40,19,18,1990,155,28]
    selectionsortAscendingOrder(nums)
    print('Selection Sort ascending order : ',nums)

    nums = [36,62,11,40,19,18,1990,155,28]
    selectionsortDescendingOrder(nums)
    print('Selection Sort descending order : ',nums)

main()

==========================================================================

main.py O saved : , [11, 18, 19, 28, 36, 40, 62, 155, 1990]) : , [1990, 155, 62, 40, 36, 28, 19, 18, 11]} : , [11, 18, 19,

Add a comment
Know the answer?
Add Answer to:
PYTHON Fill in 3 numbers to complete the following 'list', as shown: 35 62 ___ 40...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Consider the following python code that will sort the list of numbers using the Bubble Sort...

    Consider the following python code that will sort the list of numbers using the Bubble Sort algorithm def bubbleSort(alist): print(alist) for j in range (len(alist) - 1, 8, -1): for i in range(): if alist[i] > alist[i + 1]: temp = alist[i] alist[i] = alist[i+1] alist[i+1] = temp print(alist) alist = [52, 25, 94, 17, 25, 52] bubbleSort (alist) print(alist) Sort the following series of values into ascending order using the Bubble Sort algorithm. Write out the complete row of...

  • Please solve this problem using Python Write a quicksort method that accept a list of numbers...

    Please solve this problem using Python Write a quicksort method that accept a list of numbers and use list comprehension to construct the method. Note that you need to sort the numbers in descending order . You MUST use List Comprehension to do the sorting Your program should contain the function with format shown as below: def quicksort(a): # Your codes here. Use List Comprehension and return the result.

  • Directions: Problem 1: Write (using pen-and-paper rather than code) the list after each pass of quick...

    Directions: Problem 1: Write (using pen-and-paper rather than code) the list after each pass of quick and merge sort for the following list of numbers. Assume that you are sorting the numbers into ascending order. For quick sort, assume that the first number from the sublist is chosen as the pivot. 54 17 21 18 4 7 19 41 Problem 2: Write the list after each pass of the quick sort algorithm for the following list of numbers, using the...

  • Using c++ Write a program that reads in a list of up to 25 first names...

    Using c++ Write a program that reads in a list of up to 25 first names from an input file nameData.txt and allows the user to display the name data, sort it in ascending or descending order, count the number of occurrences of a given name, or exit the program. The input file consists of a single names per line with each line terminated with an end of line (i.e. using Enter key to end the line). Your program should...

  • Written in Java Your job is to produce a program that sorts a list of numbers...

    Written in Java Your job is to produce a program that sorts a list of numbers in ascending order. Your program will need to read-in, from a file, a list of integers – at which point you should allow the user an option to choose to sort the numbers in ascending order via one of the three Sorting algorithms that we have explored. Your program should use the concept of Polymorphism to provide this sorting feature. As output, you will...

  • C++ Sorting and Searching 1. Mark the following statements as true or false. a. A sequential...

    C++ Sorting and Searching 1. Mark the following statements as true or false. a. A sequential search of a list assumes that the list elements are sorted in ascending order. b. A binary search of a list assumes that the list is sorted. 2. Consider the following list: 63 45 32 98 46 57 28 100 Using a sequential search, how many comparisons are required to determine whether the following items are in the list or not? (Recall that comparisons...

  • Radix sort C++ Come up with an unsorted array of numbers (integer array). Sort the numbers...

    Radix sort C++ Come up with an unsorted array of numbers (integer array). Sort the numbers in ascending order and descending order and display them using radix sort. First sort in ascending, then reset the array to its original order and finally sort the array again in descending order. USE THIS STUCTURE struct nodeQ{                            node *front;                            node *rear;               };               nodeQ que[10]; enqueue(que[i],data); EXAMPLE: Original, unsorted list: [170, 45, 75, 90, 2, 802, 24, 66] 1ST PASS:...

  • Python Help Please Problem 4-4: Make a list of 20 numbers and place them in a...

    Python Help Please Problem 4-4: Make a list of 20 numbers and place them in a random order (don't arrange them in ascending or descending order - make sure the list is truly random). Calculate and print out the largest number in the list and the lowest number in the list. Problem 4-5: Make a list of multiples of 5 between 1 and 100. Once you have your list, print it out. Problem 4-6: Generate a list of values from...

  • Consider the list myList: myList = ["a", "America", "1", [5,3,9], "3", ["Mercy"]] #1 1) The Python...

    Consider the list myList: myList = ["a", "America", "1", [5,3,9], "3", ["Mercy"]] #1 1) The Python statement __________________ returns a #2 2) The Python statement __________________ returns America #3 3) The Python statement __________________ returns Ame #4 The type of the third element is _______. #6 The Python statement __________________ returns the following: ['Mercy'] #7 The python statement temp = _______ converts the third element to integer and assigns the result to temp. #8 Consider the fourth element of myList...

  • Need help with program. I'm stuck Objectives: In this assignment, we will practice manipulating lists of...

    Need help with program. I'm stuck Objectives: In this assignment, we will practice manipulating lists of data and arranging items in an ascending/descending order. you will also explore storing lists/arrays using different sorting algorithms including, the selection sort, bubble sort, and insertion sort algorithm. Comparison between the three algorithms are made based on the number of comparisons and item assignments (basic operations) each algorithms executes. Background: Ordering the elements of a list is a problem that occurs in many computer...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT