Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Overview: In this lab, you will trace (walk through) two algorithms for sorting

ID: 3702344 • Letter: O

Question

Overview: In this lab, you will trace (walk through) two algorithms for sorting and searching. l. Bubble Sort Trace through one pass of the Bubble Sort algorithm over the following array. Be as detailed as possible, describing which items are compared, which items are swapped, and what the array looks like after the first pass. Is the entire sequence in sorted order after the first pass over the array? 5 7 Il. Binary Search Trace the binary search algorithm on the following input, if we are searching for the element 6. Be as detailed as possible, describing which items are compared, which sub-arrays are being examined, and how many steps the algorithm takes in this case. 2 4 7 10 13

Explanation / Answer

[5, 3, 8, 1, 7] : 5 3 being compared and Swapped *** --> [3, 5, 8, 1, 7] [3, 5, 8, 1, 7] : 5 8 being compared --> [3, 5, 8, 1, 7] [3, 5, 8, 1, 7] : 8 1 being compared and Swapped *** --> [3, 5, 1, 8, 7] [3, 5, 1, 8, 7] : 8 7 being compared and Swapped *** --> [3, 5, 1, 7, 8] [3, 5, 1, 7, 8] : 3 5 being compared --> [3, 5, 1, 7, 8] [3, 5, 1, 7, 8] : 5 1 being compared and Swapped *** --> [3, 1, 5, 7, 8] [3, 1, 5, 7, 8] : 5 7 being compared --> [3, 1, 5, 7, 8] [3, 1, 5, 7, 8] : 3 1 being compared and Swapped *** --> [1, 3, 5, 7, 8] [1, 3, 5, 7, 8] : 3 5 being compared --> [1, 3, 5, 7, 8] [1, 3, 5, 7, 8] : 1 3 being compared --> [1, 3, 5, 7, 8] Sorted array is: [1, 3, 5, 7, 8] Considered array: [2, 4, 6, 7, 9, 10, 13] Middle element: 7 Element is present at index 3