Download presentation
Presentation is loading. Please wait.
Published byAbel Cameron Modified over 9 years ago
1
The Fundamentals: Algorithms, Integers, and Matrices CSC-2259 Discrete Structures Konstantin Busch - LSU1
2
The Growth of Functions Konstantin Busch - LSU2 Big-Oh: Big-Omega: Big-Theta: is no larger order than is no smaller order than is of same order as
3
(Notation abuse: ) Konstantin Busch - LSU3 There are constants (called witnesses) such that for all : Big-Oh:
4
Konstantin Busch - LSU4 For : Witnesses:
5
Konstantin Busch - LSU5 For : Witnesses:
6
Konstantin Busch - LSU6 and and are of the same order Example: and are of the same order
7
Konstantin Busch - LSU7 and Example:
8
Konstantin Busch - LSU8 Suppose Then for all : Impossible for
9
Konstantin Busch - LSU9 Theorem:If then Proof:for End of Proof Witnesses:
10
Konstantin Busch - LSU10 Witnesses:
11
Konstantin Busch - LSU11 Witnesses:
12
Konstantin Busch - LSU12 Witnesses:
13
Konstantin Busch - LSU13 Witnesses:
14
Konstantin Busch - LSU14 Witnesses: For :
15
Konstantin Busch - LSU15 Witnesses:
16
For : Konstantin Busch - LSU16 Witnesses: constant
17
Konstantin Busch - LSU17 Higher growth Interesting functions
18
Konstantin Busch - LSU18 Theorem:If, then Proof: Witnesses: End of Proof
19
Konstantin Busch - LSU19 Corollary:If, then Theorem:If, then
20
Konstantin Busch - LSU20 Multiplication Addition
21
(Notation abuse: ) Konstantin Busch - LSU21 There are constants (called witnesses) such that for all : Big-Omega:
22
Konstantin Busch - LSU22 Witnesses:
23
(Notation abuse: ) Konstantin Busch - LSU23 Big-Theta: Alternative definition: Same order
24
Konstantin Busch - LSU24 Witnesses:
25
Konstantin Busch - LSU25 Theorem:If then Proof:We have shown: We only need to show Take and examine two cases Case 1: Case 2:
26
Konstantin Busch - LSU26 Case 1: For and Case 2 is similar End of Proof
27
Complexity of Algorithms Konstantin Busch - LSU27 Time complexity Space complexity Number of operations performed Size of memory used
28
Konstantin Busch - LSU28 Linear search algorithm Linear-Search( ) { while( ) if ( ) return else return } //item found //item not found
29
Konstantin Busch - LSU29 Item not found in list: Comparisons Item found in position : Worst case performance: Time complexity
30
Konstantin Busch - LSU30 Binary search algorithm Binary-Search( ) { while( ) { if ( ) else } if ( ) return else return } //left endpoint of search area //item is in right half //right endpoint of search area //item is in left half //item found //item not found
31
Konstantin Busch - LSU31 1 2 3 5 6 7 8 10 12 13 15 16 18 19 20 22 Search 19 1 2 3 5 6 7 8 1012 13 15 16 18 19 20 22 12 13 15 1618 19 20 22 18 1920 22 1819
32
Konstantin Busch - LSU32 Time complexity Size of search list at iteration 1: Size of search list at iteration 2: Size of search list at iteration :
33
Konstantin Busch - LSU33 Size of search list at iteration : Smallest list size: in last iteration :
34
Konstantin Busch - LSU34 Total comparisons: #iterations Comparisons per iteration Last comparison
35
Konstantin Busch - LSU35 Bubble sort algorithm Bubble-Sort( ) { for ( to ) { for ( to ) if ( ) swap }
36
Konstantin Busch - LSU36 2341523415 2345123451 2354123541 2534125341 5234152341 First iteration 5234152341 Second iteration 5234152341 5243152431 5423154231 5432154321 Last iteration
37
Konstantin Busch - LSU37 Time complexity Comparisons in iteration 1: Comparisons in iteration 2: Comparisons in iteration : Total:
38
Class : Konstantin Busch - LSU38 Tractable problems Problems with algorithms whose time complexity is polynomial Examples: Search, Sorting, Shortest path
39
Konstantin Busch - LSU39 Intractable problems Solution can be verified in polynomial time but no polynomial time algorithm is known Important computer science question Class : Examples: Satisfiability, TSP, Vertex coloring
40
Konstantin Busch - LSU40 Unsolvable problems There exist unsolvable problems which do not have any algorithm Example: Halting problem in Turing Machines
41
Integers and Algorithms Konstantin Busch - LSU41 Base expansion of integer : Integers: Example:
42
Konstantin Busch - LSU42 Binary expansion Digits:
43
Konstantin Busch - LSU43 Hexadecimal expansion Digits:
44
Konstantin Busch - LSU44 Octal expansion Digits:
45
Konstantin Busch - LSU45 Conversion between binary and hexadecimal half byte Conversion between binary and octal
46
Konstantin Busch - LSU46 Base expansion( ) { While ( ) { } return }
47
Konstantin Busch - LSU47 Binary expansion of
48
Konstantin Busch - LSU48 Octal expansion of
49
Konstantin Busch - LSU49 Binary_addition( ) { for to { } return } //carry bit //j sum bit //auxilliary //last sum bit
50
Konstantin Busch - LSU50 Carry bit: 1 1 1 Time complexity of binary addition: (counting bit additions)
51
Konstantin Busch - LSU51 Binary_multiplication( ) { for to { if ( ) else } return binary expansion of } //a shifted j positions
52
Konstantin Busch - LSU52 Time complexity of multiplication: (counting shifts and bit additions)
53
Integers and Division Konstantin Busch - LSU53 divides : Examples: Integers factor
54
Konstantin Busch - LSU54 integers if then
55
Konstantin Busch - LSU55 integers if and then
56
Konstantin Busch - LSU56 integers if and then
57
Konstantin Busch - LSU57 integers if and then
58
Konstantin Busch - LSU58 The division “algorithm” There are unique such that: divisor quotientremainder
59
Konstantin Busch - LSU59 Examples:
60
Konstantin Busch - LSU60 Number of positive integers divisible by and not exceeding :
61
Konstantin Busch - LSU61 Division_algorithm( ) { while ( ) { } if ( and ) { } else if ( ) { } return, } //a is negative //adjust r //adjust q
62
Konstantin Busch - LSU62 Time complexity of division alg.: There is a better algorithm: (based on binary search)
63
“ is congruent to modulo ” Konstantin Busch - LSU63 Modular Arithmetic Examples:
64
Konstantin Busch - LSU64 Equivalent definitions
65
Konstantin Busch - LSU65 3 Length of line represents number
66
Konstantin Busch - LSU66 11 Length of helix line represents number
67
Konstantin Busch - LSU67 19 Length of helix line represents number
68
Konstantin Busch - LSU68 3 1119 Helix lines terminate in same number
69
Konstantin Busch - LSU69 Congruence class of modulo : There are congruence classes:
70
Konstantin Busch - LSU70
71
Konstantin Busch - LSU71
72
Konstantin Busch - LSU72
73
Konstantin Busch - LSU73 Follows from previous results by using:
74
Konstantin Busch - LSU74 Modular exponentiation Compute efficiently using small numbers Binary expansion of
75
Konstantin Busch - LSU75 Example:
76
Konstantin Busch - LSU76 Compute all the powers of 3 efficiently Use the powers of 3 to get result efficiently
77
Konstantin Busch - LSU77 Modular_Exponentiation( ) { for to { if ( ) } return } Time complexity: bit operations
78
Konstantin Busch - LSU78 Congruent application: Hashing functions Example: Employer idFolder# collision
79
Konstantin Busch - LSU79 Application: Pseudorandom numbers Linear congruential method: Sequence of pseudorandom numbers seed Example: 3,7,8,6,1,2,0,4,5,3,7,8,6,1,2,0,4,5,3… seed
80
Konstantin Busch - LSU80 Application: Cryptology “MEET YOU IN THE PARK” “PHHW BRX LQ WKH SDUN” Shift cipher: Affine transformation: encryptiondecryption
81
Primes and Greatest Common Divisor Konstantin Busch - LSU81 Prime :Positive integer greater than 1, only positive factors are Non-prime = composite Primes:2,3,5,7,11,13,17,19,23,29,31,37,41,…
82
Konstantin Busch - LSU82 Fundamental theorem of arithmetic Every positive integer is either prime or a unique product of primes Examples: prime Prime factorization:
83
Konstantin Busch - LSU83 Theorem: If is composite then it has prime divisor Proof: is composite since otherwise From fundamental theorem of arithmetic is either prime or has a prime divisor End of Proof
84
Konstantin Busch - LSU84 Prime_factorization( ) { while ( and ) { if ( divides ) { is a factor of } else next prime after } return all prime factors found } //first prime
85
Konstantin Busch - LSU85 do not divide 7007 does not divide 143
86
Konstantin Busch - LSU86 Theorem:There are infinitely many primes Proof:Suppose finite primes Let If some prime Since impossible No prime dividesis prime Contradiction! (From fundamental theorem of arithmetic) End of Proof
87
Konstantin Busch - LSU87 Largest prime known (as of 2006) Mersenne primes have the form:
88
Konstantin Busch - LSU88 Prime number theorem The number of primes less or equal to approaches to:
89
Konstantin Busch - LSU89 Goldbach’s conjecture: Every integer is the sum of two primes Twin prime conjecture: There are infinitely many twin primes Twin primes differ by 2:
90
Konstantin Busch - LSU90 Greatest common divisor largest integer such that and Examples: Common divisors of 24, 36:1, 2, 3, 4, 6, 12 Common divisors of 17, 22:1
91
Konstantin Busch - LSU91 Trivial cases:
92
Konstantin Busch - LSU92 Theorem: If then Proof: Thus, and have the same set of common divisors End of proof
93
Konstantin Busch - LSU93 first zeroresult divisions remainder
94
Konstantin Busch - LSU94 result
95
Konstantin Busch - LSU95
96
Konstantin Busch - LSU96
97
Konstantin Busch - LSU97 Property: Descending sequence: Case 1:
98
Konstantin Busch - LSU98 Property: Descending sequence: Case 2:
99
Konstantin Busch - LSU99 Property: Descending sequence:
100
Konstantin Busch - LSU100 Euclidian Algorithm gcd( ) { while ( ) { } return } Time complexity:divisions
101
and have no common factors in their prime factorization Konstantin Busch - LSU101 Relatively prime numbers If then are relatively prime Example: 21, 22 are relatively prime
102
Konstantin Busch - LSU102 Least common multiple smallest positive integer such that and Examples:
103
Applications of Number Theory Konstantin Busch - LSU103 Linear combination: if then there are such that Example:
104
Konstantin Busch - LSU104 The linear combination can be found by reversing the Euclidian algorithm steps
105
Konstantin Busch - LSU105 Linear congruences We want to solve the equation for
106
Konstantin Busch - LSU106 Inverse of :
107
Konstantin Busch - LSU107 If and are relatively prime then the inverse modulo exists Theorem: Proof: End of proof
108
Konstantin Busch - LSU108 Example: solve equation Inverse of 3:
109
Konstantin Busch - LSU109 Chinese remainder problem :pairwise relatively prime Has unique solution for modulo
110
Konstantin Busch - LSU110 Unique solution modulo : :inverse of modulo
111
Konstantin Busch - LSU111 Explanation::inverse of modulo Similar for any
112
Konstantin Busch - LSU112 Example:
113
Konstantin Busch - LSU113 An Application of Chinese remainder problem Perform arithmetic with large numbers using arithmetic modulo small numbers Example:relatively prime numbers Any number smaller than has unique representation
114
Konstantin Busch - LSU114 + We obtain this by using the Chinese remainder problem solution ++++
115
Konstantin Busch - LSU115 Fermat’s little theorem: For any prime and integer not divisible by ( ): Example:
116
Konstantin Busch - LSU116 does not divide any of: Proof: Property 1:
117
Konstantin Busch - LSU117 Explanation: Suppose divides, Does not have as prime factor has as prime factor Contradicts fundamental theorem of arithmetic
118
Konstantin Busch - LSU118 any pair below is not congruent modulo : Property 2:
119
Konstantin Busch - LSU119 Explanation: Suppose, divides Contradicts Property 1
120
Konstantin Busch - LSU120 Property 3:
121
Konstantin Busch - LSU121 Explanation: From Property 2
122
Konstantin Busch - LSU122 Property 4: (follows directly from property 3)
123
Konstantin Busch - LSU123 Property 5:
124
Konstantin Busch - LSU124 End of Proof Explanation: from Property 4: does not divide exists Multiply both sides with:
125
Konstantin Busch - LSU125 RSA cryptosystem “MEET YOU IN THE PARK” “9383772909383637467” encryptiondecryption Large primes are public keys are private keys
126
Konstantin Busch - LSU126 Message to encrypt: “STOP” Encryption example: Translate to equivalent numbers “18 19 14 15” Group into blocks of two numbers
127
Konstantin Busch - LSU127 “1819 1415” “2081 2182” Apply encryption function to each block Encrypted message:
128
Konstantin Busch - LSU 128 Message decryption :an original block of the message :respective encrypted block “1819 1415” “2081 2182” We want to find by knowing
129
Konstantin Busch - LSU129 :inverse of modulo Inverse exists because by definition of congruent
130
Konstantin Busch - LSU130
131
Konstantin Busch - LSU131 Very likely it holds (because is a large prime and is small) By Fermat’s little theorem
132
Konstantin Busch - LSU132
133
Konstantin Busch - LSU133 By symmetry, when replacing with : We showed: By the Chinese remainder problem:
134
Konstantin Busch - LSU134 We showed: In other words:
135
Konstantin Busch - LSU135 Decryption example: “2081 2182” We can compute: “1819 1415” “18 19 14 15” = “STOP”
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.