Question

In: Computer Science

Given the following array [17, 15,21,208,16,122,212,53,119,43] Apply bubble sort algorithm and show the status of the...

Given the following array
[17, 15,21,208,16,122,212,53,119,43]

Apply bubble sort algorithm and show the status of the array after each pass. Also calculate how many comparisons you will be required to pass

Solutions

Expert Solution

The array is given as,

17 , 15, 21, 208,16,122,21,53,119,43

1) first 17 and 15 are compared ---> comparison -1

Swap 15 and 17

2) Comparing 17 and 21 ------> comparison - 2

3) compare 21 and 208 ---------> comparison ->3

4) compare 208 and 16 ---------> comparison ->4

swap 16 and 208

5) compare 122 and 208 ---------> comparison ->5

swap 122 and 208

6) compare 208 and 212 ---------> comparison ->6

7) compare 212 and 53 ---------> comparison ->7

swap 212 and 53

8) Compare 212 and 119 ---------> Comparison -> 8

swap 119 and 212

9) compare 212 and 43 ---------> comparison ->9

swap 212 and 43

10) compare 15 and 17---------> comparison ->10

11) compare 17 and 21  ---------> comparison ->11

12) compare 21 and 16 ---------> comparison ->12

swap 16 and 21

13) compare 21 and 122 --------> comparison ->13

14 )compare 122  and 208 ---------> comparison ->14

15) compare 2018 and 53 ---------> comparison ->15

swap 53 and 208

16) compare 208 and 119 ---------> comparison ->16

swap 119 and 208

17) compare 208 and 43 ---------> comparison ->17

swap 208 and 43

18 ) compare 208 and 212 ------> comparison -> 18

19) compare 15 and 17 ---------> comparison ->19

20) compare 17 and 16 ---------> comparison ->20

swap 16 and 17

21) compare 17 and 21 ---------> comparison ->21

22) compare 21 and 122 ---------> comparison ->22

23) compare 122 and 53 ---------> comparison ->23

swap 53 and 122

24) compare 119 and 122 --------> comparison ->24

swap 119 and 122

25) compare 122 and 43 ---------> comparison ->25

swap 122 and 43

26) compare 122 and 208 ---------> comparison ->26

27) compare 208 and 212 ---------> comparison ->27

28) compare 16 ad 15 ---------> comparison ->28

29) compare 16 and 17 ---------> comparison ->29

30) compare 21 and 17 ---------> comparison ->30

31) compare 21 and 53 ---------> comparison ->31

32) compare 53 and 119 ---------> comparison ->32

33) compare 119 and 43 --------> comparison ->33

swap 43 and 119

34) compare 119 and 122 ---------> comparison ->34

35) compare 122 and 208 ---------> comparison ->35

36) compare 208 and 212 ---------> comparison ->36

37) compare 15 and 16---------> comparison ->37

38) compare 16 and 17 ---------> comparison ->38

39) compare 17 and 21 ---------> comparison ->39

40) compare 21 and 53 ---------> comparison ->40

41) compare 53 and 43 ---------> comparison ->41

swap 43 and 53

42) compare 53 and 119 ---------> comparison ->42

43) compare 119 and 122 ---------> comparison ->43

44) compare 122 and 208 ---------> comparison -> 44

45 ) compare 208 and 212 ----------> comparison-> 45

there are 45 comparisons and 16 swaps made and the sorted array is :

15,16,17,21,43,53,119,122,208,212.


Related Solutions

For the given array, simulate the working operation of Bubble Sort. Show your work at each...
For the given array, simulate the working operation of Bubble Sort. Show your work at each step. Make sure to show the status of the array after every swap. [ 28, 13, 22, 7, 34, 2 ]
5. (20 marks) Write a recursive Bubble Sort algorithm that takes an array A of n...
5. Write a recursive Bubble Sort algorithm that takes an array A of n numbers as input. Analyze its time complexity using a recursion tree. Implement your algorithm in Java
Sort the following set of numbers using bubble sort, insertion sort, and selection sort. Show the...
Sort the following set of numbers using bubble sort, insertion sort, and selection sort. Show the process step-by-step, and find the time complexity in Big-O notation for each method. For sorting, use ascending order. 49, 7, 60, 44, 18, 105
Write a program and test a program that translates the following Bubble Sort algorithm to a...
Write a program and test a program that translates the following Bubble Sort algorithm to a bubblesort function. The function's prototype is, void bubblesort(int a[], int size); Bubble Sort The inner loop moves the largest element in the unsorted part of the array to the last position of the unsorted part of the array; the outer loop moves the last position of the unsorted part of the array. The Bubble sort exchanges elements with adjacent elements as it moves the...
What is the number of comparisons in the bubble sort algorithm, if it is used to...
What is the number of comparisons in the bubble sort algorithm, if it is used to sort a list of n-entries? Justify your formula.
How would I make a bubble sort and an optimized bubble sort with the code given?...
How would I make a bubble sort and an optimized bubble sort with the code given? I also need to implement a timer into each sort and display runtime with the sorts. NODE.H _______________________________________________________________________________________________________ /* node.h */ /* two classes 1: node.h 2. singlylinkedlist.h nod1 (value + pointer) ---> node2 ---> node3 ---> |||| <--- node.h ^ | singlylinkedlist ----------------*node head; */ #ifndef NODE_H #define NODE_H #include <iostream> using namespace std; class Node {    friend class singlyLinkedList; public:   ...
Apply Algorithm split on the array 27 ،13، 31،18، 45 ،16، 17، 53 .
Apply Algorithm split on the array 27 ،13، 31،18، 45 ،16، 17، 53 .
Write Insertion Sort and Bubble Sort Program for C# also write their algorithm and Explain their...
Write Insertion Sort and Bubble Sort Program for C# also write their algorithm and Explain their working.
ASSEMBLY PROGRAM!!! QtSpim Sorting Data Add the Bubble Sort to minMaxArray.asm to sort the array into...
ASSEMBLY PROGRAM!!! QtSpim Sorting Data Add the Bubble Sort to minMaxArray.asm to sort the array into ascending order. Use the Bubble Sort algorithm from the lecture. You can use either Base Addressing or Indexed Addressing for the arrays. For this assignment, make sure you prompt the user for the numbers. Do not hard-code them in the data section. NOTE: Declare the array last in the Data section.
// This program uses a bubble sort to arrange an array of integers in // ascending...
// This program uses a bubble sort to arrange an array of integers in // ascending order (smallest to largest). It then display the array // before the sorting and after the sorting. Modify the program so it orders // integers in descending order (largest to smallest). Then add some code // to display the array at each step of the algorithm. You don't have to // modify anything in the main() function. All modification are inside // the bubbleSortArray()...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT