Sorting Examples CS 202 Department of Computer Engineering Bilkent University Slides adapted from Aybar Acar Spring 2015 Spring 2015 � 2015, CS 202 (Bilkent University) c 1 / 14
Playing Cards Spring 2015 � 2015, CS 202 (Bilkent University) c 2 / 14
Insertion Sort: Random Input Outer : j = 1 Inner : i = 0 Ops : 0 Spring 2015 � 2015, CS 202 (Bilkent University) c 3 / 14
Insertion Sort: Sorted Input Outer : j = 1 Inner : i = 0 Ops : 0 Spring 2015 � 2015, CS 202 (Bilkent University) c 4 / 14
Insertion Sort: Reverse Sorted Input Outer : j = 1 Inner : i = 0 Ops : 0 Spring 2015 � 2015, CS 202 (Bilkent University) c 5 / 14
Selection Sort: Random Input Outer : j = − 1 Inner : i = − 1 Ops : 0 Spring 2015 � 2015, CS 202 (Bilkent University) c 6 / 14
Selection Sort: Sorted Input Outer : j = − 1 Inner : i = − 1 Ops : 0 Spring 2015 � 2015, CS 202 (Bilkent University) c 7 / 14
Selection Sort: Reverse Sorted Input Outer : j = − 1 Inner : i = − 1 Ops : 0 Spring 2015 � 2015, CS 202 (Bilkent University) c 8 / 14
Bubble Sort: Random Input Outer : j = − 1 Inner : i = − 1 Ops : 0 Spring 2015 � 2015, CS 202 (Bilkent University) c 9 / 14
Bubble Sort: Reverse Sorted Input Outer : j = − 1 Inner : i = − 1 Ops : 0 Spring 2015 � 2015, CS 202 (Bilkent University) c 10 / 14
Merge Sort: Merge Step p q r A: ... ... 1 4 5 7 2 3 6 8 ... ... Spring 2015 � 2015, CS 202 (Bilkent University) c 11 / 14
Merge Sort: Merge Step p q r A: ... ... 1 4 5 7 2 3 6 8 ... ... 0 1 2 3 4 0 1 2 3 4 L: R: 1 4 5 7 2 3 6 8 8 8 Spring 2015 � 2015, CS 202 (Bilkent University) c 11 / 14
Merge Sort: Merge Step 0 1 2 3 4 0 1 2 3 4 1 4 5 7 2 3 6 8 8 8 p q r ... ... 1 4 5 7 2 3 6 8 ... ... Spring 2015 � 2015, CS 202 (Bilkent University) c 12 / 14
Merge Sort: Random Input Spring 2015 � 2015, CS 202 (Bilkent University) c 13 / 14
Merge Sort: Reverse Sorted Input Spring 2015 � 2015, CS 202 (Bilkent University) c 14 / 14
Recommend
More recommend