{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# hw01_sol - CS202Hw1Solutions CS202 HW1 Solutions(Updated...

This preview shows pages 1–3. Sign up to view the full content.

CS202 Hw1 Solutions 1 CS202 HW1 Solutions (Updated) Question-1 (30 points) Trace the following sorting algorithm for sorting the array: 6 1 9 3 2 5 into ascending order. Use the array implementation as described in the textbook/lectures. a) Insertion sort. Initial Array 6 1 9 3 2 5 After pass 1 1 6 9 3 2 5 After pass 2 1 6 9 3 2 5 After pass 3 1 3 6 9 2 5 After pass 4 1 2 3 6 9 5 After pass 5 1 2 3 5 6 9 b) Selection sort. Initial Array 6 1 9 3 2 5 After 1 st swap 6 1 5 3 2 9 After 2nd swap 2 1 5 3 6 9 After 3rd swap 2 1 3 5 6 9 After 4th swap 2 1 3 5 6 9 After 5th swap 1 2 3 5 6 9 c) Bubble sort. Pass 1 Initial Array 6 1 9 3 2 5 1 6 9 3 2 5 1 6 9 3 2 5 1 6 3 9 2 5 1 6 3 2 9 5 1 6 3 2 5 9 Pass 2 1 6 3 2 5 9 1 6 3 2 5 9 1 3 6 2 5 9 1 3 2 6 5 9 1 3 2 5 6 9

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
2 Pass 3 1 3 2 5 6 9 1 3 2 5 6 9 1 2 3 5 6 9 1 2 3 5 6 9 Pass 4 1 2 3 5 6 9 1 2 3 5 6 9 1 2 3 5 6 9 d) Mergesort. Also list the calls to mergesort and merge in the order in which they occur. 6 1
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 5

hw01_sol - CS202Hw1Solutions CS202 HW1 Solutions(Updated...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online