HW1-CS202 - HW-I 1-) My name is Ilker Koksal and I am using...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: HW-I 1-) My name is Ilker Koksal and I am using sorting the first 6 letters of the concatenation of my name. a-) Insertion Sort Initial Array: After 1st swap: After 2nd swap: After 3rd swap: After 4th swap: After 5th swap: After 6th swap: After 7th swap: After 8th swap: I I I I I E E E E L L K K E I I I I K K L E K K K K K E E E L L L L L K R R R R R R R K L b-) Bubble Sort L K E R K L K E R K I K L E R K I K E L R K I K E L R K I b-) I I a-) Initial Array: K E L K R I K E L K R I K E L K R I E K L K R I E K L K R I E K K L R K K K K K K K R R I E K K L R E I K K L R E I K K L R E I K K L R I LKERK c-) b-) Merge Sort Initial Array: I L K E I K R K E K R L E L K E R K E L K E R K E K E R K E 5-) L L K E R K a-) result = false; key = Desired value; for ( i ----> n ) // start to loop through the array { if (array[i] == key) // if match is found result = true; } If the desired item is not in the array, result must be false. b-) For both sorted and unsorted data, if desired item is not in the data = O(n) The best case performance is, if the desired item is the first index of the array, the best case performance : O(1) The worst case performance, if the desired item is the last item of the array, so the worst case performance : O(n) c-) As I showed at part a, the algorithm goes like this, so this algorithm is not interested in the array which is sorted or unsorted because, it is looking the key element, so the algorithm’s order does not depend upon whether or not the data items are sorted. ...
View Full Document

Page1 / 3

HW1-CS202 - HW-I 1-) My name is Ilker Koksal and I am using...

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