Lecture 6 More Divide-Conquer and Paradigm #4 Data Structure.

Slides:



Advertisements
Similar presentations
A simple example finding the maximum of a set S of n numbers.
Advertisements

Analysis of Algorithms
More on Divide and Conquer. The divide-and-conquer design paradigm 1. Divide the problem (instance) into subproblems. 2. Conquer the subproblems by solving.
Comp 122, Spring 2004 Divide and Conquer (Merge Sort)
Introduction to Algorithms Jiafen Liu Sept
CS4413 Divide-and-Conquer
Divide-and-Conquer Recursive in structure –Divide the problem into several smaller sub-problems that are similar to the original but smaller in size –Conquer.
Introduction to Algorithms 6.046J/18.401J L ECTURE 3 Divide and Conquer Binary search Powering a number Fibonacci numbers Matrix multiplication Strassen’s.
CS223 Advanced Data Structures and Algorithms 1 Divide and Conquer Neil Tang 4/15/2010.
CS Section 600 CS Section 002 Dr. Angela Guercio Spring 2010.
Divide-and-Conquer1 7 2  9 4   2  2 79  4   72  29  94  4.
Divide-and-Conquer1 7 2  9 4   2  2 79  4   72  29  94  4.
CSE 421 Algorithms Richard Anderson Lecture 12 Recurrences.
Data Structures, Spring 2004 © L. Joskowicz 1 Data Structures – LECTURE 7 Heapsort and priority queues Motivation Heaps Building and maintaining heaps.
CSC 2300 Data Structures & Algorithms January 30, 2007 Chapter 2. Algorithm Analysis.
Recurrence Examples.
Lecture 2 We have given O(n 3 ), O(n 2 ), O(nlogn) algorithms for the max sub-range problem. This time, a linear time algorithm! The idea is as follows:
Divide-and-Conquer 7 2  9 4   2   4   7
David Luebke 1 10/3/2015 CS 332: Algorithms Solving Recurrences Continued The Master Theorem Introduction to heapsort.
CS 3343: Analysis of Algorithms
Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 3 Prof. Erik Demaine.
CS223 Advanced Data Structures and Algorithms 1 Sorting and Master Method Neil Tang 01/21/2009.
Week 6 - Monday.  What did we talk about last time?  Exam 1!  Before that:  Recursion.
Recurrences David Kauchak cs161 Summer Administrative Algorithms graded on efficiency! Be specific about the run times (e.g. log bases) Reminder:
CSC 413/513: Intro to Algorithms Solving Recurrences Continued The Master Theorem Introduction to heapsort.
Lecture 5 Today, how to solve recurrences We learned “guess and proved by induction” We also learned “substitution” method Today, we learn the “master.
1Computer Sciences. 2 GROWTH OF FUNCTIONS 3.2 STANDARD NOTATIONS AND COMMON FUNCTIONS.
CS321 Spring 2016 Lecture 3 Jan Admin A1 Due this Friday – 11:00PM Thursday = Recurrence Equations – Important. Everyone Should be added to class.
Lecture # 6 1 Advance Analysis of Algorithms. Divide-and-Conquer Divide the problem into a number of subproblems Similar sub-problems of smaller size.
ECOE 556: Algorithms and Computational Complexity Heapsort Serdar Taşıran.
Sorting Lower Bounds n Beating Them. Recap Divide and Conquer –Know how to break a problem into smaller problems, such that –Given a solution to the smaller.
Introduction to Algorithms: Divide-n-Conquer Algorithms
Introduction to Algorithms
"Teachers open the door, but you must enter by yourself. "
Lecture 3: Parallel Algorithm Design
Heaps, Heapsort, and Priority Queues
Divide-and-Conquer 6/30/2018 9:16 AM
CS 3343: Analysis of Algorithms
Algorithm Design & Analysis
Divide-and-Conquer The most-well known algorithm design strategy:
Chapter 4 Divide-and-Conquer
COMP 103 HeapSort Thomas Kuehne 2013-T1 Lecture 27
Algorithms with numbers (1) CISC4080, Computer Algorithms
Lecture Outline for Recurrences
CS 3343: Analysis of Algorithms
Intro to Recursion.
MergeSort Source: Gibbs & Tamassia.
Growth Functions Algorithms Lecture 8
CS 3343: Analysis of Algorithms
CS 3343: Analysis of Algorithms
Priority Queue and Binary Heap Neil Tang 02/12/2008
תרגול 3 - רקורסיה.
Data Structures Review Session
CS 3343: Analysis of Algorithms
Divide-and-Conquer 7 2  9 4   2   4   7
Richard Anderson Lecture 11 Recurrences
Sorting.
CSE 373 Data Structures and Algorithms
Design and Analysis of Algorithms
Introduction to Algorithms
Divide and Conquer (Merge Sort)
Divide-and-Conquer 7 2  9 4   2   4   7
Divide and Conquer Neil Tang 4/24/2008
Trevor Brown CS 341: Algorithms Trevor Brown
Solving Recurrences Continued The Master Theorem
Lecture 30 CSE 331 Nov 12, 2012.
Divide-and-Conquer 7 2  9 4   2   4   7
Richard Anderson Lecture 12, Winter 2019 Recurrences
Searching.
Richard Anderson Lecture 12 Recurrences
Presentation transcript:

Lecture 6 More Divide-Conquer and Paradigm #4 Data Structure. Talk at U of Maryland Lecture 6 More Divide-Conquer and Paradigm #4 Data Structure. Today, we do more “divide-and-conquer”. And, we do Algorithm design paradigm # 4: invent or augment a data structure.

More divide and conquer: powering a number Problem: Compute an , where n is an integer. Naïve algorithm Θ(n). Divide-and-conquer: an = an/2 an/2 if n is even. = a(n-1)/2 a(n-1)/2 a if n is odd Note, another kind of divide and conquer. Time complexity: T(n) = T(n/2) + Θ(1) = Θ(logn)

Back to Fibonacci numbers Recursion: not careful would give exponential time algorithm. Plain linear bottom up computation: Θ(n). Can we do better? Theorem: Fn+1 Fn 1 1 Fn Fn-1 1 0 I will prove this in class. Then you can compute this similar to powering of an integer in Θ(logn) steps. n

VLSI tree layout Problem: Embed a complete binary tree with n leaves in a grid using minimal area. W(n) H(n) H(n) = Θ(lg n) W(n) = Θ(n) Area = Θ(n lg n)

How do we improve this embedding? If we wish to have an O(n) solution for the area, perhaps we wish to have √n for L(n) and W(n). What recursion scheme would get us there? The Master theorem Case 1 says if b=4, a=2, then log4 2 =1/2. So if we have something like T(n) = 2T(n/4) + o(√n) we would get O(√n) solution for L(n) and W(n).

H-tree embedding scheme L(n/4) L(n) L(n) = 2L(n/4) + Θ(1) = Θ(√n) Area = Θ(n)

Paradigm #4 Use a data structure.

Talk at U of Maryland Example 1. Heapsort We invent a data structure (the heap) to support sorting.

Talk at U of Maryland Example 2. Subrange sum We want to maintain an array of integers a[1..n], and support the following operations: A. Increment a[i] by b; that is, set a[i] += b. B. Subrange sum: compute the sum of the elements a[c], a[c+1], ..., a[d]. Augment array as follows: a[1] a[2] a[3] a[4] a[5] a[6] a[7] a[8] a[1..2] a[3..4] a[5..6] a[7..8] a[1..4] a[5..8] a[1..8] Operations A and B are both in O(logn) time.