MERGESORT BBM ALGORITHMS DEPT. OF COMPUTER ENGINEERING ERKUT ERDEM. Mergesort. Feb. 27, 2014
|
|
- Patrick Gray
- 5 years ago
- Views:
Transcription
1 ergesort BB ALGOITHS Basc plan. Dvde array nto two halves. ecursvely sort each half. erge two halves. DPT. OF COPUT NGINING KUT D GSOT nput G S O T X A P L sort left half G O S T X A P L sort rght half G O S A L P T X merge results A G L O P S T X ergesort overvew Feb. 27, 2014 Acnowledgement: The course sldes are adapted from the sldes prepared by. Sedgewc and K. Wayne of Prnceton Unversty. 2 Abstract n-place merge Abstract n-place merge lo G sorted md md+1 A h C lo T G md md+1 A h C T sorted copy to auxlary array 3 4
2 Abstract n-place merge Abstract n-place merge compare mnmum n each subarray G A C T 5 6 Abstract n-place merge Abstract n-place merge A A G A C T compare mnmum n each subarray compare mnmum n each subarray 7 8
3 Abstract n-place merge Abstract n-place merge A C G A C T A C G A C T compare mnmum n each subarray compare mnmum n each subarray 9 10 Abstract n-place merge Abstract n-place merge A C G A C T A C A C T compare mnmum n each subarray compare mnmum n each subarray 11 12
4 Abstract n-place merge Abstract n-place merge A C A C T A C A C T compare mnmum n each subarray compare mnmum n each subarray G A C T Abstract n-place merge Abstract n-place merge A C A C T A C A C T compare mnmum n each subarray compare mnmum n each subarray 15 16
5 Abstract n-place merge Abstract n-place merge A C AG C T A C G C T compare mnmum n each subarray compare mnmum n each subarray Abstract n-place merge Abstract n-place merge A C G C T A C G T compare mnmum n each subarray compare mnmum n each subarray 19 20
6 Abstract n-place merge Abstract n-place merge A C G T A C G T compare mnmum n each subarray one subarray exhausted, tae from other Abstract n-place merge Abstract n-place merge A C G T A C G T one subarray exhausted, tae from other one subarray exhausted, tae from other 23 24
7 Abstract n-place merge Abstract n-place merge A C G T A C G T one subarray exhausted, tae from other both subarrays exhausted, done Abstract n-place merge ergng Q. How to combne two sorted subarrays nto a sorted whole. A. Use an auxlary array. lo h A C G T sorted nput copy merged result A A C 0 7 G C T 2 A C 1 7 G T 3 A C 2 7 G T 4 A C 2 8 G T 5 A C G 3 8 G T 6 A C G 4 8 T 7 A C G 5 8 T 8 A C G 5 9 T 9 A C G T 6 10 T A C G T Abstract n-place merge trace 27 28
8 ergng: Java mplementaton ergesort: Java mplementaton prvate statc vod merge(comparable[] a, Comparable[] aux, nt lo, nt md, nt h) assert ssorted(a, lo, md); // precondton: a[lo..md] sorted assert ssorted(a, md+1, h); // precondton: a[md+1..h] sorted for (nt = lo; <= h; ++) copy aux[] = a[]; nt = lo, = md+1; for (nt = lo; <= h; ++) f ( > md) a[] = aux[++]; else f ( > h) a[] = aux[++]; else f (less(aux[], aux[])) a[] = aux[++]; else a[] = aux[++]; assert ssorted(a, lo, h); lo // postcondton: a[lo..h] sorted md A G L O H I S T h merge publc class erge prvate statc vod merge(comparable[] a, Comparable[] aux, nt lo, nt md, nt h) /* as before */ prvate statc vod sort(comparable[] a, Comparable[] aux, nt lo, nt h) f (h <= lo) return; nt md = lo + (h - lo) / 2; sort (a, aux, lo, md); sort (a, aux, md+1, h); merge(a, aux, lo, md, h); publc statc vod sort(comparable[] a) aux = new Comparable[a.length]; sort(a, aux, 0, a.length - 1); A G H I L 29 lo md h ergesort: trace ergesort: anmaton 50 random tems lo h merge(a, 0, 0, 1) merge(a, 2, 2, 3) merge(a, 0, 1, 3) merge(a, 4, 4, 5) merge(a, 6, 6, 7) merge(a, 4, 5, 7) merge(a, 0, 3, 7) merge(a, 8, 8, 9) merge(a, 10, 10, 11) merge(a, 8, 9, 11) merge(a, 12, 12, 13) merge(a, 14, 14, 15) merge(a, 12, 13, 15) merge(a, 8, 11, 15) merge(a, 0, 7, 15) G S O T X A P L G S O T X A P L G S O T X A P L G S O T X A P L G S O T X A P L G S O T X A P L G O S T X A P L G O S T X A P L G O S T X A P L G O S T A X P L G O S A T X P L G O S A T X P L G O S A T X P L G O S A T X L P G O S A L P T X A G L O P S T X Trace of merge results for top-down mergesort result after recursve call algorthm poston n order current subarray not n order 31 32
9 ergesort: anmaton ergesort: emprcal analyss 50 reverse-sorted tems algorthm poston n order current subarray not n order unnng tme estmates: Laptop executes 10 8 compares/second. Supercomputer executes compares/second. nserton sort (N mergesort (N log N) computer thousand mllon bllon thousand mllon bllon home nstant 2.8 hours 317 years nstant 1 second 18 mn super nstant 1 second 1 wee nstant nstant nstant Bottom lne. Good algorthms are better than supercomputers ergesort: number of compares and array accesses Proposton. ergesort uses at most N lg N compares and 6 N lg N array accesses to sort any array of sze N. Pf setch. The number of compares C (N) and array accesses A (N) to mergesort an array of sze N satsfy the recurrences: Dvde-and-conquer recurrence: proof by pcture Proposton. If D (N) satsfes D (N) = 2 D (N / 2) + N for N > 1, wth D (1) = 0, then D (N) = N lg N. Pf 1. [assumng N s a power of 2] D (N) N = N C (N) C ( N / 2 ) + C ( N / 2 ) + N for N > 1, wth C (1) = 0. D (N / 2) D (N / 2) 2 (N/2) = N left half rght half merge A (N) A ( N / 2 ) + A ( N / 2 ) + 6 N for N > 1, wth A (1) = 0. We solve the recurrence when N s a power of 2. lg N D (N / 4) D (N / 4) D (N / 4) D (N / 2 ) D (N / 4) 4 (N/4) = N... 2 (N/2 ) = N... D (N) = 2 D (N / 2) + N, for N > 1, wth D (1) = 0. D (2) D (2) D (2) D (2) D (2) D (2) D (2) D (2) N/2 (2) = N N lg N 35 36
10 Dvde-and-conquer recurrence: proof by expanson Proposton. If D (N) satsfes D (N) = 2 D (N / 2) + N for N > 1, wth D (1) = 0, then D (N) = N lg N. Pf 2. [assumng N s a power of 2] gven D (N) = 2 D (N/2) + N D (N) / N = 2 D (N/2) / N + 1 dvde both sdes by N = D (N/2) / (N/2) + 1 algebra = D (N/4) / (N/4) apply to frst term = D (N/8) / (N/8) Dvde-and-conquer recurrence: proof by nducton Proposton. If D (N) satsfes D (N) = 2 D (N / 2) + N for N > 1, wth D (1) = 0, then D (N) = N lg N. Pf 3. [assumng N s a power of 2] Base case: N = 1. Inductve hypothess: D (N) = N lg N. Goal: show that D (2N) = (2N) lg (2N). D (2N) = 2 D (N) + 2N = 2 N lg N + 2N gven nductve hypothess... = D (N/N) / (N/N) apply to frst term agan = 2 N (lg (2N) 1) + 2N = 2 N lg (2N) algebra = lg N stop applyng, D(1) = 0 QD ergesort analyss: memory Proposton. ergesort uses extra space proportonal to N. Pf. The array needs to be of sze N for the last merge. A C D G H I N U V two sorted subarrays A B C D F G H I J N O P Q S T U V merged result Def. A sortng algorthm s n-place f t uses c log N extra memory. x. Inserton sort, selecton sort, shellsort. B F J O P Q S T Challenge for the bored. In-place merge. [Kronrod, 1969] ergesort: practcal mprovements Use nserton sort for small subarrays. ergesort has too much overhead for tny subarrays. Cutoff to nserton sort for 7 tems. prvate statc vod sort(comparable[] a, Comparable[] aux, nt lo, nt h) f (h <= lo + CUTOFF - 1) Inserton.sort(a, lo, h); nt md = lo + (h - lo) / 2; sort (a, aux, lo, md); sort (a, aux, md+1, h); merge(a, aux, lo, md, h); 39 40
11 ergesort: practcal mprovements Stop f already sorted. Is bggest tem n frst half smallest tem n second half? Helps for partally-ordered arrays. A B C D F G H I J N O P Q S T U V A B C D F G H I J N O P Q S T U V prvate statc vod sort(comparable[] a, Comparable[] aux, nt lo, nt h) f (h <= lo) return; nt md = lo + (h - lo) / 2; sort (a, aux, lo, md); sort (a, aux, md+1, h); f (less(a[md+1], a[md])) return; merge(a, aux, lo, md, h); ergesort: practcal mprovements lmnate the copy to the auxlary array. Save tme (but not space) by swtchng the role of the nput and auxlary array n each recursve call. prvate statc vod merge(comparable[] a, Comparable[] aux, nt lo, nt md, nt h) nt = lo, = md+1; for (nt = lo; <= h; ++) f ( > md) aux[] = a[++]; else f ( > h) aux[] = a[++]; merge from to else f (less(a[], a[])) aux[] = a[++]; else aux[] = a[++]; prvate statc vod sort(comparable[] a, Comparable[] aux, nt lo, nt h) f (h <= lo) return; nt md = lo + (h - lo) / 2; sort (aux, a, lo, md); sort (aux, a, md+1, h); merge(aux, a, lo, md, h); 41 swtch roles of and 42 ergesort: vsualzaton Bottom-up mergesort frst subarray second subarray frst merge frst half sorted second half sorted result 43 Basc plan. Pass through array, mergng subarrays of sze 1. epeat for subarrays of sze 2, 4, 8, 16,... sz = 1 merge(a, 0, 0, 1) merge(a, 2, 2, 3) merge(a, 4, 4, 5) merge(a, 6, 6, 7) merge(a, 8, 8, 9) merge(a, 10, 10, 11) merge(a, 12, 12, 13) merge(a, 14, 14, 15) sz = 2 merge(a, 0, 1, 3) merge(a, 4, 5, 7) merge(a, 8, 9, 11) merge(a, 12, 13, 15) sz = 4 merge(a, 0, 3, 7) merge(a, 8, 11, 15) sz = 8 merge(a, 0, 7, 15) Trace of merge results for bottom-up mergesort Bottom lne. No recurson needed a[] G S O T X A P L G S O T X A P L G S O T X A P L G S O T X A P L G S O T X A P L G S O T X A P L G S O T A X P L G S O T A X P L G S O T A X P L G S O T A X P L G O S T A X P L G O S A T X P L G O S A T X L P G O S A T X L P G O S A L P T X A G L O P S T X 44
12 Bottom-up mergesort: Java mplementaton Bottom-up mergesort: vsual trace publc class ergebu prvate statc Comparable[] aux; prvate statc vod merge(comparable[] a, nt lo, nt md, nt h) /* as before */ publc statc vod sort(comparable[] a) nt N = a.length; aux = new Comparable[N]; for (nt sz = 1; sz < N; sz = sz+sz) for (nt lo = 0; lo < N-sz; lo += sz+sz) merge(a, lo, lo+sz-1, ath.mn(lo+sz+sz-1, N-1)); Bottom lne. Concse ndustral-strength code, f you have the space
MERGESORT BBM ALGORITHMS DEPT. OF COMPUTER ENGINEERING. Mergesort
BBM 202 - ALGORITHMS DEPT. OF COMPUTER ENGINEERING Mergesort Basc plan. Dvde array nto two halves. Recursvely sort each half. Merge two halves. MERGESORT nput sort left half sort rght half merge results
More informationAlgorithms. Algorithms. Algorithms 2.2 M ERGESORT. mergesort bottom-up mergesort. sorting complexity divide-and-conquer
Algorthms Two classc sortng algorthms: mergesort and qucsort R OBERT S EDGEWICK K EVIN W AYNE Crtcal components n the world s computatonal nfrastructure. Full scentfc understandng of ther propertes has
More informationAlgorithms. Algorithms 2.2 MERGESORT. mergesort bottom-up mergesort sorting complexity divide-and-conquer ROBERT SEDGEWICK KEVIN WAYNE
Algorithms ROBERT SEDGEWICK KEVIN WAYNE 2.2 MERGESORT Algorithms F O U R T H E D I T I O N mergesort bottom-up mergesort sorting complexity divide-and-conquer ROBERT SEDGEWICK KEVIN WAYNE http://algs4.cs.princeton.edu
More informationELEMENTARY SORTING ALGORITHMS
BBM 202 - ALGORITHMS DEPT. OF COMPUTER ENGINEERING ELEMENTARY SORTING ALGORITHMS Feb. 20, 2017 Acknowledgement: The course sldes are adapted from the sldes prepared by R. Sedgewck and K. Wayne of Prnceton
More informationSORTING ALGORITHMS BBM ALGORITHMS DEPT. OF COMPUTER ENGINEERING ERKUT ERDEM. Mar. 21, 2013
BBM 202 - ALGORITHMS DPT. OF COMPUTR NGINRING RKUT RDM SORTING ALGORITHMS Mar. 21, 2013 Acknowledgement: The course slides are adapted from the slides prepared by R. Sedgewick and K. Wayne of Princeton
More informationOutline. 1 Merging. 2 Merge Sort. 3 Complexity of Sorting. 4 Merge Sort and Other Sorts 2 / 10
Merge Sort 1 / 10 Outline 1 Merging 2 Merge Sort 3 Complexity of Sorting 4 Merge Sort and Other Sorts 2 / 10 Merging Merge sort is based on a simple operation known as merging: combining two ordered arrays
More informationSorting Algorithms. !rules of the game!shellsort!mergesort!quicksort!animations. Classic sorting algorithms
Classic sorting algorithms Sorting Algorithms!rules of the game!shellsort!mergesort!quicksort!animations Reference: Algorithms in Java, Chapters 6-8 1 Critical components in the world s computational infrastructure.
More informationInf 2B: Sorting, MergeSort and Divide-and-Conquer
Inf 2B: Sorting, MergeSort and Divide-and-Conquer Lecture 7 of ADS thread Kyriakos Kalorkoti School of Informatics University of Edinburgh The Sorting Problem Input: Task: Array A of items with comparable
More informationMath Review. CptS 223 Advanced Data Structures. Larry Holder School of Electrical Engineering and Computer Science Washington State University
Math Revew CptS 223 dvanced Data Structures Larry Holder School of Electrcal Engneerng and Computer Scence Washngton State Unversty 1 Why do we need math n a data structures course? nalyzng data structures
More informationAdvanced Algebraic Algorithms on Integers and Polynomials
Advanced Algebrac Algorthms on Integers and Polynomals Analyss of Algorthms Prepared by John Ref, Ph.D. Integer and Polynomal Computatons a) Newton Iteraton: applcaton to dvson b) Evaluaton and Interpolaton
More informationLecture 14: Nov. 11 & 13
CIS 2168 Data Structures Fall 2014 Lecturer: Anwar Mamat Lecture 14: Nov. 11 & 13 Disclaimer: These notes may be distributed outside this class only with the permission of the Instructor. 14.1 Sorting
More informationCS 770G - Parallel Algorithms in Scientific Computing
References CS 770G - Parallel Algorthms n Scentfc Computng Parallel Sortng Introducton to Parallel Computng Kumar, Grama, Gupta, Karyps, Benjamn Cummngs. A porton of the notes comes from Prof. J. Demmel
More informationLecture 4: November 17, Part 1 Single Buffer Management
Lecturer: Ad Rosén Algorthms for the anagement of Networs Fall 2003-2004 Lecture 4: November 7, 2003 Scrbe: Guy Grebla Part Sngle Buffer anagement In the prevous lecture we taled about the Combned Input
More informationExercises. 18 Algorithms
18 Algorthms Exercses 0.1. In each of the followng stuatons, ndcate whether f = O(g), or f = Ω(g), or both (n whch case f = Θ(g)). f(n) g(n) (a) n 100 n 200 (b) n 1/2 n 2/3 (c) 100n + log n n + (log n)
More informationOutline and Reading. Dynamic Programming. Dynamic Programming revealed. Computing Fibonacci. The General Dynamic Programming Technique
Outlne and Readng Dynamc Programmng The General Technque ( 5.3.2) -1 Knapsac Problem ( 5.3.3) Matrx Chan-Product ( 5.3.1) Dynamc Programmng verson 1.4 1 Dynamc Programmng verson 1.4 2 Dynamc Programmng
More informationDynamic Programming! CSE 417: Algorithms and Computational Complexity!
Dynamc Programmng CSE 417: Algorthms and Computatonal Complexty Wnter 2009 W. L. Ruzzo Dynamc Programmng, I:" Fbonacc & Stamps Outlne: General Prncples Easy Examples Fbonacc, Lckng Stamps Meater examples
More informationPartition and Select
Divide-Conquer-Glue Algorithms Quicksort, Quickselect and the Master Theorem Quickselect algorithm Tyler Moore CSE 3353, SMU, Dallas, TX Lecture 11 Selection Problem: find the kth smallest number of an
More informationLearning Theory: Lecture Notes
Learnng Theory: Lecture Notes Lecturer: Kamalka Chaudhur Scrbe: Qush Wang October 27, 2012 1 The Agnostc PAC Model Recall that one of the constrants of the PAC model s that the data dstrbuton has to be
More informationCS 350 Algorithms and Complexity
CS 350 Algorthms and Complexty Wnter 2015 Lecture 8: Decrease & Conquer (contnued) Andrew P. Black Department of Computer Scence Portland State Unversty Example: DFS traversal of undrected graph a b c
More informationMergesort and Recurrences (CLRS 2.3, 4.4)
Mergesort and Recurrences (CLRS 2.3, 4.4) We saw a couple of O(n 2 ) algorithms for sorting. Today we ll see a different approach that runs in O(n lg n) and uses one of the most powerful techniques for
More informationSingle Variable Optimization
8/4/07 Course Instructor Dr. Raymond C. Rump Oce: A 337 Phone: (95) 747 6958 E Mal: rcrump@utep.edu Topc 8b Sngle Varable Optmzaton EE 4386/530 Computatonal Methods n EE Outlne Mathematcal Prelmnares Sngle
More informationDivide-Conquer-Glue. Divide-Conquer-Glue Algorithm Strategy. Skyline Problem as an Example of Divide-Conquer-Glue
Divide-Conquer-Glue Tyler Moore CSE 3353, SMU, Dallas, TX February 19, 2013 Portions of these slides have been adapted from the slides written by Prof. Steven Skiena at SUNY Stony Brook, author of Algorithm
More informationOutline. 1 Introduction. Merging and MergeSort. 3 Analysis. 4 Reference
Outline Computer Science 331 Sort Mike Jacobson Department of Computer Science University of Calgary Lecture #25 1 Introduction 2 Merging and 3 4 Reference Mike Jacobson (University of Calgary) Computer
More informationHomework 9 Solutions. 1. (Exercises from the book, 6 th edition, 6.6, 1-3.) Determine the number of distinct orderings of the letters given:
Homework 9 Solutons PROBLEM ONE 1 (Exercses from the book, th edton,, 1-) Determne the number of dstnct orderngs of the letters gven: (a) GUIDE Soluton: 5! (b) SCHOOL Soluton:! (c) SALESPERSONS Soluton:
More informationThe Selection Problem - Variable Size Decrease/Conquer (Practice with algorithm analysis)
We have covered: Selecto, Iserto, Mergesort, Bubblesort, Heapsort Next: Selecto the Qucksort The Selecto Problem - Varable Sze Decrease/Coquer (Practce wth algorthm aalyss) Cosder the problem of fdg the
More informationDivide-and-Conquer. Consequence. Brute force: n 2. Divide-and-conquer: n log n. Divide et impera. Veni, vidi, vici.
Divide-and-Conquer Divide-and-conquer. Break up problem into several parts. Solve each part recursively. Combine solutions to sub-problems into overall solution. Most common usage. Break up problem of
More informationChapter 5. Divide and Conquer CLRS 4.3. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.
Chapter 5 Divide and Conquer CLRS 4.3 Slides by Kevin Wayne. Copyright 25 Pearson-Addison Wesley. All rights reserved. Divide-and-Conquer Divide-and-conquer. Break up problem into several parts. Solve
More informationV. Adamchik 1. Recurrences. Victor Adamchik Fall of 2005
V. Adamchi Recurrences Victor Adamchi Fall of 00 Plan Multiple roots. More on multiple roots. Inhomogeneous equations 3. Divide-and-conquer recurrences In the previous lecture we have showed that if the
More informationThe maximum-subarray problem. Given an array of integers, find a contiguous subarray with the maximum sum. Very naïve algorithm:
The maximum-subarray problem Given an array of integers, find a contiguous subarray with the maximum sum. Very naïve algorithm: Brute force algorithm: At best, θ(n 2 ) time complexity 129 Can we do divide
More informationFor now, let us focus on a specific model of neurons. These are simplified from reality but can achieve remarkable results.
Neural Networks : Dervaton compled by Alvn Wan from Professor Jtendra Malk s lecture Ths type of computaton s called deep learnng and s the most popular method for many problems, such as computer vson
More informationENTROPIC QUESTIONING
ENTROPIC QUESTIONING NACHUM. Introucton Goal. Pck the queston that contrbutes most to fnng a sutable prouct. Iea. Use an nformaton-theoretc measure. Bascs. Entropy (a non-negatve real number) measures
More informationCHAPTER 17 Amortized Analysis
CHAPTER 7 Amortzed Analyss In an amortzed analyss, the tme requred to perform a sequence of data structure operatons s averaged over all the operatons performed. It can be used to show that the average
More informationWeek 5: Quicksort, Lower bound, Greedy
Week 5: Quicksort, Lower bound, Greedy Agenda: Quicksort: Average case Lower bound for sorting Greedy method 1 Week 5: Quicksort Recall Quicksort: The ideas: Pick one key Compare to others: partition into
More informationCPS 616 DIVIDE-AND-CONQUER 6-1
CPS 616 DIVIDE-AND-CONQUER 6-1 DIVIDE-AND-CONQUER Approach 1. Divide instance of problem into two or more smaller instances 2. Solve smaller instances recursively 3. Obtain solution to original (larger)
More informationA design paradigm. Divide and conquer: (When) does decomposing a problem into smaller parts help? 09/09/ EECS 3101
A design paradigm Divide and conquer: (When) does decomposing a problem into smaller parts help? 09/09/17 112 Multiplying complex numbers (from Jeff Edmonds slides) INPUT: Two pairs of integers, (a,b),
More informationDivide&Conquer: MergeSort. Algorithmic Thinking Luay Nakhleh Department of Computer Science Rice University Spring 2014
Divide&Conquer: MergeSort Algorithmic Thinking Luay Nakhleh Department of Computer Science Rice University Spring 2014 1 Divide-and-Conquer Algorithms Divide-and-conquer algorithms work according to the
More informationprinceton univ. F 13 cos 521: Advanced Algorithm Design Lecture 3: Large deviations bounds and applications Lecturer: Sanjeev Arora
prnceton unv. F 13 cos 521: Advanced Algorthm Desgn Lecture 3: Large devatons bounds and applcatons Lecturer: Sanjeev Arora Scrbe: Today s topc s devaton bounds: what s the probablty that a random varable
More informationdata structures and algorithms lecture 2
data structures and algorithms 2018 09 06 lecture 2 recall: insertion sort Algorithm insertionsort(a, n): for j := 2 to n do key := A[j] i := j 1 while i 1 and A[i] > key do A[i + 1] := A[i] i := i 1 A[i
More informationChapter 5. Divide and Conquer. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.
Chapter 5 Divide and Conquer Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. 1 Divide-and-Conquer Divide-and-conquer. Break up problem into several parts. Solve each
More informationChapter 5. Divide and Conquer CLRS 4.3. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.
Chapter 5 Divide and Conquer CLRS 4.3 Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. 1 Divide-and-Conquer Divide-and-conquer. Break up problem into several parts. Solve
More informationDivide and Conquer. Recurrence Relations
Divide and Conquer Recurrence Relations Divide-and-Conquer Strategy: Break up problem into parts. Solve each part recursively. Combine solutions to sub-problems into overall solution. 2 MergeSort Mergesort.
More informationDesign and Analysis of Algorithms
Desgn and Analyss of Algorthms CSE 53 Lecture 4 Dynamc Programmng Junzhou Huang, Ph.D. Department of Computer Scence and Engneerng CSE53 Desgn and Analyss of Algorthms The General Dynamc Programmng Technque
More informationElementary Sorts 1 / 18
Elementary Sorts 1 / 18 Outline 1 Rules of the Game 2 Selection Sort 3 Insertion Sort 4 Shell Sort 5 Visualizing Sorting Algorithms 6 Comparing Sorting Algorithms 2 / 18 Rules of the Game Sorting is the
More informationCommon loop optimizations. Example to improve locality. Why Dependence Analysis. Data Dependence in Loops. Goal is to find best schedule:
15-745 Lecture 6 Data Dependence n Loops Copyrght Seth Goldsten, 2008 Based on sldes from Allen&Kennedy Lecture 6 15-745 2005-8 1 Common loop optmzatons Hostng of loop-nvarant computatons pre-compute before
More informationAlgorithms Test 1. Question 1. (10 points) for (i = 1; i <= n; i++) { j = 1; while (j < n) {
Question 1. (10 points) for (i = 1; i
More informationVapnik-Chervonenkis theory
Vapnk-Chervonenks theory Rs Kondor June 13, 2008 For the purposes of ths lecture, we restrct ourselves to the bnary supervsed batch learnng settng. We assume that we have an nput space X, and an unknown
More informationAlgorithms. Algorithms 2.3 QUICKSORT. quicksort selection duplicate keys system sorts ROBERT SEDGEWICK KEVIN WAYNE.
Algorithms ROBERT SEDGEWICK KEVIN WAYNE 2.3 QUICKSORT Algorithms F O U R T H E D I T I O N quicksort selection duplicate keys system sorts ROBERT SEDGEWICK KEVIN WAYNE http://algs4.cs.princeton.edu Two
More informationAlgorithm Design and Analysis
Algorithm Design and Analysis LECTURE 9 Divide and Conquer Merge sort Counting Inversions Binary Search Exponentiation Solving Recurrences Recursion Tree Method Master Theorem Sofya Raskhodnikova S. Raskhodnikova;
More informationStanford University CS359G: Graph Partitioning and Expanders Handout 4 Luca Trevisan January 13, 2011
Stanford Unversty CS359G: Graph Parttonng and Expanders Handout 4 Luca Trevsan January 3, 0 Lecture 4 In whch we prove the dffcult drecton of Cheeger s nequalty. As n the past lectures, consder an undrected
More informationNON LINEAR ANALYSIS OF STRUCTURES ACCORDING TO NEW EUROPEAN DESIGN CODE
October 1-17, 008, Bejng, Chna NON LINEAR ANALYSIS OF SRUCURES ACCORDING O NEW EUROPEAN DESIGN CODE D. Mestrovc 1, D. Czmar and M. Pende 3 1 Professor, Dept. of Structural Engneerng, Faculty of Cvl Engneerng,
More information5. DIVIDE AND CONQUER I
5. DIVIDE AND CONQUER I mergesort counting inversions closest pair of points median and selection Lecture slides by Kevin Wayne Copyright 2005 Pearson-Addison Wesley http://www.cs.princeton.edu/~wayne/kleinberg-tardos
More informationDATA STRUCTURES FOR LOGIC OPTIMIZATION
DATA STRUCTURES FOR LOGIC OPTIMIZATION Outlne Revew of Boolean algera. c Govann De Mchel Stanford Unversty Representatons of logc functons. Matrx representatons of covers. Operatons on logc covers. Background
More informationLecture 22: Multithreaded Algorithms CSCI Algorithms I. Andrew Rosenberg
Lecture 22: Multithreaded Algorithms CSCI 700 - Algorithms I Andrew Rosenberg Last Time Open Addressing Hashing Today Multithreading Two Styles of Threading Shared Memory Every thread can access the same
More informationCSci 6974 and ECSE 6966 Math. Tech. for Vision, Graphics and Robotics Lecture 21, April 17, 2006 Estimating A Plane Homography
CSc 6974 and ECSE 6966 Math. Tech. for Vson, Graphcs and Robotcs Lecture 21, Aprl 17, 2006 Estmatng A Plane Homography Overvew We contnue wth a dscusson of the major ssues, usng estmaton of plane projectve
More informationFinding Primitive Roots Pseudo-Deterministically
Electronc Colloquum on Computatonal Complexty, Report No 207 (205) Fndng Prmtve Roots Pseudo-Determnstcally Ofer Grossman December 22, 205 Abstract Pseudo-determnstc algorthms are randomzed search algorthms
More informationAlgorithms And Programming I. Lecture 5 Quicksort
Algorithms And Programming I Lecture 5 Quicksort Quick Sort Partition set into two using randomly chosen pivot 88 31 25 52 14 98 62 30 23 79 14 31 2530 23 52 88 62 98 79 Quick Sort 14 31 2530 23 52 88
More informationFor combinatorial problems we might need to generate all permutations, combinations, or subsets of a set.
Addtoal Decrease ad Coquer Algorthms For combatoral problems we mght eed to geerate all permutatos, combatos, or subsets of a set. Geeratg Permutatos If we have a set f elemets: { a 1, a 2, a 3, a } the
More information= 1.23 m/s 2 [W] Required: t. Solution:!t = = 17 m/s [W]! m/s [W] (two extra digits carried) = 2.1 m/s [W]
Secton 1.3: Acceleraton Tutoral 1 Practce, page 24 1. Gven: 0 m/s; 15.0 m/s [S]; t 12.5 s Requred: Analyss: a av v t v f v t a v av f v t 15.0 m/s [S] 0 m/s 12.5 s 15.0 m/s [S] 12.5 s 1.20 m/s 2 [S] Statement:
More informationA generalization of a trace inequality for positive definite matrices
A generalzaton of a trace nequalty for postve defnte matrces Elena Veronca Belmega, Marc Jungers, Samson Lasaulce To cte ths verson: Elena Veronca Belmega, Marc Jungers, Samson Lasaulce. A generalzaton
More informationEffective Power Optimization combining Placement, Sizing, and Multi-Vt techniques
Effectve Power Optmzaton combnng Placement, Szng, and Mult-Vt technques Tao Luo, Davd Newmark*, and Davd Z Pan Department of Electrcal and Computer Engneerng, Unversty of Texas at Austn *Advanced Mcro
More informationLecture 4. Quicksort
Lecture 4. Quicksort T. H. Cormen, C. E. Leiserson and R. L. Rivest Introduction to Algorithms, 3rd Edition, MIT Press, 2009 Sungkyunkwan University Hyunseung Choo choo@skku.edu Copyright 2000-2018 Networking
More informationIntroduction to Divide and Conquer
Introduction to Divide and Conquer Sorting with O(n log n) comparisons and integer multiplication faster than O(n 2 ) Periklis A. Papakonstantinou York University Consider a problem that admits a straightforward
More information2.3 Nilpotent endomorphisms
s a block dagonal matrx, wth A Mat dm U (C) In fact, we can assume that B = B 1 B k, wth B an ordered bass of U, and that A = [f U ] B, where f U : U U s the restrcton of f to U 40 23 Nlpotent endomorphsms
More informationA CLASS OF RECURSIVE SETS. Florentin Smarandache University of New Mexico 200 College Road Gallup, NM 87301, USA
A CLASS OF RECURSIVE SETS Florentn Smarandache Unversty of New Mexco 200 College Road Gallup, NM 87301, USA E-mal: smarand@unmedu In ths artcle one bulds a class of recursve sets, one establshes propertes
More informationOn some variants of Jensen s inequality
On some varants of Jensen s nequalty S S DRAGOMIR School of Communcatons & Informatcs, Vctora Unversty, Vc 800, Australa EMMA HUNT Department of Mathematcs, Unversty of Adelade, SA 5005, Adelade, Australa
More informationErrors for Linear Systems
Errors for Lnear Systems When we solve a lnear system Ax b we often do not know A and b exactly, but have only approxmatons  and ˆb avalable. Then the best thng we can do s to solve ˆx ˆb exactly whch
More informationEnsemble Methods: Boosting
Ensemble Methods: Boostng Ncholas Ruozz Unversty of Texas at Dallas Based on the sldes of Vbhav Gogate and Rob Schapre Last Tme Varance reducton va baggng Generate new tranng data sets by samplng wth replacement
More informationAlgorithms. Algorithms 2.3 QUICKSORT. quicksort selection duplicate keys system sorts ROBERT SEDGEWICK KEVIN WAYNE.
Announcements Last normal lecture for 3 weeks. Sign up for Coursera if you have not already. Next week s video lectures will be available tomorrow at 2 PM. Exercises also posted (so you can test comprehension).
More informationDivide and Conquer. Arash Rafiey. 27 October, 2016
27 October, 2016 Divide the problem into a number of subproblems Divide the problem into a number of subproblems Conquer the subproblems by solving them recursively or if they are small, there must be
More informationCalculation of time complexity (3%)
Problem 1. (30%) Calculaton of tme complexty (3%) Gven n ctes, usng exhaust search to see every result takes O(n!). Calculaton of tme needed to solve the problem (2%) 40 ctes:40! dfferent tours 40 add
More informationSUBSTRING SEARCH BBM ALGORITHMS TODAY DEPT. OF COMPUTER ENGINEERING ERKUT ERDEM. Apr. 29, Substring search applications.
M 22 - LGORITHMS TODY Substrng search DPT. OF OMPUTR NGINRING RKUT RDM rute force Knuth-Morrs-Pratt oyer-moore Rabn-Karp SUSTRING SRH pr. 29, 214 cknowledgement: The course sldes are adapted from the sldes
More informationAppendix B: Resampling Algorithms
407 Appendx B: Resamplng Algorthms A common problem of all partcle flters s the degeneracy of weghts, whch conssts of the unbounded ncrease of the varance of the mportance weghts ω [ ] of the partcles
More informationLecture 2: Prelude to the big shrink
Lecture 2: Prelude to the bg shrnk Last tme A slght detour wth vsualzaton tools (hey, t was the frst day... why not start out wth somethng pretty to look at?) Then, we consdered a smple 120a-style regresson
More informationRELIABILITY ASSESSMENT
CHAPTER Rsk Analyss n Engneerng and Economcs RELIABILITY ASSESSMENT A. J. Clark School of Engneerng Department of Cvl and Envronmental Engneerng 4a CHAPMAN HALL/CRC Rsk Analyss for Engneerng Department
More informationJOURNAL OF OBJECT TECHNOLOGY
JOURNAL OF OBJECT TECHNOLOGY Publshed by ETH Zurch, Char of Software Engneerng JOT, 2010 Vol. 9, No. 2, March - Aprl 2010 The Dscrete Fourer Transform, Part 6: Cross-Correlaton By Douglas Lyon Abstract
More informationCS 331 DESIGN AND ANALYSIS OF ALGORITHMS DYNAMIC PROGRAMMING. Dr. Daisy Tang
CS DESIGN ND NLYSIS OF LGORITHMS DYNMIC PROGRMMING Dr. Dasy Tang Dynamc Programmng Idea: Problems can be dvded nto stages Soluton s a sequence o decsons and the decson at the current stage s based on the
More informationFoundations of Arithmetic
Foundatons of Arthmetc Notaton We shall denote the sum and product of numbers n the usual notaton as a 2 + a 2 + a 3 + + a = a, a 1 a 2 a 3 a = a The notaton a b means a dvdes b,.e. ac = b where c s an
More informationDynamic Programming. Preview. Dynamic Programming. Dynamic Programming. Dynamic Programming (Example: Fibonacci Sequence)
/24/27 Prevew Fbonacc Sequence Longest Common Subsequence Dynamc programmng s a method for solvng complex problems by breakng them down nto smpler sub-problems. It s applcable to problems exhbtng the propertes
More informationLecture 21: Numerical methods for pricing American type derivatives
Lecture 21: Numercal methods for prcng Amercan type dervatves Xaoguang Wang STAT 598W Aprl 10th, 2014 (STAT 598W) Lecture 21 1 / 26 Outlne 1 Fnte Dfference Method Explct Method Penalty Method (STAT 598W)
More informationSUBSTRING SEARCH BBM ALGORITHMS TODAY DEPT. OF COMPUTER ENGINEERING ERKUT ERDEM. Apr. 28, Substring search applications.
M 22 - LGORITHMS TODY DEPT. OF OMPUTER ENGINEERING ERKUT ERDEM Substrng search rute force Knuth-Morrs-Pratt oyer-moore Rabn-Karp SUSTRING SERH pr. 28, 215 cknowledgement:.the$course$sldes$are$adapted$from$the$sldes$prepared$by$r.$sedgewck$
More informationFeature Selection & Dynamic Tracking F&P Textbook New: Ch 11, Old: Ch 17 Guido Gerig CS 6320, Spring 2013
Feature Selecton & Dynamc Trackng F&P Textbook New: Ch 11, Old: Ch 17 Gudo Gerg CS 6320, Sprng 2013 Credts: Materal Greg Welch & Gary Bshop, UNC Chapel Hll, some sldes modfed from J.M. Frahm/ M. Pollefeys,
More informationStructure and Drive Paul A. Jensen Copyright July 20, 2003
Structure and Drve Paul A. Jensen Copyrght July 20, 2003 A system s made up of several operatons wth flow passng between them. The structure of the system descrbes the flow paths from nputs to outputs.
More informationE Tail Inequalities. E.1 Markov s Inequality. Non-Lecture E: Tail Inequalities
Algorthms Non-Lecture E: Tal Inequaltes If you hold a cat by the tal you learn thngs you cannot learn any other way. Mar Twan E Tal Inequaltes The smple recursve structure of sp lsts made t relatvely easy
More information5. DIVIDE AND CONQUER I
5. DIVIDE AND CONQUER I mergesort counting inversions closest pair of points randomized quicksort median and selection Lecture slides by Kevin Wayne Copyright 2005 Pearson-Addison Wesley http://www.cs.princeton.edu/~wayne/kleinberg-tardos
More informationDivide and Conquer Algorithms
Divide and Conquer Algorithms Divide-and-Conquer The most-well known algorithm design strategy: 1. Divide instance of problem into two or more smaller instances 2. Solve smaller instances recursively 3.
More informationReview Of Topics. Review: Induction
Review Of Topics Asymptotic notation Solving recurrences Sorting algorithms Insertion sort Merge sort Heap sort Quick sort Counting sort Radix sort Medians/order statistics Randomized algorithm Worst-case
More informationChapter 3 Describing Data Using Numerical Measures
Chapter 3 Student Lecture Notes 3-1 Chapter 3 Descrbng Data Usng Numercal Measures Fall 2006 Fundamentals of Busness Statstcs 1 Chapter Goals To establsh the usefulness of summary measures of data. The
More informationSuppose that there s a measured wndow of data fff k () ; :::; ff k g of a sze w, measured dscretely wth varable dscretzaton step. It s convenent to pl
RECURSIVE SPLINE INTERPOLATION METHOD FOR REAL TIME ENGINE CONTROL APPLICATIONS A. Stotsky Volvo Car Corporaton Engne Desgn and Development Dept. 97542, HA1N, SE- 405 31 Gothenburg Sweden. Emal: astotsky@volvocars.com
More information04 - Treaps. Dr. Alexander Souza
Algorths Theory 04 - Treaps Dr. Alexander Souza The dctonary proble Gven: Unverse (U,
More informationCompiling for Parallelism & Locality. Example. Announcement Need to make up November 14th lecture. Last time Data dependences and loops
Complng for Parallelsm & Localty Announcement Need to make up November 14th lecture Last tme Data dependences and loops Today Fnsh data dependence analyss for loops CS553 Lecture Complng for Parallelsm
More informationSupplement: Proofs and Technical Details for The Solution Path of the Generalized Lasso
Supplement: Proofs and Techncal Detals for The Soluton Path of the Generalzed Lasso Ryan J. Tbshran Jonathan Taylor In ths document we gve supplementary detals to the paper The Soluton Path of the Generalzed
More informationThe Problem: Mapping programs to architectures
Complng for Parallelsm & Localty!Last tme! SSA and ts uses!today! Parallelsm and localty! Data dependences and loops CS553 Lecture Complng for Parallelsm & Localty 1 The Problem: Mappng programs to archtectures
More informationCOMP 382: Reasoning about algorithms
Fall 2014 Unit 4: Basics of complexity analysis Correctness and efficiency So far, we have talked about correctness and termination of algorithms What about efficiency? Running time of an algorithm For
More informationEconomics 101. Lecture 4 - Equilibrium and Efficiency
Economcs 0 Lecture 4 - Equlbrum and Effcency Intro As dscussed n the prevous lecture, we wll now move from an envronment where we looed at consumers mang decsons n solaton to analyzng economes full of
More informationModeling and Simulation NETW 707
Modelng and Smulaton NETW 707 Lecture 5 Tests for Random Numbers Course Instructor: Dr.-Ing. Magge Mashaly magge.ezzat@guc.edu.eg C3.220 1 Propertes of Random Numbers Random Number Generators (RNGs) must
More informationSurvey says... Announcements. Survey says... Survey says...
Announcements Survey says... Last normal lecture for 3 weeks. Sign up for Coursera if you have not already. Next week s video lectures will be available tomorrow at 2 PM. Exercises also posted (so you
More informationCopyright 2000, Kevin Wayne 1
Divide-and-Conquer Chapter 5 Divide and Conquer Divide-and-conquer. Break up problem into several parts. Solve each part recursively. Combine solutions to sub-problems into overall solution. Most common
More informationPARTICIPATION FACTOR IN MODAL ANALYSIS OF POWER SYSTEMS STABILITY
POZNAN UNIVE RSITY OF TE CHNOLOGY ACADE MIC JOURNALS No 86 Electrcal Engneerng 6 Volodymyr KONOVAL* Roman PRYTULA** PARTICIPATION FACTOR IN MODAL ANALYSIS OF POWER SYSTEMS STABILITY Ths paper provdes a
More informationThis lecture and the next. Why Sorting? Sorting Algorithms so far. Why Sorting? (2) Selection Sort. Heap Sort. Heapsort
Ths lecture ad the ext Heapsort Heap data structure ad prorty queue ADT Qucksort a popular algorthm, very fast o average Why Sortg? Whe doubt, sort oe of the prcples of algorthm desg. Sortg used as a subroute
More informationQuicksort. ! quicksort! selection! duplicate keys! system sorts. Two classic sorting algorithms
wo classc ng algorthms uck rtcal components n the world s computatonal nfrastructure. Full scentfc understandng of ther propertes has enabled us to deep them nto practcal system s. uck honored as one of
More information