Professional Documents
Culture Documents
CH 7 Bubble Sort
CH 7 Bubble Sort
[5, 2, 9, 3, 4, 1]
Please write the steps of the Bubble Sort algorithm in pseudo code to sort this list in ascending order.
Include all the necessary loops, comparisons, and swaps, and make sure to explain each step of the
algorithm as you go along.
Additionally, calculate the total number of comparisons and swaps required to sort the given list using
the Bubble Sort algorithm.
SOL :
FIRST = 1
LAST = 6
REPEAT
SWAP = FALSE
FOR Index FIRST TO LAST -1
IF NUM {INDEX} > NUM {INDEX +1}
THEN
TEMP = NUM{ INDEX }
NUM {INDEX } = NUM {INDEX +1}
NUM {INDEX +1} = TEMP
SWAP = TRUE
END IF
NEXT INDEX
LAST = LAST -1
UNTIL (NOT SWAP) OR LAST = 1
CH7 LINER SEARCH
Write the steps of a Linear Search algorithm in pseudo code to search for a specific target value within
this array. Include all the necessary loops and comparisons. Assume the target value is 56. Explain the
algorithm step by step and determine if the target value is found in the array. If found, also provide the
index at which it is located. If not found, indicate that it's not present in the array.
Additionally, calculate the total number of comparisons required to search for the target value in the
given array using the Linear Search algorithm.