• Home
  • Blog
  • Debug program to get specific output in ZyBooks (Code is written just need to fix indentation)

Debug program to get specific output in ZyBooks (Code is written just need to fix indentation)

0 comments

4.1 Bubble Sort

Implement the Bubblesort Algorithm presented in the lecture slides.

Each time you compare two elements in the array, print out the comparison.

Implement a function compareElements that does the comparison and also prints.

An example execution trace is given below.

Bubble Sort Test Question
Enter Seed for Testing:
10
Enter Test Size:
3
Bubble Sorting List
Initial List: [36, 2, 27]
Compare 36 to 2
Compare 36 to 27
Compare 2 to 27
Compare 27 to 36
Final List: [2, 27, 36]

You may add helper functions to the below starter file.

If you do not follow the lecture slides, your code may not pass the below tests. Even it it sorts correctly, it will be marked wrong.

4.2 Insertion Sort

Implement the Insertion Sort Algorithm presented in the lecture slides.

Each time you compare two elements in the array, print out the comparison.

An example execution trace is given below.

Insertion Sort Test Question
Enter Seed for Testing:
5
Enter Test Size:
3
Insertion Sorting List
Initial List: [39, 16, 47]
Compare 39 to 16
Compare 39 to 47
Final List: [16, 39, 47]

You may add helper functions to the below starter file.

If you do not follow the lecture slides, your code may not pass the below tests. Even it it sorts correctly, it will be marked wrong.

4.3 Merge Sort

Implement the Merge Sort Algorithm presented in the lecture slides.

Each time you compare two elements in the array, print out the comparison.

An example execution trace is given below.

Merge Sort Test Question
Enter Seed for Testing:
10
Enter Test Size:
6
Merge Sorting List
Initial List: [36, 2, 27, 30, 36, 0]
Compare 2 to 36
Compare 27 to 2
Compare 27 to 36
Compare 36 to 30
Compare 0 to 30
Compare 0 to 2
Compare 30 to 2
Compare 30 to 27
Compare 30 to 36
Compare 36 to 36
Final List: [0, 2, 27, 30, 36, 36]

You may add helper functions to the below starter file.

If you do not follow the lecture slides, your code may not pass the below tests. Even it it sorts correctly, it will be marked wrong.

4.4 Quick Sort

Implement the Quick Sort Algorithm presented in the lecture slides.

Each time you compare two elements in the array, print out the comparison.

An example execution trace is given below.

Quick Sort Test Question
Enter Seed for Testing:
10
Enter Test Size:
4
Quick Sorting List
Initial List: [36, 2, 27, 30]
Compare 36 to 30
Compare 2 to 30
Compare 27 to 30
Compare 2 to 27
Final List: [2, 27, 30, 36]

You may add helper functions to the below starter file.

If you do not follow the lecture slides, your code may not pass the below tests. Even it it sorts correctly, it will be marked wrong.

About the Author

Follow me


{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}