Sorting … and Insertion Sort.

Slides:



Advertisements
Similar presentations
CMPT 225 Sorting Algorithms Algorithm Analysis: Big O Notation.
Advertisements

Quick Sort, Shell Sort, Counting Sort, Radix Sort AND Bucket Sort
DIVIDE AND CONQUER APPROACH. General Method Works on the approach of dividing a given problem into smaller sub problems (ideally of same size).  Divide.
Sorting Algorithms. Motivation Example: Phone Book Searching Example: Phone Book Searching If the phone book was in random order, we would probably never.
CMPS1371 Introduction to Computing for Engineers SORTING.
CS203 Programming with Data Structures Sorting California State University, Los Angeles.
the fourth iteration of this loop is shown here
Insertion sort, Merge sort COMP171 Fall Sorting I / Slide 2 Insertion sort 1) Initially p = 1 2) Let the first p elements be sorted. 3) Insert the.
Sorting. Input: A sequence of n numbers a 1, …, a n Output: A reordering a 1 ’, …, a n ’, such that a 1 ’ < … < a n ’
Simple Sorting Algorithms
Cmpt-225 Sorting. Fundamental problem in computing science  putting a collection of items in order Often used as part of another algorithm  e.g. sort.
Sorting 2 An array a is sorted (ascending order) if: for all i a[i]  a[j] Probably the most well-studied algorithmic problem in Computer Science There.
Searching and Sorting Arrays
Simple Sorting Algorithms. 2 Bubble sort Compare each element (except the last one) with its neighbor to the right If they are out of order, swap them.
Sorting Example Insertion Sort. Insertion Sort Sorting problem: n Given an array of N integers, rearrange them so that they are in increasing order. Insertion.
Simple Sorting Algorithms. 2 Outline We are going to look at three simple sorting techniques: Bubble Sort, Selection Sort, and Insertion Sort We are going.
Advance Data Structure 1 College Of Mathematic & Computer Sciences 1 Computer Sciences Department م. م علي عبد الكريم حبيب.
HKOI 2006 Intermediate Training Searching and Sorting 1/4/2006.
1 Today’s Material Iterative Sorting Algorithms –Sorting - Definitions –Bubble Sort –Selection Sort –Insertion Sort.
Sorting – Insertion and Selection. Sorting Arranging data into ascending or descending order Influences the speed and complexity of algorithms that use.
Fundamentals of Algorithms MCS - 2 Lecture # 15. Bubble Sort.
Chapter 18: Searching and Sorting Algorithms. Objectives In this chapter, you will: Learn the various search algorithms Implement sequential and binary.
1 Introduction to Sorting Algorithms Sort: arrange values into an order Alphabetical Ascending numeric Descending numeric Two algorithms considered here.
3 – SIMPLE SORTING ALGORITHMS
1 Sorting (Bubble Sort, Insertion Sort, Selection Sort)
Review 1 Selection Sort Selection Sort Algorithm Time Complexity Best case Average case Worst case Examples.
UNIT 5.  The related activities of sorting, searching and merging are central to many computer applications.  Sorting and merging provide us with a.
Lecture No. 04,05 Sorting.  A process that organizes a collection of data into either ascending or descending order.  Can be used as a first step for.
Chapter 9 Sorting. The efficiency of data handling can often be increased if the data are sorted according to some criteria of order. The first step is.
Searching and Sorting Searching: Sequential, Binary Sorting: Selection, Insertion, Shell.
Selection Sort main( ) { int a[ ] = { 17, 6, 13,12, 2 } ; int i, j, t ; for ( i = 0 ; i
Computer Science 1620 Sorting. cases exist where we would like our data to be in ascending (descending order) binary searching printing purposes selection.
Review 1 Merge Sort Merge Sort Algorithm Time Complexity Best case Average case Worst case Examples.
Sorting & Searching Geletaw S (MSC, MCITP). Objectives At the end of this session the students should be able to: – Design and implement the following.
INTRO2CS Tirgul 8 1. Searching and Sorting  Tips for debugging  Binary search  Sorting algorithms:  Bogo sort  Bubble sort  Quick sort and maybe.
Algorithm Design Techniques, Greedy Method – Knapsack Problem, Job Sequencing, Divide and Conquer Method – Quick Sort, Finding Maximum and Minimum, Dynamic.
Chapter 11 Sorting Acknowledgement: These slides are adapted from slides provided with Data Structures and Algorithms in C++, Goodrich, Tamassia and Mount.
Sorting.
Insertion sort Loop invariants Dynamic memory
CSCE 210 Data Structures and Algorithms
Chapter 9: Sorting and Searching Arrays
Alternate Version of STARTING OUT WITH C++ 4th Edition
CS212: Data Structures and Algorithms
Growth of Functions & Algorithms
May 17th – Comparison Sorts
Analysis of Algorithms
Introduction to Search Algorithms
Chapter 9: Searching, Sorting, and Algorithm Analysis
Recitation 13 Searching and Sorting.
Simple Sorting Algorithms
Algorithm Analysis CSE 2011 Winter September 2018.
Data Structures and Algorithms
Bubble Sort Bubble sort is one way to sort an array of numbers. Adjacent values are swapped until the array is completely sorted. This algorithm gets its.
Binary Search Back in the days when phone numbers weren’t stored in cell phones, you might have actually had to look them up in a phonebook. How did you.
Linear and Binary Search
Describing algorithms in pseudo code
Advanced Sorting Methods: Shellsort
Ch 7: Quicksort Ming-Te Chi
8/04/2009 Many thanks to David Sun for some of the included slides!
Simple Sorting Methods: Bubble, Selection, Insertion, Shell
Insertion Sort Demo Sorting problem:
Simple Sorting Algorithms
Simple Sorting Algorithms
Simple Sorting Algorithms
Quicksort and Randomized Algs
Algorithms.
Discrete Mathematics CS 2610
Algorithm Course Algorithms Lecture 3 Sorting Algorithm-1
Advanced Sorting Methods: Shellsort
the fourth iteration of this loop is shown here
Presentation transcript:

Sorting … and Insertion Sort

Sorting techniques Ideally, when we set up a new data collection, we ensure that it is (somehow) ordered: Initially (easy if it is empty or contains one item) Each addition ensures that the ordering is preserved (e.g. by inserting in the correct place) We also need a sorting technique to put jumbled data into order The data may be completely randomly ordered, or we may know that some order already exists Different sorting algorithms may perform better in different circumstances

Sorting Algorithms Problem: Given a sequence of N values, rearrange them so that they are in non-decreasing order. E.g. ascending numerical order, or alphabetical order ‘non-decreasing’ allows for repeat/duplicate values We restrict ourselves to arrays of numbers Algorithms for sorting lists: “Naïve”: Bubble sort, Selection sort Cleverer: Quick sort There are many others: Insert sort, Merge sort,... We'll look at a few of these, and understand their complexity analysis 1

Things to keep in mind… The data to be sorted may vary in type and be simple or more complex objects The sorting techniques remain the same. The result of sorting is simply the rearranged list No value is "returned", and no exception can be thrown We will assume the problem consists of: data is size integers, in elements indexed 0 to (size-1) of array numbers

Merge sort

Insertion Sort

Insertion Sort Descending order.

the fourth iteration of this loop is shown here Insertion Sort GREEN– sorted, RED unsorted. while some elements unsorted: Using linear search, find the location in the sorted portion where the 1st element of the unsorted portion should be inserted Move all the elements after the insertion location up one position to make space for the new element 45 38 60 60 66 66 45 79 47 13 74 36 21 94 22 57 16 29 81 the fourth iteration of this loop is shown here 38 45 60 66 60 45 66 79 47 13 74 36 21 94 22 57 16 29 81

Insert sort in action Start of algorithm. Sorted portion of list will be marked in colour. 15 3 91 68 2 25 31 32 16 4 21 62 1 5 6 7 8 9 10 11 12 Assign i the value 1. Set pivot to be equal to numbers[i] (next…)

Insert sort in action 3 15 91 68 2 25 31 32 16 4 21 62 i pivot 1 3 5 6 7 8 9 10 11 12 i Is the value before the gap greater than pivot? Yes! Move this value into the gap (next…)

Insert sort in action 3 15 91 68 2 25 31 32 16 4 21 62 pivot i 1 3 5 6 7 8 9 10 11 12 i Is the value before the gap greater than pivot? No. Move pivot into the gap. Add 1 to i, then select the ith value as pivot (next…)

Insert sort in action 91 3 15 68 2 25 31 32 16 4 21 62 pivot i 1 5 6 7 8 9 10 11 12 i Is the value before the gap greater than pivot? No. Move pivot into the gap. Add 1 to i, then select the ith value as pivot (next…)

Insert sort in action 68 3 15 91 2 25 31 32 16 4 21 62 pivot i 1 5 6 7 8 9 10 11 12 i Is the value before the gap greater than pivot? Yes! Move this value into the gap (next…)

Insert sort in action 68 3 15 91 2 25 31 32 16 4 21 62 pivot i 1 5 6 7 8 9 10 11 12 i Is the value before the gap greater than pivot? No. Move pivot into the gap. Add 1 to i, then select the ith value as pivot (next…)

Insert sort in action 2 3 15 68 91 25 31 32 16 4 21 62 pivot i 1 2 5 6 7 8 9 10 11 12 i Is the value before the gap greater than pivot? Yes! Move this value into the gap (next…)

Insert sort in action 2 3 15 68 91 25 31 32 16 4 21 62 pivot i 1 2 5 6 7 8 9 10 11 12 i Is the value before the gap greater than pivot? Yes! Move this value into the gap (next…)

Insert sort in action 2 3 15 68 91 25 31 32 16 4 21 62 pivot i 1 2 5 6 7 8 9 10 11 12 i Is the value before the gap greater than pivot? Yes! Move this value into the gap (next…)

Insert sort in action 2 3 15 68 91 25 31 32 16 4 21 62 pivot i 1 2 5 6 7 8 9 10 11 12 i Is the value before the gap greater than pivot? Yes! Move this value into the gap (next…)

Insert sort in action 2 3 15 68 91 25 31 32 16 4 21 62 pivot i 1 2 5 6 7 8 9 10 11 12 i Is the value before the gap greater than pivot? No. Move pivot into the gap. Add 1 to i, then select the ith value as pivot (next…)

Insert sort in action 25 2 3 15 68 91 31 32 16 4 21 62 pivot i 1 5 6 7 1 5 6 7 8 9 10 11 12 i

And so on…until the list is finally in order: pivot 2 3 4 15 16 21 25 31 32 62 68 91 1 5 6 7 8 9 10 11 12 i

An insertion sort partitions the array into two regions; variable i referred to as pivot.

Algorithm InsertionSort(A) Input: An array ‘A’ of n comparable items Output: The array ‘A’ with elements in non-decreasing order for i1 to n-1 do //Insert A[i] at is proper location in A[0]…A[i-1]. pivot  A[i] j  i-1 While j >= 0 and A[j] > pivot do A[j+1]  A[j] j  j – 1 A[j+1]  pivot

An insertion sort of an array of five integers

Insertion Sort Demo: Another perspective Sorting problem (recall): Given an array of N integers, rearrange them so that they are in increasing order. Insertion sort (general idea) Brute-force sorting solution. Move left-to-right through array. Exchange next element with larger elements to its left, one-by-one.

Insertion Sort Demo Sorting problem: Given an array of N integers, rearrange them so that they are in increasing order. Insertion sort Brute-force sorting solution. Move left-to-right through array. Exchange next element with larger elements to its left, one-by-one.

Insertion Sort Demo Sorting problem: Given an array of N integers, rearrange them so that they are in increasing order. Insertion sort Brute-force sorting solution. Move left-to-right through array. Exchange next element with larger elements to its left, one-by-one.

Insertion Sort Demo Sorting problem: Given an array of N integers, rearrange them so that they are in increasing order. Insertion sort Brute-force sorting solution. Move left-to-right through array. Exchange next element with larger elements to its left, one-by-one.

Insertion Sort Demo Sorting problem: Given an array of N integers, rearrange them so that they are in increasing order. Insertion sort Brute-force sorting solution. Move left-to-right through array. Exchange next element with larger elements to its left, one-by-one.

Insertion Sort Demo Sorting problem: Given an array of N integers, rearrange them so that they are in increasing order. Insertion sort Brute-force sorting solution. Move left-to-right through array. Exchange next element with larger elements to its left, one-by-one.

Insertion Sort Demo Sorting problem: Given an array of N integers, rearrange them so that they are in increasing order. Insertion sort Brute-force sorting solution. Move left-to-right through array. Exchange next element with larger elements to its left, one-by-one.

Insertion Sort Demo Sorting problem: Given an array of N integers, rearrange them so that they are in increasing order. Insertion sort Brute-force sorting solution. Move left-to-right through array. Exchange next element with larger elements to its left, one-by-one.

Insertion Sort Demo Sorting problem: Given an array of N integers, rearrange them so that they are in increasing order. Insertion sort Brute-force sorting solution. Move left-to-right through array. Exchange next element with larger elements to its left, one-by-one.

Insertion Sort Demo Sorting problem: Given an array of N integers, rearrange them so that they are in increasing order. Insertion sort Brute-force sorting solution. Move left-to-right through array. Exchange next element with larger elements to its left, one-by-one.

Insertion Sort Demo Sorting problem: Given an array of N integers, rearrange them so that they are in increasing order. Insertion sort Brute-force sorting solution. Move left-to-right through array. Exchange next element with larger elements to its left, one-by-one.

Insertion Sort Demo Sorting problem: Given an array of N integers, rearrange them so that they are in increasing order. Insertion sort Brute-force sorting solution. Move left-to-right through array. Exchange next element with larger elements to its left, one-by-one.

Insertion Sort Demo Sorting problem: Given an array of N integers, rearrange them so that they are in increasing order. Insertion sort Brute-force sorting solution. Move left-to-right through array. Exchange next element with larger elements to its left, one-by-one.

Insertion Sort Demo Sorting problem: Given an array of N integers, rearrange them so that they are in increasing order. Insertion sort Brute-force sorting solution. Move left-to-right through array. Exchange next element with larger elements to its left, one-by-one.

Insertion Sort Demo Sorting problem: Given an array of N integers, rearrange them so that they are in increasing order. Insertion sort Brute-force sorting solution. Move left-to-right through array. Exchange next element with larger elements to its left, one-by-one.

Insertion Sort Demo Sorting problem: Given an array of N integers, rearrange them so that they are in increasing order. Insertion sort Brute-force sorting solution. Move left-to-right through array. Exchange next element with larger elements to its left, one-by-one.

Insertion Sort Demo Sorting problem: Given an array of N integers, rearrange them so that they are in increasing order. Insertion sort Brute-force sorting solution. Move left-to-right through array. Exchange next element with larger elements to its left, one-by-one.

Insertion Sort Demo Sorting problem: Given an array of N integers, rearrange them so that they are in increasing order. Insertion sort Brute-force sorting solution. Move left-to-right through array. Exchange next element with larger elements to its left, one-by-one.

Insertion Sort Demo Sorting problem: Given an array of N integers, rearrange them so that they are in increasing order. Insertion sort Brute-force sorting solution. Move left-to-right through array. Exchange next element with larger elements to its left, one-by-one.

Insertion Sort Demo Sorting problem: Given an array of N integers, rearrange them so that they are in increasing order. Insertion sort Brute-force sorting solution. Move left-to-right through array. Exchange next element with larger elements to its left, one-by-one.

Insertion Sort Demo Sorting problem: Given an array of N integers, rearrange them so that they are in increasing order. Insertion sort Brute-force sorting solution. Move left-to-right through array. Exchange next element with larger elements to its left, one-by-one.

Insertion Sort Demo Sorting problem: Given an array of N integers, rearrange them so that they are in increasing order. Insertion sort Brute-force sorting solution. Move left-to-right through array. Exchange next element with larger elements to its left, one-by-one.

Insertion Sort Demo Sorting problem: Given an array of N integers, rearrange them so that they are in increasing order. Insertion sort Brute-force sorting solution. Move left-to-right through array. Exchange next element with larger elements to its left, one-by-one.

Insertion Sort Demo Sorting problem: Given an array of N integers, rearrange them so that they are in increasing order. Insertion sort Brute-force sorting solution. Move left-to-right through array. Exchange next element with larger elements to its left, one-by-one.

Insertion Sort Demo Sorting problem: Given an array of N integers, rearrange them so that they are in increasing order. Insertion sort Brute-force sorting solution. Move left-to-right through array. Exchange next element with larger elements to its left, one-by-one.

Insertion Sort Demo Sorting problem: Given an array of N integers, rearrange them so that they are in increasing order. Insertion sort Brute-force sorting solution. Move left-to-right through array. Exchange next element with larger elements to its left, one-by-one.

Insertion Sort Demo Sorting problem: Given an array of N integers, rearrange them so that they are in increasing order. Insertion sort Brute-force sorting solution. Move left-to-right through array. Exchange next element with larger elements to its left, one-by-one.

Insertion Sort Demo Sorting problem: Given an array of N integers, rearrange them so that they are in increasing order. Insertion sort Brute-force sorting solution. Move left-to-right through array. Exchange next element with larger elements to its left, one-by-one.

Insertion Sort Demo Sorting problem: Given an array of N integers, rearrange them so that they are in increasing order. Insertion sort Brute-force sorting solution. Move left-to-right through array. Exchange next element with larger elements to its left, one-by-one.

Insertion Sort Demo Sorting problem: Given an array of N integers, rearrange them so that they are in increasing order. Insertion sort Brute-force sorting solution. Move left-to-right through array. Exchange next element with larger elements to its left, one-by-one.

Insertion Sort Demo Sorting problem: Given an array of N integers, rearrange them so that they are in increasing order. Insertion sort Brute-force sorting solution. Move left-to-right through array. Exchange next element with larger elements to its left, one-by-one.

Insertion Sort Demo Sorting problem: Given an array of N integers, rearrange them so that they are in increasing order. Insertion sort Brute-force sorting solution. Move left-to-right through array. Exchange next element with larger elements to its left, one-by-one.

Insertion Sort Demo Sorting problem: Given an array of N integers, rearrange them so that they are in increasing order. Insertion sort Brute-force sorting solution. Move left-to-right through array. Exchange next element with larger elements to its left, one-by-one.

Insertion Sort Demo Sorting problem: Given an array of N integers, rearrange them so that they are in increasing order. Insertion sort Brute-force sorting solution. Move left-to-right through array. Exchange next element with larger elements to its left, one-by-one.

Insertion Sort Demo Sorting problem: Given an array of N integers, rearrange them so that they are in increasing order. Insertion sort Brute-force sorting solution. Move left-to-right through array. Exchange next element with larger elements to its left, one-by-one.

Insertion Sort Demo Sorting problem: Given an array of N integers, rearrange them so that they are in increasing order. Insertion sort Brute-force sorting solution. Move left-to-right through array. Exchange next element with larger elements to its left, one-by-one.

Insertion Sort Demo Sorting problem: Given an array of N integers, rearrange them so that they are in increasing order. Insertion sort Brute-force sorting solution. Move left-to-right through array. Exchange next element with larger elements to its left, one-by-one.

Insertion Sort Demo Sorting problem: Given an array of N integers, rearrange them so that they are in increasing order. Insertion sort Brute-force sorting solution. Move left-to-right through array. Exchange next element with larger elements to its left, one-by-one.

Insertion Sort Demo Sorting problem: Given an array of N integers, rearrange them so that they are in increasing order. Insertion sort Brute-force sorting solution. Move left-to-right through array. Exchange next element with larger elements to its left, one-by-one.

Insertion Sort Demo Sorting problem: Given an array of N integers, rearrange them so that they are in increasing order. Insertion sort Brute-force sorting solution. Move left-to-right through array. Exchange next element with larger elements to its left, one-by-one.

Insertion Sort Demo Sorting problem: Given an array of N integers, rearrange them so that they are in increasing order. Insertion sort Brute-force sorting solution. Move left-to-right through array. Exchange next element with larger elements to its left, one-by-one.

Insertion Sort Demo Sorting problem: Given an array of N integers, rearrange them so that they are in increasing order. Insertion sort Brute-force sorting solution. Move left-to-right through array. Exchange next element with larger elements to its left, one-by-one.

Insertion Sort Demo Sorting problem: Given an array of N integers, rearrange them so that they are in increasing order. Insertion sort Brute-force sorting solution. Move left-to-right through array. Exchange next element with larger elements to its left, one-by-one.

Insertion Sort Demo Sorting problem: Given an array of N integers, rearrange them so that they are in increasing order. Insertion sort Brute-force sorting solution. Move left-to-right through array. Exchange next element with larger elements to its left, one-by-one.

Insertion Sort Demo Sorting problem: Given an array of N integers, rearrange them so that they are in increasing order. Insertion sort Brute-force sorting solution. Move left-to-right through array. Exchange next element with larger elements to its left, one-by-one.

Insertion Sort Demo Sorting problem: Given an array of N integers, rearrange them so that they are in increasing order. Insertion sort Brute-force sorting solution. Move left-to-right through array. Exchange next element with larger elements to its left, one-by-one.

Insertion Sort: Number of Comparisons # of Sorted Elements Best case Worst case 1 2 … n-1 n(n-1)/2 Remark: we only count comparisons of elements in the array.

Count the steps InsertionSort(A) Input: An array ‘A’ of n comparable items Output: The array ‘A’ with elements in non-decreasing order for i1 to n-1 do //LOOPS OVER WHOLE ARRAY //Insert A[i] at is proper location in A[0]…A[i-1]. pivot  A[i] j  i-1 While j >= 0 and A[j] > pivot do //moves the item. A[j+1]  A[j] j  j – 1 A[j+1]  pivot outer loop outer steps inner loop inner steps outer step

Insertion Sort: Cost Function 1 operation to initialize the outer loop The outer loop is evaluated n-1 times 5 instructions (including outer loop comparison and increment) Total cost of the outer loop: 5(n-1) How many times the inner loop is evaluated is affected by the state of the array to be sorted, so may vary Best case: the array is already completely sorted, so no “shifting” of array elements is required. We only test the condition of the inner loop once (2 operations = 1 comparison + 1 element comparison), and the body is never executed Requires 2(n-1) operations, ie. O(n).

Insertion Sort: Cost Function Worst case: the array is sorted in reverse order (so each item has to be moved to the front of the array) In the i-th iteration of the outer loop, the inner loop will perform 4i+1 operations Therefore, the total cost of the inner loop will be 2n(n-1)+n-1, ie. O(n2) Time cost: Best case: 7(n-1) Worst case: 5(n-1)+2n(n-1)+n-1 What about the number of moves? Best case: 2(n-1) moves Worst case: 2(n-1)+n(n-1)/2 Aside: Where are the dominant terms, above?

Insertion Sort: Average Case Is it closer to the best case (n comparisons)? Is it closer to the worst case (n * (n-1) / 2) comparisons? It turns out that when random data is sorted, insertion sort is usually closer to the worst case Around n * (n-1) / 4 comparisons Calculating the average number of comparisons more exactly would require us to state assumptions about what the “average” input data set looked like This would, for example, necessitate discussion of how items were distributed over the array Exact calculation of the number of operations required to perform even simple algorithms can be challenging!

Now let’s compare against something else…

Selection Sort 5 1 3 4 6 2 Comparison Data Movement Sorted

Selection Sort 5 1 3 4 6 2 Comparison Data Movement Sorted

Selection Sort 5 1 3 4 6 2 Comparison Data Movement Sorted

Selection Sort 5 1 3 4 6 2 Comparison Data Movement Sorted

Selection Sort 5 1 3 4 6 2 Comparison Data Movement Sorted

Selection Sort 5 1 3 4 6 2 Comparison Data Movement Sorted

Selection Sort 5 1 3 4 6 2 Comparison Data Movement Sorted

Selection Sort 5 1 3 4 6 2  Smallest Comparison Data Movement Sorted

Selection Sort 1 5 3 4 6 2 Comparison Data Movement Sorted

Selection Sort 1 5 3 4 6 2 Comparison Data Movement Sorted

Selection Sort 1 5 3 4 6 2 Comparison Data Movement Sorted

Selection Sort 1 5 3 4 6 2 Comparison Data Movement Sorted

Selection Sort 1 5 3 4 6 2 Comparison Data Movement Sorted

Selection Sort 1 5 3 4 6 2  Smallest Comparison Data Movement Sorted

Selection Sort 1 5 3 4 6 2  Smallest Comparison Data Movement Sorted

Selection Sort 1 2 3 4 6 5 Comparison Data Movement Sorted

Selection Sort 1 2 3 4 6 5 Comparison Data Movement Sorted

Selection Sort Algorithm Input: An array ‘A’ of n comparable items Output: The array ‘A’ with elements in non-decreasing order for i0 to n-2 do // note n-2 not n-1 //Insert smallest item in 0th slot, 2nd smallest in 1st, etc. min  i for j  i+1 to j <= n-1 do if (A[j] < A[min]) min  j swap A[i] and A[min]. // What is really happening here? What is the complexity of Selection Sort, and does it vary with input?