7 Winning Career Strategies They'll Never Teach You in Business School
Teacher Talk 2011. 1.There has never been a better time to teach Computer Science 2.We can learn...
-
Upload
emily-todd -
Category
Documents
-
view
213 -
download
0
Transcript of Teacher Talk 2011. 1.There has never been a better time to teach Computer Science 2.We can learn...
Teacher Talk2011
1. There has never been a better time to teach Computer Science
2. We can learn from Chemistry, Physics, Biology, …
What am I going to show you?
First, I will use sorting to demonstrate “This is the best time to teach CS”
Second, I will use binary trees (and AVL trees) to show we can do what Chemists do
Sorting, what’s that then?
Given a collection of data, get it into order …
Sorting, what’s that then?
Given a collection of data, get it into order …
9 2 6 0 4 3 2 7 5
This is NOT in order
Sorting, what’s that then?
Given a collection of data, get it into order …
0 2 3 4 5 6 7 9
This is IS in order
Sorting, what’s that then?
Given a collection of data, get it into order …
0 2 3 4 5 6 7 9
This is IS in order
It’s in ascending order
Sorting, what’s that then?
Sorting is the process of going from this
0 2 3 4 5 6 7 9
9 2 6 0 4 3 2 7 5
to that
Sorting, why bother?
9 2 6 0 4 3 2 7 5
Who cares?
You can find things quicker!
Sorting, why bother?
0 2 3 4 5 6 7 9
9 2 6 0 4 3 2 7 5
Who cares?
You can find things quicker!
Use “binary search” (or even linear search and stop early)
Sorting, why bother?Who cares?
Do you remember the telephone directory? Imagine if it was just in any order (random)How long would it take you to find my telephone number?
Sorting, why bother?Who cares?
Do you remember the telephone directory? Imagine if it was just in any order (random)How long would it take you to find my telephone number?
Do you remember the dictionary?Imagine if that was just in any order.How long would it take to find a word, or to determine if the word was not present?
Sorting, why bother?Who cares?
Do you remember the telephone directory? Imagine if it was just in any order (random)How long would it take you to find my telephone number?
Do you remember the dictionary?Imagine if that was just in any order.How long would it take to find a word, or to determine if the word was not present?
Do you ever use an online spelling checker?How does that work?
Sorting, why bother?Who cares?
Sorting, why bother?Who cares?
What do you prefer?
Some algorithms for sorting
• bubble sort• insertion sort• selection sort• shell sort• gnome sort• merge sort• quick sort• heap sort• radix sort• bead sort
sorting
Some algorithms for sorting
• bubble sort• insertion sort• selection sort• shell sort• gnome sort• merge sort• quick sort• heap sort• radix sort• bead sort
sorting
What’s an algorithm?
Some algorithms for sorting
• bubble sort• insertion sort• selection sort• shell sort• gnome sort• merge sort• quick sort• heap sort• radix sort• bead sort
sorting
quadratic
Some algorithms for sorting
• bubble sort• insertion sort• selection sort• shell sort• gnome sort• merge sort• quick sort• heap sort• radix sort• bead sort
sorting
logarithmic
Some algorithms for sorting
• bubble sort• insertion sort• selection sort• shell sort• gnome sort• merge sort• quick sort• heap sort• radix sort• bead sort
sorting
linear
Some algorithms for sorting
• bubble sort• insertion sort• selection sort• shell sort• gnome sort• merge sort• quick sort• heap sort• radix sort• bead sort
sorting
Our example
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
9 2 06 4 3 2 57
Example
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
9 2 06 4 3 2 57
Example
compare
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
2 9 06 4 3 2 57
Example
swap
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
2 9 06 4 3 2 57
Example
compare
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
2 6 09 4 3 2 57
Example
swap
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
2 6 09 4 3 2 57
Example
compare
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
2 6 90 4 3 2 57
Example
swap
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
2 6 90 4 3 2 57
Example
compare
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
2 6 40 9 3 2 57
Example
swap
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
2 6 40 9 3 2 57
Example
compare
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
2 6 40 3 9 2 57
Example
swap
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
2 6 40 3 9 2 57
Example
compare
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
2 6 40 3 2 9 57
Example
swap
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
2 6 40 3 2 9 57
Example
compare
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
2 6 40 3 2 7 59
Example
swap
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
2 6 40 3 2 7 59
Example
compare
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
2 6 40 3 2 7 95
Example
swap
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
2 6 40 3 2 7 95
Example
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
2 6 40 3 2 7 95
Example
compare
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
2 6 40 3 2 7 95
Example
compare
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
2 0 46 3 2 7 95
Example
swap
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
2 0 46 3 2 7 95
Example
compare
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
2 0 64 3 2 7 95
Example
swap
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
2 0 64 3 2 7 95
Example
compare
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
2 0 34 6 2 7 95
Example
swap
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
2 0 34 6 2 7 95
Example
compare
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
2 0 34 2 6 7 95
Example
swap
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
2 0 34 2 6 7 95
Example
compare
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
2 0 34 2 6 7 95
Example
compare
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
2 0 34 2 6 5 97
Example
swap
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
2 0 34 2 6 5 97
Example
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
2 0 34 2 6 5 97
Example
Are you tired yet? Bored?
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
2 0 34 2 6 5 97
Example
compare
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
0 2 34 2 6 5 97
Example
swap
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
0 2 34 2 6 5 97
Example
compare
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
0 2 34 2 6 5 97
Example
compare
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
0 2 43 2 6 5 97
Example
swap
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
0 2 43 2 6 5 97
Example
compare
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
0 2 23 4 6 5 97
Example
swap
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
0 2 23 4 6 5 97
Example
compare
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
0 2 23 4 6 5 97
Example
compare
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
0 2 23 4 5 6 97
Example
swap
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
0 2 23 4 5 6 97
Example
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
0 2 23 4 5 6 97
Example
compare
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
0 2 23 4 5 6 97
Example
compare
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
0 2 23 4 5 6 97
Example
compare
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
0 2 32 4 5 6 97
Example
swap
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
0 2 32 4 5 6 97
Example
compare
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
0 2 32 4 5 6 97
Example
compare
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
0 2 32 4 5 6 97
Example
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
0 2 32 4 5 6 97
Example
compare
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
0 2 32 4 5 6 97
Example
compare
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
0 2 32 4 5 6 97
Example
compare
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
0 2 32 4 5 6 97
Example
compare
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
0 2 32 4 5 6 97
Example
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
0 2 32 4 5 6 97
Example
Phew!
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
On an Array
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
9 2 06 4 3 2 57
Example
i=8
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
9 2 06 4 3 2 57
Example
compare
i=8j=0
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
2 9 06 4 3 2 57
Example
swap
Example
i=8j=0
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
2 9 06 4 3 2 57
Example
compare
ExampleExample
i=8j=1
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
2 6 09 4 3 2 57
Example
swap
ExampleExampleExample
i=8j=1
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
2 6 09 4 3 2 57
Example
compare
ExampleExampleExampleExample
i=8j=2
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
2 6 90 4 3 2 57
Example
swap
ExampleExampleExampleExampleExample
i=8j=2
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
2 6 90 4 3 2 57
Example
compare
ExampleExampleExampleExampleExampleExample
i=8j=3
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
2 6 40 9 3 2 57
Example
swap
ExampleExampleExampleExampleExampleExampleExample
i=8j=3
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
2 6 40 9 3 2 57
Example
compare
ExampleExampleExampleExampleExampleExampleExampleExample
i=8j=4
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
2 6 40 3 9 2 57
Example
swap
ExampleExampleExampleExampleExampleExampleExampleExampleExample
i=8j=4
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
2 6 40 3 9 2 57
Example
compare
ExampleExampleExampleExampleExampleExampleExampleExampleExampleExample
i=8j=5
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
2 6 40 3 2 9 57
Example
swap
ExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExample
i=8j=5
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
2 6 40 3 2 9 57
Example
compare
ExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExample
i=8j=6
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
2 6 40 3 2 7 59
Example
swap
ExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExample
i=8j=6
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
2 6 40 3 2 7 59
Example
compare
ExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExample
i=8j=7
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
2 6 40 3 2 7 95
Example
swap
ExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExample
i=8j=7
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
2 6 40 3 2 7 95
Example sortingExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExample
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
2 6 40 3 2 7 95
Example
compare
sortingExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExample
i=7j=0
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
2 6 40 3 2 7 95
Example
compare
ExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExample
i=7j=1
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
2 0 46 3 2 7 95
Example
swap
ExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExample
i=7j=1
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
2 0 46 3 2 7 95
Example
compare
ExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExample
i=7j=2
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
2 0 64 3 2 7 95
Example
swap
sortingExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExample
i=7j=2
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
2 0 64 3 2 7 95
Example
compare
sortingExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExample
i=7j=3
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
2 0 34 6 2 7 95
Example
swap
sortingExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExample
i=7j=3
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
2 0 34 6 2 7 95
Example
compare
sortingExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExample
i=7j=4
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
2 0 34 2 6 7 95
Example
swap
sortingExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExample
i=7j=4
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
2 0 34 2 6 7 95
Example
compare
sortingExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExample
i=7j=5
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
2 0 34 2 6 7 95
Example
compare
sortingExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExample
i=7j=6
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
2 0 34 2 6 5 97
Example
swap
sortingExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExample
i=7j=6
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
2 0 34 2 6 5 97
ExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExample
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
2 0 34 2 6 5 97
Example
compare
sortingExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExample
i=6j=0
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
0 2 34 2 6 5 97
Example
swap
ExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExample
i=6j=0
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
0 2 34 2 6 5 97
Example
compare
ExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExample
i=6j=1
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
0 2 34 2 6 5 97
Example
compare
ExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExample
i=6j=2
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
0 2 43 2 6 5 97
Example
swap
ExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExample
i=6j=2
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
0 2 43 2 6 5 97
Example
compare
ExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExample
i=6j=3
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
0 2 23 4 6 5 97
Example
swap
ExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExample
i=6j=3
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
0 2 23 4 6 5 97
Example
compare
ExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExample
i=6j=4
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
0 2 23 4 6 5 97
Example
compare
ExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExample
i=6j=5
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
0 2 23 4 5 6 97
Example
swap
ExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExample
i=6j=5
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
0 2 23 4 5 6 97
ExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExample
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
0 2 23 4 5 6 97
Example
compare
ExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExample
i=5j=0
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
0 2 23 4 5 6 97
Example
compare
ExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExample
i=5j=1
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
0 2 23 4 5 6 97
Example
compare
ExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExample
i=5j=2
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
0 2 32 4 5 6 97
Example
swap
ExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExample
i=5j=2
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
0 2 32 4 5 6 97
Example
compare
ExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExample
i=5j=3
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
0 2 32 4 5 6 97
Example
compare
ExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExample
i=5j=4
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
0 2 32 4 5 6 97
ExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExample
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
0 2 32 4 5 6 97
Example
compare
ExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExample
i=4j=0
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
0 2 32 4 5 6 97
Example
compare
ExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExample
i=4j=1
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
0 2 32 4 5 6 97
Example
compare
ExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExample
i=4j=2
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
0 2 32 4 5 6 97
Example
compare
ExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExample
i=4j=3
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
0 2 32 4 5 6 97
ExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExample
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
0 2 32 4 5 6 97
ExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExampleExample
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
0 2 32 4 5 6 97
Example
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
0 2 32 4 5 6 97
Example
Phew!
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
On an Array
Can we visualize this?
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
On an Array
Can we visualize this?
Assume we have a random list of numbers from 0 to n-1, put in an array ASuch that A[0] is the 1st number and A[n-1] is the last
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
On an Array
Can we visualize this?
Assume we have a random list of numbers from 0 to n-1, put in an array ASuch that A[0] is the 1st number and A[n-1] is the last
9 2 06 4 3 2 57
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
On an Array
Can we visualize this?
Assume we have a random list of numbers from 0 to n-1, put in an array ASuch that A[0] is the 1st number and A[n-1] is the last
9 2 06 4 3 2 57
A[0] A[1] A[2] A[3] A[4] A[5] A[6] A[7] A[8]
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
On an Array
Can we visualize this?
Assume we have a random list of numbers from 0 to n-1, put in an array ASuch that A[0] is the 1st number and A[n-1] is the last
9 2 06 4 3 2 57
A[0] A[1] A[2] A[3] A[4] A[5] A[6] A[7] A[8]
We could plot A[i] on a graph as a point with x/y coordinates i/A[i]
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
On an Array
Can we visualize this?
Assume we have a random list of numbers from 0 to n-1, put in an array ASuch that A[0] is the 1st number and A[n-1] is the last
9 2 06 4 3 2 57
A[0] A[1] A[2] A[3] A[4] A[5] A[6] A[7] A[8]
We could plot A[i] on a graph as a point with x/y coordinates i/A[i]
Do this as the algorithm progress to see how it progresses.
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
On an Array
Can we visualize this?
Assume we have a random list of numbers from 0 to n-1, put in an array ASuch that A[0] is the 1st number and A[n-1] is the last
9 2 06 4 3 2 57
A[0] A[1] A[2] A[3] A[4] A[5] A[6] A[7] A[8]
We could plot A[i] on a graph as a point with x/y coordinates i/A[i]
Do this as the algorithm progress to see how it progresses.
Ready?
Quadratic algorithms
• bubble sort• insertion sort• selection sort
sorting
Bubble Sort
On an Array
sorting
Bubble Sort
Show me more!
sorting
Bubble Sort
Show me more!
• different sorting algorithms and relative performance• a beauty contest
• what is the “sound” of sorting?• can you show me it by mime? Expressive dance?
sorting
Bubble Sort
NOTE to self:Bubble sort is a quadratic time algorithm.If I have to sort a data set of N objects the run time will be proportional to N2
sorting
Bubble Sort
NOTE to self:Bubble sort is a quadratic time algorithm.If I have to sort a data set of N objects the run time will be proportional to N2
To sort 10 numbers will take 100 units of time
sorting
Bubble Sort
NOTE to self:Bubble sort is a quadratic time algorithm.If I have to sort a data set of N objects the run time will be proportional to N2
To sort 10 numbers will take 100 units of timeTo sort 100 numbers will take 10,000 units of time
sorting
Bubble Sort
NOTE to self:Bubble sort is a quadratic time algorithm.If I have to sort a data set of N objects the run time will be proportional to N2
To sort 10 numbers will take 100 units of timeTo sort 100 numbers will take 10,000 units of timeTo sort 1000 numbers will take 1,000,000 units of time
Links
• sorting algorithm animation• sound of sorting (part 1)• sound of sorting (part 2)• bubble sort by folk dancing
Barak on Sorting
I think there has never been a better time to teach Computer Science
end of part 1
Live dangerously … live like a teacher, like a Physics teacher,or Chemistry, or Biology, or …
Balanced binary trees … without powerpoint
Binary search trees and AVL trees
Live dangerously