This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
precisely defined mechanical steps terminates input and related output
What might we want to know about it?
Why?
COVID
Algorithms
Algorithms Today
Definition
Why?
The Word
The Founder
This Class
Complexity
Wheeler Ruml (UNH) Class 1, CS 758 – 6 / 25
Computer scientist 6= programmer
understand program behavior have confidence in results, performance know when optimality is abandoned solve ‘impossible’ problems sets you apart (eg, Amazon.com)
CPUs aren’t getting faster Devices are getting smaller Software is the differentiator ‘Software is eating the world’ — Marc Andreessen, 2011 Everything is computation
The Word: Abu ‘Abdallah Muh.ammad ibn Musa al-Khwarizmı
COVID
Algorithms
Algorithms Today
Definition
Why?
The Word
The Founder
This Class
Complexity
Wheeler Ruml (UNH) Class 1, CS 758 – 7 / 25
780-850 ADBorn in Uzbekistan,
worked in Baghdad.Solution of linear and
quadratic equations.Founder of algebra.Popularized arabic numerals,
requires 531/659 (formal thinking), 515 (data structures, C) some intentional overlap! central (required for BS CS and BS DS) same content, assignments, grading both semesters continuous improvement!
Topics
COVID
Algorithms
This Class
Relations
Topics
Course Mechanics
Complexity
Wheeler Ruml (UNH) Class 1, CS 758 – 11 / 25
‘Greatest Hits’
1. data structures: trees, tries, hashing2. algorithms: divide-and-conquer, dynamic programming,
greedy, graphs3. correctness: invariants4. complexity: time and space5. NP-completeness: reductions
2. count[i] ← 03. for each input number x4. increment count[x]5. for i from 0 to k
6. do count[i] times7. emit i
Counting Sort
COVID
Algorithms
This Class
Complexity
Sorting
Counting Sort
Correctness
Counting Sort
Complexity
Counting Sort
Order Notation
O()
Examples
And Friends
Asymptotics
EOLQs
Wheeler Ruml (UNH) Class 1, CS 758 – 15 / 25
For n numbers in the range 0 to k:
1. for i from 0 to k
2. count[i] ← 03. for each input number x4. increment count[x]5. for i from 0 to k
6. do count[i] times7. emit i
Correctness?
Complexity?
Correctness
COVID
Algorithms
This Class
Complexity
Sorting
Counting Sort
Correctness
Counting Sort
Complexity
Counting Sort
Order Notation
O()
Examples
And Friends
Asymptotics
EOLQs
Wheeler Ruml (UNH) Class 1, CS 758 – 16 / 25
property 1: output is in sorted orderproof sketch: output loop increments i, never decrements
Correctness
COVID
Algorithms
This Class
Complexity
Sorting
Counting Sort
Correctness
Counting Sort
Complexity
Counting Sort
Order Notation
O()
Examples
And Friends
Asymptotics
EOLQs
Wheeler Ruml (UNH) Class 1, CS 758 – 16 / 25
property 1: output is in sorted orderproof sketch: output loop increments i, never decrements
property 2: output contains same numbers as inputinvariant:
Correctness
COVID
Algorithms
This Class
Complexity
Sorting
Counting Sort
Correctness
Counting Sort
Complexity
Counting Sort
Order Notation
O()
Examples
And Friends
Asymptotics
EOLQs
Wheeler Ruml (UNH) Class 1, CS 758 – 16 / 25
property 1: output is in sorted orderproof sketch: output loop increments i, never decrements
property 2: output contains same numbers as inputinvariant: for each value,
remaining input + sum of counts = totalproof sketch:
Correctness
COVID
Algorithms
This Class
Complexity
Sorting
Counting Sort
Correctness
Counting Sort
Complexity
Counting Sort
Order Notation
O()
Examples
And Friends
Asymptotics
EOLQs
Wheeler Ruml (UNH) Class 1, CS 758 – 16 / 25
property 1: output is in sorted orderproof sketch: output loop increments i, never decrements
property 2: output contains same numbers as inputinvariant: for each value,
remaining input + sum of counts = totalproof sketch:initialized/established: before line 3maintained: through lines 3–4at termination: no remaining input
each number printed count timestherefore, output has same numbers as input
Counting Sort
COVID
Algorithms
This Class
Complexity
Sorting
Counting Sort
Correctness
Counting Sort
Complexity
Counting Sort
Order Notation
O()
Examples
And Friends
Asymptotics
EOLQs
Wheeler Ruml (UNH) Class 1, CS 758 – 17 / 25
For n numbers in the range 0 to k:
1. for i from 0 to k
2. count[i] ← 03. for each input number x4. increment count[x]5. for i from 0 to k
6. do count[i] times7. emit i
Correctness? Yes.
Complexity?
Complexity
COVID
Algorithms
This Class
Complexity
Sorting
Counting Sort
Correctness
Counting Sort
Complexity
Counting Sort
Order Notation
O()
Examples
And Friends
Asymptotics
EOLQs
Wheeler Ruml (UNH) Class 1, CS 758 – 18 / 25
RAM model: no cacheorder of growthworst-case
[ try with previous slide ]
Counting Sort
COVID
Algorithms
This Class
Complexity
Sorting
Counting Sort
Correctness
Counting Sort
Complexity
Counting Sort
Order Notation
O()
Examples
And Friends
Asymptotics
EOLQs
Wheeler Ruml (UNH) Class 1, CS 758 – 19 / 25
For n numbers in the range 0 to k:
1. for i from 0 to k O(k)2. count[i] ← 03. for each input number x O(n)4. increment count[x]5. for i from 0 to k O(k + n)6. do count[i] times7. emit i