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

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

View Full Document Right Arrow Icon
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
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/01/2010 for the course CS cs-202 at Bilkent University.

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 Right Arrow Icon
Ask a homework question - tutors are online