Question
2). Sort the list E, X, A, M, P, L, E in alphabetical order by bubble sort. Trace the execution steps also besides providing the pseudo code.
Note: include the actual list elements in the execution of the algorithms.
Solution Preview
This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.
We can consider our array to sort by Selection Sort being A[0..6] where A[0]=E, A[1]=X,…A[6]=E.The above pseudocode can be equivalently rewritten as:
For i=0 to 7-2=5 do Min=i
For j=i+1 to 7-1=6 do
If A(j) < A(min) min=j
Swap A(i) with A(min)
Step1)
i=0=> min=0
for j=1 to 6 do if A(j)< A(min) min=j
swap A(0) with A(min)
j=1=> if A(1) <A(0) => X <E nothing
j=2=> if A(2) <A(0)=> A<E => min=2
j=3=> if A(3)<A(2)=> M < A nothing
j=4=> if A(4) < A(2)=> P < A nothing
j=5=> if A(5) < A(2) => L < A nothing
j=6=> If A(6) <A(2)=> E < A nothing
swap (A(0), A(2))= > swap (E, A)=A, E => the array is A X E M P L E
Step2)...