1.45k likes | 1.74k Views
The Fundamentals: Algorithms, Integers, and Matrices. CSC-2259 Discrete Structures. The Growth of Functions. Big-Oh:. is no larger order than. Big-Omega:. is no smaller order than. Big-Theta:. is of same order as. Big-Oh:. (Notation abuse: ).
E N D
The Fundamentals: Algorithms, Integers, and Matrices CSC-2259 Discrete Structures Konstantin Busch - LSU
The Growth of Functions Big-Oh: is no larger order than Big-Omega: is no smaller order than Big-Theta: is of same order as Konstantin Busch - LSU
Big-Oh: (Notation abuse: ) There are constants (called witnesses) such that for all : Konstantin Busch - LSU
For : Witnesses: Konstantin Busch - LSU
For : Witnesses: Konstantin Busch - LSU
and and are of the same order Example: and are of the same order Konstantin Busch - LSU
and Example: Konstantin Busch - LSU
Suppose Then for all : Impossible for Konstantin Busch - LSU
Theorem: If then Proof: for Witnesses: End of Proof Konstantin Busch - LSU
Witnesses: Konstantin Busch - LSU
Witnesses: Konstantin Busch - LSU
Witnesses: Konstantin Busch - LSU
Witnesses: Konstantin Busch - LSU
For : Witnesses: Konstantin Busch - LSU
Witnesses: Konstantin Busch - LSU
constant For : Witnesses: Konstantin Busch - LSU
Interesting functions Higher growth Konstantin Busch - LSU
Theorem: If , then Proof: Witnesses: End of Proof Konstantin Busch - LSU
Corollary: If , then Theorem: If , then Konstantin Busch - LSU
Multiplication Addition Konstantin Busch - LSU
Big-Omega: (Notation abuse: ) There are constants (called witnesses) such that for all : Konstantin Busch - LSU
Witnesses: Konstantin Busch - LSU
Same order Big-Theta: (Notation abuse: ) Alternative definition: Konstantin Busch - LSU
Witnesses: Witnesses: Konstantin Busch - LSU
Theorem: If then Proof: We have shown: We only need to show Take and examine two cases Case 1: Case 2: Konstantin Busch - LSU
Case 1: For and Case 2 is similar End of Proof Konstantin Busch - LSU
Complexity of Algorithms Time complexity Number of operations performed Space complexity Size of memory used Konstantin Busch - LSU
Linear search algorithm Linear-Search( ) { while( ) if ( ) return else return } //item found //item not found Konstantin Busch - LSU
Time complexity Comparisons Item not found in list: Item found in position : Worst case performance: Konstantin Busch - LSU
Binary search algorithm Binary-Search( ) { while( ) { if ( ) else } if ( ) return else return } //left endpoint of search area //right endpoint of search area //item is in right half //item is in left half //item found //item not found Konstantin Busch - LSU
Search 19 1 2 3 5 6 7 8 10 12 13 15 16 18 19 20 22 1 2 3 5 6 7 8 10 12 13 15 16 18 19 20 22 12 13 15 16 18 19 20 22 18 19 20 22 18 19 Konstantin Busch - LSU
Time complexity Size of search list at iteration 1: Size of search list at iteration 2: Size of search list at iteration : Konstantin Busch - LSU
Size of search list at iteration : Smallest list size: in last iteration : Konstantin Busch - LSU
Total comparisons: Last comparison #iterations Comparisons per iteration Konstantin Busch - LSU
Bubble sort algorithm Bubble-Sort( ) { for ( to ) { for ( to ) if ( ) swap } Konstantin Busch - LSU
First iteration 2 3 4 1 5 2 3 4 5 1 2 3 5 4 1 2 5 3 4 1 5 2 3 4 1 Second iteration Last iteration 5 2 3 4 1 5 2 3 4 1 5 2 4 3 1 5 4 2 3 1 5 4 3 2 1 Konstantin Busch - LSU
Time complexity Comparisons in iteration 1: Comparisons in iteration 2: Comparisons in iteration : Total: Konstantin Busch - LSU
Tractable problems Class : Problems with algorithms whose time complexity is polynomial Examples: Search, Sorting, Shortest path Konstantin Busch - LSU
Intractable problems Class : Solution can be verified in polynomial time but no polynomial time algorithm is known Examples: Satisfiability, TSP, Vertex coloring Important computer science question Konstantin Busch - LSU
Unsolvable problems There exist unsolvable problems which do not have any algorithm Example: Halting problem in Turing Machines Konstantin Busch - LSU
Integers and Algorithms Base expansion of integer : Integers: Example: Konstantin Busch - LSU
Binary expansion Digits: Konstantin Busch - LSU
Hexadecimal expansion Digits: Konstantin Busch - LSU
Octal expansion Digits: Konstantin Busch - LSU
Conversion between binary and hexadecimal half byte Conversion between binary and octal Konstantin Busch - LSU
Base expansion( ) { While ( ) { } return } Konstantin Busch - LSU
Binary expansion of Konstantin Busch - LSU
Octal expansion of Konstantin Busch - LSU
Binary_addition( ) { for to { } return } //carry bit //auxilliary //j sum bit //carry bit //last sum bit Konstantin Busch - LSU
Carry bit: 1 1 1 Time complexity of binary addition: (counting bit additions) Konstantin Busch - LSU