http iti wtf Algorithms and Data Structures Divide
- Slides: 66
http: //iti. wtf Algorithms and Data Structures Divide and conquer: Searching in an Array Artem A. Golubnichiy artem@golubnichij. ru Department of Software of Computer Facilities and Automated Systems Katanov Khakass State University
STRUCTURE OF THE CLASS • Main Idea of Divide-and-Conquer • Linear Search • Binary Search 2
a problem to be solved 3
Divide: Break into non-overlapping subproblems of the same type 4
Divide: Break into non-overlapping subproblems of the same type 5
Divide: Break into non-overlapping subproblems of the same type 6
Divide: Break into non-overlapping subproblems of the same type 7
Divide: Break into non-overlapping subproblems of the same type 8
9
10
11
12
Not the same type 13
14
15
16
17
Overlapping 18
Divide: Break apart 19
Divide: Break apart 20
Conquer: Solve subproblems 21
Conquer: Solve subproblems ✔� 22
Conquer: Solve subproblems ✔� ✔� 23
Conquer: Solve subproblems ✔� ✔� ✔� 24
Conquer: Solve subproblems ✔� ✔� 25
Conquer: combine ✔� ✔� 26
Conquer: combine ✔� ✔� ✔� 27
Summary 1. Break into non-overlapping subproblems of the same type 2. Solve subproblems 3. Combine results 28
Linear Search in Array Ann Pat … Joe Bob 29
Linear Search in Array Ann Pat … Joe Bob 30
Linear Search in Array Ann Pat … Joe Bob 31
Linear Search in Array Ann Pat … Joe Bob 32
Linear Search in Array Ann Pat … Joe Bob 33
Linear Search in Array Ann Pat … Joe Bob 34
Real-life Example English French Italian German Spanish house maison casa Haus casa car voiture auto Auto auto table tavola Tabelle mesa 35
Searching in an array Input: An array A with n elements. A key k. Output: An index, i, where A[i] = k. If there is no such i, then NOT_FOUND. 36
Recursive Solution Linear. Search(A, low , high, key ) if high<low: return NOT_FOUND if A[low] = key: return low 37
Recursive Solution Linear. Search(A, low , high, key ) if high<low: return NOT_FOUND if A[low] = key: return low return Linear. Search(A, low+1, high, key) 38
Definition A recurrence relation is an equation recursively defining a sequence of values. 39
Definition A recurrence relation is an equation recursively defining a sequence of values. Fibonacci recurrence relation 40
Recursive Solution Linear. Search(A, low , high, key ) if high<low: return NOT_FOUND if A[low] = key: return low return Linear. Search(A, low+1, high, key) 41
Recursive Solution Linear. Search(A, low , high, key ) if high<low: return NOT_FOUND if A[low] = key: return low return Linear. Search(A, low+1, high, key) Recurrence defining worst-case time: T (n) = T (n − 1) + c 42
Recursive Solution Linear. Search(A, low , high, key ) if high<low: return NOT_FOUND if A[low] = key: return low return Linear. Search(A, low+1, high, key) Recurrence defining worst-case time: T (n) = T (n − 1) + c T (0) = c 43
Runtime of Linear Search n n-1 n-2 ・ ・ ・ 2 1 44
Runtime of Linear Search work c n-1 c n-2 ・ ・ ・ 2 c 1 c 45
Runtime of Linear Search work c n-1 c n-2 ・ ・ ・ 2 c 1 c Total: 46
Iterative Version Linear. Search. It(A, low , high, key ) for i from low to high: if A[i] = key: return i return NOT_FOUND 47
Summary Create a recursive solution 48
Summary Create a recursive solution Define a corresponding recurrence relation, T 49
Summary Create a recursive solution Define a corresponding recurrence relation, T Determine T(n): worst-case runtime 50
Summary Create a recursive solution Define a corresponding recurrence relation, T Determine T(n): worst-case runtime Optionally, create iterative solution 51
Searching Sorted Data 52
Searching in a sorted array Input: A sorted array A[low. . . high] (∀low ≤ i < high : A[i] ≤ A[i + 1]). A key k. Output: An index, i, (low ≤ i ≤ high) where A[i] = k. Otherwise, the greatest index i, where A[i] < k. Otherwise (k < A[low]), the result is low − 1. 53
Searching in a Sorted Array Example 3 1 5 2 8 20 20 50 60 3 4 5 6 7 54
Searching in a Sorted Array Example search(2) → 0 3 1 5 2 8 20 20 50 60 3 4 5 6 7 55
Searching in a Sorted Array Example search(2) → 0 search(3) → 1 3 1 5 2 8 20 20 50 60 3 4 5 6 7 56
Searching in a Sorted Array Example search(2) → 0 search(3) → 1 search(4) → 1 3 1 5 2 8 20 20 50 60 3 4 5 6 7 57
Searching in a Sorted Array Example search(2) → 0 search(3) → 1 search(4) → 1 search(20) → 4 3 1 5 2 8 20 20 50 60 3 4 5 6 7 58
Searching in a Sorted Array Example search(2) → 0 search(3) → 1 search(4) → 1 search(20) → 4 search(20) → 5 3 1 5 2 8 20 20 50 60 3 4 5 6 7 59
Searching in a Sorted Array Example search(2) → 0 search(3) → 1 search(4) → 1 search(20) → 4 search(20) → 5 search(60) → 7 3 1 5 2 8 20 20 50 60 3 4 5 6 7 60
Searching in a Sorted Array Example search(2) → 0 search(3) → 1 search(4) → 1 search(20) search(60) search(70) 3 1 5 2 → → 4 5 7 7 8 20 20 50 60 3 4 5 6 7 61
Searching in a Sorted Array Binary. Search(A, low , high, key ) if high<low: return low − 1 62
Searching in a Sorted Array Binary. Search(A, low , high, key ) if high<low: return low − 1 mid ← [low + (high−low)/2] � 63
Searching in a Sorted Array Binary. Search(A, low , high, key ) if high<low: return low − 1 mid ← [low + (high−low)/2] � if key = A[mid]: return mid 64
Searching in a Sorted Array Binary. Search(A, low , high, key ) if high<low: return low − 1 mid ← [low + (high−low)/2] � if key = A[mid]: return mid else if key < A[mid]: return Binary. Search(A, low, mid− 1, key) 65
Searching in a Sorted Array Binary. Search(A, low , high, key ) if high<low: return low − 1 mid ← [low + (high−low)/2] � if key = A[mid]: return mid else if key < A[mid]: return Binary. Search(A, low, mid− 1, key) else: return Binary. Search(A, mid+1, high, key) 66
- Ajit diwan iit bombay
- Princeton data structures and algorithms
- Data structures and algorithms tutorial
- Information retrieval data structures and algorithms
- Data structures and algorithms bits pilani
- Ajit diwan iitb
- Data structures and algorithms
- Data structures and algorithms
- Waterloo data structures and algorithms
- Signature file structure in information retrieval system
- Data structures and algorithms
- Algorithms + data structures = programs
- Wtf per minute
- Unicode plane
- Awkward family photos wtf
- Löschwasserentnahmestelle offenes gewässer
- Human arm and whale flipper function
- Muthukrishnan data stream algorithms
- El e domnul domnilor versuri
- Xatkes
- Kor bucaq iti bucaq
- O doamne mare
- Iti livorno
- Majorana grugliasco
- Cand ai intrat in ghetsimani
- Fgenera
- Awan ti danum in tagalog
- Pacinotti scafati
- Iti multumim sfant dumnezeu
- Iti 1100
- Iti 1100
- Iti mattei rosignano
- Prasasti tuk mas yang berisi atribut dewa
- Iti marconi pontedera
- Randunica plural
- Iti 1100
- Daca iti vei opri piciorul ziua sabatului
- Iti p hensemberger
- Pacinotti scafati
- Iti faenza
- Andrea zoccheddu
- Iti majorana grugliasco
- Iti 1120
- Iti majorana grugliasco
- Iti 1121
- Http //mbs.meb.gov.tr/ http //www.alantercihleri.com
- Siat ung sistem informasi akademik
- Data structures used in macro processor
- Assembler data structures
- Data structures and abstractions with java
- Adts, data structures, and problem solving with c++
- Data structures and algorithm
- Persistent and ephemeral data structures
- Divide data sets in fourths
- Divide and conquer advantages and disadvantages
- Greedy vs divide and conquer
- Computational thinking algorithms and programming
- Design and analysis of algorithms syllabus
- Association analysis: basic concepts and algorithms
- Computer arithmetic: algorithms and hardware designs
- Algorithms for select and join operations
- Algorithms and flowcharts
- Undecidable problems and unreasonable time algorithms.
- Cluster analysis basic concepts and algorithms
- Probabilistic analysis and randomized algorithms
- Design and analysis of algorithms introduction
- Algorithms for query processing and optimization