Introduction. Introduction: Multi-Pop Stack Example. Multi-Pop Stack Cost (clever) Multi-Pop Stack Cost (naïve)
|
|
- Corey Gallagher
- 6 years ago
- Views:
Transcription
1 Introduction Today we begin studying how to calculate the total time of a sequence of operations as a whole. (As opposed to each operation individually.) Why and when we care: You have an algorithm that uses a certain data structure. E.g., Kruskal s uses clusters (disjoint sets). Some operation takes a long time. E.g., merging two clusters is sometimes expensive. But the total time turns out OK. E.g., Kruskal s total time O( V lg V + E lg E ) still good. Introduction: Multi-Pop Stack Example Multi-pop stack operations: push(x): Implementation as usual, Θ(1) time. pop(): Implementation as usual, Θ(1) time. multipop(k): Calls pop() up to k times, Θ(k) worst-case time. (Probably silly, but on purpose to show something.) Start from empty and perform m operations. What is the total time? 1 / 20 2 / 20 Multi-Pop Stack Cost (naïve) Start from empty and perform m operations. What is the total time? A naïve calculation may get a gross overestimate: 1. Each operation may take O(k) time. 2. k may be near m because stack size may be near m. 3. Total: m operations take O(m 2 ) time. You may see what s wrong with it: either multipop happens too rarely to matter or multipop happens so often, stack size stays small How to calculate a better answer? Multi-Pop Stack Cost (clever) Starting from empty, perform m operations: 1. At most m pushes. 2. Cannot pop/multipop more than what has been pushed. 3. All pops+multipops together at most m pops. 4. Total: m operations take O(m) time, worst case. (Execise: Why is it also Ω(m)?) You may be tempted to say: Each operation takes O(1) time in some sense. The next slide tells you the magic word for that! 3 / 20 4 / 20
2 Amortized Time m operations take O(m) total time, worst case. Each operation takes O(1) amortized time. This name is inspired by obvious analogies with paying for mortgages etc. Generally: If m operations take O(f (m)) total worst-case time, we can say each operation take O(f (m)/m) amortized time. Amortization Method #0: Aggregate Aggregate method: Like what I just did about multi-pop stacks. 1. At most m pushes. 2. Cannot pop/multipop more than what has been pushed. 3. All pops+multipops together at most m pops. 4. Total: m operations take O(m) time, worst case. In general: Holistically calculate total worst-case time. Usually count important events. (Similar idea outside this context: In BFS, overall count enqueue s, dequeue s, looping over adjacency lists.) Very often ad-hoc arguments and tailor-making to each situation. 5 / 20 6 / 20 Amortization Method #1: Banker/Accounting Banker/Accounting method: Using multi-pop stacks again, imagine: Each operation receives 2 dollars. Push spends 1 dollar; pop does too. Multipop(k) spends min(k, size) dollars. If surplus: Save up for future spending. If deficit: Spend past savings. Prove: savings 0 always (next slide). Conclude: each operation takes O(2) amortized time (i.e., what it receives). Prove: Multi-Pop Stack Savings 0 Actually, prove invariant: savings size. Then invoke size 0. Initially: $0 savings, and size = 0. push: $1 surplus. Both savings and size go up by 1. savings size before, savings size after. Imagine attaching this 1 dollar to the item pushed. pop: $1 surplus. savings increases, size decreases, savings size. multipop: spending = number of items popped, call it j. So just spend the money attached to those items. Recevied $2 unused. savings go down by j 2, size goes down by j. savings size before, savings size after. Remark: could have said: pop receives $0, multipop receives $0. 7 / 20 8 / 20
3 Banker/Accounting Method: Generally Postulate: Each operation receives some dollars. This will become amortized time. (Remark: Different operations may receive different dollars.) Each operation spends some dollars. This should equal actual time (within Θ). If surplus: Save up for future spending. If deficit: Spend past savings. Prove: savings 0 always. (Common technique: Imagine a distribution of savings over data. This helps the deficit case.) Conclude: Amortize time is in O(received dollars). Amortization Method #2: Physicist/Potential Physicist/Potential method: Using multi-pop stacks again: Choose potential Φ(D i ) = stack size after i operations. Let a i = (ith op actual time) + Φ(D i ) Φ(D i 1 ). Use O(a i ) as amortized time upper bound. Legitimate because their sum is total time upper bound: m a i = i=1 m (ith op actual time) + Φ(D i ) Φ(D i 1 ) i=1 = total time + Φ(D m ) Φ(D 0 ) total time + 0 Next slide calculates a i for push, pop, multipop. 9 / / 20 Calculate: Multi-Pop Stack Amortized Time a i = (ith op actual time) + (size after) (size before) If the ith operation is: push: a i = 1 + (s + 1) s = 2 where s is size before pop: a i = 1 + (s 1) s = 0 where s is size before multipop(k): a i = j + (s j) s = 0 where s is size before, j = min(k, s). Conclusion: Each amortized time is in O(1). Physicist/Potential Method: Generally Postulate potential function Φ: function from data structure state to number. Prove: Φ(D m ) Φ(D 0 ) 0. (For all [large] m, for all sequences of m operations.) (D i stands for data structure state after i operations.) (Often abbreviate Φ(D i ) as Φ i.) Calculate: (ith op actual time) + Φ(D i ) Φ(D i 1 ) for amortized time. Remark: Different operations may have different amortized times. 11 / / 20
4 Expandable Array A.k.a. dynamic table. Support array operations, increase size on demand. E.g., Java ArrayList and Vector. private T[ ] A; // A.length = textbook size = Java ArrayList capacity private int end; // textbook num, Java ArrayList size // maintain: end A.length get(i): read A[i], if i < end set(i, x): A[i] := x, if i < end size(): return end add(x): append x : A[end] := x; end += 1 Except: if A is full, first migrate to an array twice as big. (Expensive copying.) (Exercise: Why not to an array 1 unit bigger?) Pseudocode And Accounting Method for add add(x): // receive $3 if A.length = 0 then: // corner case A := new array of length 1 end := 0 if end = A.length then: // migrate, spend $(A.length) past savings newa := new array of length 2 A.length copy A s content to newa A := newa // store x, spend $1, save $2 A[end] := x end += 1 13 / / 20 Expandable Array: Accounting Method get, set, size: receives $1, spends $1. add(x) receives $3. 1. If migration needed: Since last migration, A.length/2 cells have $2 s saved. They have saved $(A.length) Just what you need for copying all of A. 2. Whether migration or not: Use received $3: spend $1 (store x), save $2 at the cell used. Therefore, savings 0 always. Expandable Array: Potential Method Note invariant: A.length/2 end. I.e., A.length 2 end. Choose potential Φ(D) = 2 end A.length. Note Φ(D) 0 for all D. For D 0 : use initial A.length = 0, end = 0. Φ(D 0 ) = 0 Therefore, Φ(D m ) Φ(D 0 ) 0 for all sequences of m operations. Now it is valid to use (ith op actual time) + Φ(D i ) Φ(D i 1 ) for amortized time. 15 / / 20
5 Potential for add Let e be end before, l be A.length before. If no migration now: a i = add s actual time + Φ(D i ) Φ(D i 1 ) = 1 + (2(e + 1) l) (2e l) = 3 If need migration now: a i = add s actual time + Φ(D i ) Φ(D i 1 ) = (1 + l) + (2(e + 1) 2l) (2e l) = 3 Expandable, Shrinkable Array One more operation: remove() discards the last item. remove(): if end > 0: end -= 1 if end < A.length/4: migrate to new array half as big Note: Right after a migration (by add or remove), array is half-empty, half-full. (Exercise: Why not migrate when end < A.length/2?) So add s amortized time is O(3). 17 / / 20 Expandable, Shrinkable Array: Accounting Method add(x): // receive $3 if end = A.length: // since last migration, at least A.length/2 add s // saved $(A.length), now spend it: double array length, copy A.length items // spend $1, save $2 A[end] := x end += 1 Maintains savings 0. Amortized time O(3). Expandable, Shrinkable Array: Accounting Method remove(): if end > 0: // receive $2 // spend $1, save $1 end -= 1 if end < A.length/4: // since last migration, at least A.length/4 remove s // saved $(A.length/4), now spend it: half array length, copy fewer than A.length/4 items Maintains savings 0. Amortized time O(2). 19 / / 20
Today we begin studying how to calculate the total time of a sequence of operations as a whole. (As opposed to each operation individually.
Introduction Today we begin studying how to calculate the total time of a sequence of operations as a whole. (As opposed to each operation individually.) Why and when we care: You have an algorithm that
More informationAmortized Analysis. A Simple Analysis. An Amortized Analysis. Incrementing Binary Numbers. A Simple Analysis
Amortized Analysis The problem domains vary widely, so this approach is not tied to any single data structure The goal is to guarantee the average performance of each operation in the worst case Three
More informationAmortized Analysis. The time required to perform a sequence of (data structure) operations is averaged over all the operations performed.
Amortized Analysis The time required to perform a sequence of (data structure) operations is averaged over all the operations performed. No probabilistic assumptions - not an average case analysis! 1 Example:
More informationCOP 4531 Complexity & Analysis of Data Structures & Algorithms
COP 4531 Complexity & Analysis of Data Structures & Algorithms Amortized Analysis Thanks to the text authors who contributed to these slides What is amortized analysis? Analyze a sequence of operations
More informationGraduate Analysis of Algorithms Prof. Karen Daniels
UMass Lowell Computer Science 9.503 Graduate Analysis of Algorithms Prof. Karen Daniels Fall, 203 Lecture 3 Monday, 9/23/3 Amortized Analysis Stack (computational geometry application) Dynamic Table Binary
More informationAmortization Analysis
December 21, 2011 Amortization Analysis The concept of amortized runtime analysis is usually first encountered when studying the efficiency of the resizing operation for an array or vector, such as in
More informationDATA STRUCTURES. amortized analysis binomial heaps Fibonacci heaps union-find. Lecture slides by Kevin Wayne. Last updated on Apr 8, :13 AM
DATA STRUCTURES amortized analysis binomial heaps Fibonacci heaps union-find Lecture slides by Kevin Wayne http://www.cs.princeton.edu/~wayne/kleinberg-tardos Last updated on Apr 8, 2013 6:13 AM Data structures
More informationDynamic Arrays and Amortized Analysis
Yufei Tao ITEE University of Queensland As mentioned earlier, one drawback of arrays is that their lengths are fixed. This makes it difficult when you want to use an array to store a set that may continuously
More informationIntroduction to Algorithms
Introduction to Algorithms 6.046J/8.40J/SMA5503 Lecture 4 Prof. Charles E. Leiserson How large should a hash table be? Goal: Make the table as small as possible, but large enough so that it won t overflow
More informationGraduate Algorithms CS F-12 Amortized Analysis
Graduate Algorithms CS673-2016F-12 Amortized Analysis David Galles Department of Computer Science University of San Francisco 12-0: Amortized Analysis Standard Stack Push(S,elem) Pop(S) How much time for
More informationAmortized Analysis and Union-Find , Inge Li Gørtz
Amortized Analysis and Union-Find 02283, Inge Li Gørtz 1 Today Amortized analysis 3 different methods 2 examples Union-Find data structures Worst-case complexity Amortized complexity 2 Amortized Analysis
More informationCS583 Lecture 12. Previously. Jana Kosecka. Amortized/Accounting Analysis Disjoint Sets. Dynamic Programming Greedy Algorithms
CS583 Lecture 12 Jana Kosecka Amortized/Accounting Analysis Disjoint Sets Dynamic Programming Greedy Algorithms Slight digression Amortized analysis Disjoint sets Previously 1 Amortized Analysis Amortized
More informationDynamic Arrays and Amortized Analysis
Department of Computer Science and Engineering Chinese University of Hong Kong As mentioned earlier, one drawback of arrays is that their lengths are fixed. This makes it difficult when you want to use
More informationCS 561, Lecture Topic: Amortized Analysis. Jared Saia University of New Mexico
CS 561, Lecture Topic: Amortized Analysis Jared Saia University of New Mexico Outline Amortized Analysis Aggregate, Taxation and Potential Methods Dynamic Table Union Find Data Structure 1 Amortized Analysis
More informationCS 561, Lecture Topic: Amortized Analysis. Jared Saia University of New Mexico
CS 561, Lecture Topic: Amortized Analysis Jared Saia University of New Mexico Outline Amortized Analysis Aggregate, Taxation and Potential Methods Dynamic Table Union Find Data Structure 1 Amortized Analysis
More informationOutline for Today. Why could we construct them in time O(n)? Analyzing data structures over the long term.
Amortized Analysis Outline for Today Euler Tour Trees A quick bug fix from last time. Cartesian Trees Revisited Why could we construct them in time O(n)? Amortized Analysis Analyzing data structures over
More informationOutline for Today. Analyzing data structures over the long term. Why could we construct them in time O(n)? A simple and elegant queue implementation.
Amortized Analysis Outline for Today Amortized Analysis Analyzing data structures over the long term. Cartesian Trees Revisited Why could we construct them in time O(n)? The Two-Stack Queue A simple and
More informationAlgorithm Theory, Winter Term 2015/16 Problem Set 5 - Sample Solution
Albert-Ludwigs-Universität, Inst. für Informatik Prof. Dr. Fabian Kuhn M. Ahmadi, O. Saukh, A. R. Molla November, 20 Algorithm Theory, Winter Term 20/6 Problem Set - Sample Solution Exercise : Amortized
More informationConnectivity. Use DFS or BFS. 03/11/04 Lecture 18 1
Connectivity A (simple) undirected graph is connected if there exists a path between every pair of vertices. If a graph is not connected, then G (V,E ) is a connected component of the graph G(V,E) if V
More informationCSE373: Data Structures & Algorithms Lecture 12: Amortized Analysis and Memory Locality. Linda Shapiro Winter 2015
CSE373: Data Structures & Algorithms Lecture 12: Amortized Analysis and Memory Locality Linda Shapiro Winter 2015 Announcements Winter 2015 CSE 373 Data structures and Algorithms 2 Amortized Analysis In
More informationStandard ADTs. Lecture 19 CS2110 Summer 2009
Standard ADTs Lecture 19 CS2110 Summer 2009 Past Java Collections Framework How to use a few interfaces and implementations of abstract data types: Collection List Set Iterator Comparable Comparator 2
More informationLecture 11 Unbounded Arrays
Lecture 11 Unbounded Arrays 15-122: Principles of Imperative Computation (Spring 2018) Rob Simmons, Frank Pfenning Arrays have efficient O(1) access to elements given an index, but their size is set at
More informationArrays. myints = new int[15];
Arrays As you know from COMP 202 (or equivalent), an array is a data structure that holds a set of elements that are of the same type. Each element in the array can be accessed or indexed by a unique number
More informationCSE373: Data Structures & Algorithms Lecture 12: Amortized Analysis and Memory Locality. Lauren Milne Spring 2015
CSE373: Data Structures & Algorithms Lecture 12: Amortized Analysis and Memory Locality Lauren Milne Spring 2015 Announcements Homework 3 due on Wednesday at 11pm Catie back Monday Spring 2015 CSE 373
More informationWeek 12: Minimum Spanning trees and Shortest Paths
Agenda: Week 12: Minimum Spanning trees and Shortest Paths Kruskal s Algorithm Single-source shortest paths Dijkstra s algorithm for non-negatively weighted case Reading: Textbook : 61-7, 80-87, 9-601
More informationUnion-Find and Amortization
Design and Analysis of Algorithms February 20, 2015 Massachusetts Institute of Technology 6.046J/18.410J Profs. Erik Demaine, Srini Devadas and Nancy Lynch Recitation 3 Union-Find and Amortization 1 Introduction
More informationCOP 4531 Complexity & Analysis of Data Structures & Algorithms
COP 4531 Complexity & Analysis of Data Structures & Algorithms Lecture 8 Data Structures for Disjoint Sets Thanks to the text authors who contributed to these slides Data Structures for Disjoint Sets Also
More informationDynamic tables. Amortized Analysis. Example of a dynamic table. Example of a dynamic table. CS Spring 2008
CS 56 -- Spring 008 Amortized Analysis Carola Wenk Slides courtesy of Charles Leiserson with small changes by Carola Wenk CS 56 Analysis of Algorithms Dynamic tables Task: Store a dynamic set in a table/array.
More informationCS 1114: Implementing Search. Last time. ! Graph traversal. ! Two types of todo lists: ! Prof. Graeme Bailey.
CS 1114: Implementing Search! Prof. Graeme Bailey http://cs1114.cs.cornell.edu (notes modified from Noah Snavely, Spring 2009) Last time! Graph traversal 1 1 2 10 9 2 3 6 3 5 6 8 5 4 7 9 4 7 8 10! Two
More informationCOMP251: Amortized Analysis
COMP251: Amortized Analysis Jérôme Waldispühl School of Computer Science McGill University Based on (Cormen et al., 2009) Overview Analyze a sequence of operations on a data structure. We will talk about
More informationCS F-12 Amortized Analysis 1
CS673-2016F-12 Amortized Analysis 1 12-0: Amortized Analysis Standard Stack Push(S,elem) Pop(S) How much time for each operation? 12-1: Amortized Analysis Standard Stack Push(S,elem)O(1) Pop(S)O(1) Multipop(S,k)
More informationSelf-Adjusting Heaps
Heaps-0 Self-Adjusting Heaps No explicit structure. Adjust the structure in a simple, uniform way, so that the efficiency of future operations is improved. Amortized Time Complexity Total time for operations
More informationLists and Arrays. Algorithms and Data Structures. (c) Marcin Sydow. Introduction. Linked Lists. Abstract Data Structure. Amortised Analysis
and s and s Lists and Topics covered by this lecture: and s Singly Doubly The Concept of Stack Queue The Concept of of Complexity Potential function method total cost and accounting methods Examples on
More information1 Lower bound on runtime of comparison sorts
1 Lower bound on runtime of comparison sorts So far we ve looked at several sorting algorithms insertion sort, merge sort, heapsort, and quicksort. Merge sort and heapsort run in worst-case O(n log n)
More informationProblem Set 4 Solutions
Design and Analysis of Algorithms March 5, 205 Massachusetts Institute of Technology 6.046J/8.40J Profs. Erik Demaine, Srini Devadas, and Nancy Lynch Problem Set 4 Solutions Problem Set 4 Solutions This
More informationAmortized Analysis. 0.1 Amortized Case Analysis. CITS2200 Data Structures and Algorithms
0.1 Amortized Case Analysis CITS2200 Data Structures and Algorithms Topic 8 Amortized Analysis Amortized Case Analysis for Data Structures An example of amortized analysis using Multipop stack The Simplist
More informationAlgorithm Design and Analysis Homework #4
Algorithm Design and Analysis Homework #4 Due: 14:20, December 6, 2012 Homework submission instructions Submit your programming assignment (problem 1) to the Judgegirl System (http://katrina.csie.ntu.edu.tw/judgegirl/).
More informationAmortized Analysis. Prof. Clarkson Fall Today s music: : "Money, Money, Money" by ABBA
Amortized Analysis Prof. Clarkson Fall 2015 Today s music: : "Money, Money, Money" by ABBA Review Current topic: Reasoning about performance Efficiency Big Oh Today: Alternative notions of efficiency Amortized
More informationCSE373: Data Structures & Algorithms Lecture 9: Priority Queues. Aaron Bauer Winter 2014
CSE373: Data Structures & Algorithms Lecture 9: Priority Queues Aaron Bauer Winter 2014 Midterm On Wednesday, in class Closed book Closed note Closed electronic devices Closed classmate Covers everything
More informationI want my two dollars!
The goode workes that men don whil they ben in good lif al amortised by synne folwyng. Geoffrey Chaucer, The Persones [Parson s] Tale (c.1400) I will gladly pay you Tuesday for a hamburger today. I want
More informationCSci 231 Final Review
CSci 231 Final Review Here is a list of topics for the final. Generally you are responsible for anything discussed in class (except topics that appear italicized), and anything appearing on the homeworks.
More informationAmortized Analysis. Andreas Klappenecker. [partially based on the slides of Prof. Welch]
Amortized Analysis Andreas Klappenecker [partially based on the slides of Prof. Welch] 1 People who analyze algorithms have double happiness. First of all they experience the sheer beauty of elegant mathematical
More informationAmortized Analysis. Ric Glassey
Amortized Analysis Ric Glassey glassey@kth.se Overview Amortized Analysis Aim: Develop methods of determining the average cost of operations on a data structure Motivation: We do not always want to think
More informationQueue. COMP 250 Fall queues Sept. 23, 2016
Queue Last lecture we looked at a abstract data type called a stack. The two main operations were push and pop. I introduced the idea of a stack by saying that it was a kind of list, but with a restricted
More informationComplexity, General. Standard approach: count the number of primitive operations executed.
Complexity, General Allmänt Find a function T(n), which behaves as the time it takes to execute the program for input of size n. Standard approach: count the number of primitive operations executed. Standard
More informationHASH TABLES cs2420 Introduction to Algorithms and Data Structures Spring 2015
HASH TABLES cs2420 Introduction to Algorithms and Data Structures Spring 2015 1 administrivia 2 -assignment 9 is due on Monday -assignment 10 will go out on Thursday -midterm on Thursday 3 last time 4
More informationLecture Summary CSC 263H. August 5, 2016
Lecture Summary CSC 263H August 5, 2016 This document is a very brief overview of what we did in each lecture, it is by no means a replacement for attending lecture or doing the readings. 1. Week 1 2.
More informationIntroduction: (Edge-)Weighted Graph
Introduction: (Edge-)Weighted Graph c 8 7 a b 7 i d 9 e 8 h 6 f 0 g These are computers and costs of direct connections. What is a cheapest way to network them? / 8 (Edge-)Weighted Graph Many useful graphs
More informationIntroduction to Data Structures. Introduction to Data Structures. Introduction to Data Structures. Data Structures
Philip Bille Data Structures Data structure. Method for organizing data for efficient access, searching, manipulation, etc. Goal. Fast. Compact Terminology. Abstract vs. concrete data structure. Dynamic
More informationAnnouncements. Problem Set 3 is due this Tuesday! Midterm graded and will be returned on Friday during tutorial (average 60%)
CSC263 Week 7 Announcements Problem Set 3 is due this Tuesday! Midterm graded and will be returned on Friday during tutorial (average 60%) Amortized Analysis O"en, we perform sequences of opera.ons on
More information16 Greedy Algorithms
16 Greedy Algorithms Optimization algorithms typically go through a sequence of steps, with a set of choices at each For many optimization problems, using dynamic programming to determine the best choices
More informationToday s Outline. CS 561, Lecture 18. Potential Method. Pseudocode. Dynamic Tables. Jared Saia University of New Mexico
Today s Outline CS 561, Lecture 18 Jared Saia University of New Mexico Dynamic Tables 1 Pseudocode Potential Method Table-Insert(T,x){ if (T.size == 0){allocate T with 1 slot;t.size=1} if (T.num == T.size){
More informationLecture Notes for Advanced Algorithms
Lecture Notes for Advanced Algorithms Prof. Bernard Moret September 29, 2011 Notes prepared by Blanc, Eberle, and Jonnalagedda. 1 Average Case Analysis 1.1 Reminders on quicksort and tree sort We start
More informationAdam Blank Lecture 1 Winter 2017 CSE 332. Data Abstractions
Adam Blank Lecture 1 Winter 2017 CSE 332 Data Abstractions CSE 332: Data Abstractions Welcome to CSE 332! Outline 1 Administrivia 2 A Data Structures Problem 3 Review of Stacks & Queues What Am I Getting
More information(Refer Slide Time: 01.26)
Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi Lecture # 22 Why Sorting? Today we are going to be looking at sorting.
More informationHomework #5 Algorithms I Spring 2017
Homework #5 Algorithms I 600.463 Spring 2017 Due on: Saturday, March 18th, 11:59pm Late submissions: will NOT be accepted Format: Please start each problem on a new page. Where to submit: On Gradescope,
More informationAnalyze the obvious algorithm, 5 points Here is the most obvious algorithm for this problem: (LastLargerElement[A[1..n]:
CSE 101 Homework 1 Background (Order and Recurrence Relations), correctness proofs, time analysis, and speeding up algorithms with restructuring, preprocessing and data structures. Due Thursday, April
More informationLecture 9: Amortized Analysis [Fa 13] I want my two dollars!
The goode workes that men don whil they ben in good lif al amortised by synne folwyng. Geoffrey Chaucer, The Persones [Parson s] Tale (c.1400) I will gladly pay you Tuesday for a hamburger today. I want
More informationIntroduction to Data Structures
Introduction to Data Structures Data structures Stacks and Queues Linked Lists Dynamic Arrays Philip Bille Introduction to Data Structures Data structures Stacks and Queues Linked Lists Dynamic Arrays
More informationCS Prof. Clarkson Fall 2014
CS 3110 Lecture 25: Amortized Analysis Prof. Clarkson Fall 2014 Today s music: "Money, Money, Money" by ABBA "Mo Money Mo Problems" by The Notorious B.I.G. "Material Girl" by Madonna Review Current topic:
More informationArrays. Array Definition
Presentation for use with the textbook Data Structures and Algorithms in Java, 6 th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser, Wiley, 2014 Arrays Arrays 1 Array Definition An array
More informationintroduction to Programming in C Department of Computer Science and Engineering Lecture No. #40 Recursion Linear Recursion
introduction to Programming in C Department of Computer Science and Engineering Lecture No. #40 Recursion Linear Recursion Today s video will talk about an important concept in computer science which is
More informationComp2402: Review Questions
Comp2402: Review Questions 1: JCF & Big-Oh 1.1 Big-Oh Notation 1. What is O(n)? What kind of object is it? 2. What does the statement 2n + 3 = O(n 2 ) mean? 3. Recall the basic big-o hierarchy: for any
More informationCS 161 Summer 2009 Homework #1 Sample Solutions
CS 161 Summer 2009 Homework #1 Sample Solutions Regrade Policy: If you believe an error has been made in the grading of your homework, you may resubmit it for a regrade. If the error consists of more than
More informationCS301 - Data Structures Glossary By
CS301 - Data Structures Glossary By Abstract Data Type : A set of data values and associated operations that are precisely specified independent of any particular implementation. Also known as ADT Algorithm
More informationRecitation 9. Prelim Review
Recitation 9 Prelim Review 1 Heaps 2 Review: Binary heap min heap 1 2 99 4 3 PriorityQueue Maintains max or min of collection (no duplicates) Follows heap order invariant at every level Always balanced!
More informationWeek 11: Minimum Spanning trees
Week 11: Minimum Spanning trees Agenda: Minimum Spanning Trees Prim s Algorithm Reading: Textbook : 61-7 1 Week 11: Minimum Spanning trees Minimum spanning tree (MST) problem: Input: edge-weighted (simple,
More informationCOMP2402: Mid-term Review Questions
COMP2402: Mid-term Review Questions October 20, 2010 1 Java Collections Framework Interfaces All of these questions should be considered in the context of the interfaces in the Java Collections Framework
More informationThe java.util.list ADT
Presentation for use with the textbook Data Structures and Algorithms in Java, 6 th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser, Wiley, 2014 Lists and Iterators 2014 Goodrich, Tamassia,
More informationLinked Structures. See Section 3.2 of the text.
Linked Structures See Section 3.2 of the text. First, notice that Java allows classes to be recursive, in the sense that a class can have an element which is itself an object of that class: class Person
More informationThe divide and conquer strategy has three basic parts. For a given problem of size n,
1 Divide & Conquer One strategy for designing efficient algorithms is the divide and conquer approach, which is also called, more simply, a recursive approach. The analysis of recursive algorithms often
More informationDesign and Analysis of Algorithms Prof. Madhavan Mukund Chennai Mathematical Institute. Week 02 Module 06 Lecture - 14 Merge Sort: Analysis
Design and Analysis of Algorithms Prof. Madhavan Mukund Chennai Mathematical Institute Week 02 Module 06 Lecture - 14 Merge Sort: Analysis So, we have seen how to use a divide and conquer strategy, we
More informationimplementing the breadth-first search algorithm implementing the depth-first search algorithm
Graph Traversals 1 Graph Traversals representing graphs adjacency matrices and adjacency lists 2 Implementing the Breadth-First and Depth-First Search Algorithms implementing the breadth-first search algorithm
More informationCSE 373: Data Structures and Algorithms
CSE 373: Data Structures and Algorithms Lecture 6: Finishing Amortized Analysis; Dictionaries ADT; Introduction to Hash Tables Instructor: Lilian de Greef Quarter: Summer 2017 Today: Finish up Amortized
More informationStacks and queues (chapters 6.6, 15.1, 15.5)
Stacks and queues (chapters 6.6, 15.1, 15.5) So far... Complexity analysis For recursive and iterative programs Sorting algorithms Insertion, selection, quick, merge, (intro, dual-pivot quick, natural
More informationCH ALGORITHM ANALYSIS CH6. STACKS, QUEUES, AND DEQUES
CH4.2-4.3. ALGORITHM ANALYSIS CH6. STACKS, QUEUES, AND DEQUES ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN JAVA, GOODRICH, TAMASSIA AND GOLDWASSER
More informationCMPS 2200 Fall Amortized Analysis. Carola Wenk. Slides courtesy of Charles Leiserson with changes by Carola Wenk
CMPS 2200 Fall 2017 Amortized Analysis Carola Wenk Slides courtesy of Charles Leiserson with changes by Carola Wenk 11/15/17 CMPS 2200 Intro. to Algorithms 1 Dynamic tables Task: Store a dynamic set in
More informationSection 05: Solutions
Section 05: Solutions 1. Memory and B-Tree (a) Based on your understanding of how computers access and store memory, why might it be faster to access all the elements of an array-based queue than to access
More informationCS221: Algorithms and Data Structures. Asymptotic Analysis. Alan J. Hu (Borrowing slides from Steve Wolfman)
CS221: Algorithms and Data Structures Asymptotic Analysis Alan J. Hu (Borrowing slides from Steve Wolfman) 1 Learning Goals By the end of this unit, you will be able to Define which program operations
More informationStacks and Queues
Stacks and Queues 2-25-2009 1 Opening Discussion Let's look at solutions to the interclass problem. Do you have any questions about the reading? Do you have any questions about the assignment? Minute Essays
More informationThe resulting array is written as row i + 1 in our matrix:
Homework 5 Solutions Fundamental Algorithms, Fall 2004, Professor Yap Due: Thu December 9, in class SOLUTION PREPARED BY Instructor and T.A.s Ariel Cohen and Vikram Sharma INSTRUCTIONS: NOTICE: In the
More informationKeeping Order:! Stacks, Queues, & Deques. Travis W. Peters Dartmouth College - CS 10
Keeping Order:! Stacks, Queues, & Deques 1 Stacks 2 Stacks A stack is a last in, first out (LIFO) data structure Primary Operations: push() add item to top pop() return the top item and remove it peek()
More informationDesign and Analysis of Algorithms
Design and Analysis of Algorithms CSE 5311 Lecture 8 Sorting in Linear Time Junzhou Huang, Ph.D. Department of Computer Science and Engineering CSE5311 Design and Analysis of Algorithms 1 Sorting So Far
More informationActivity 13: Amortized Analysis
Activity 3: Amortized Analysis Model : Incrementing a binary counter 5 4 3 2 9 8 7 6 5 4 3 2 2 3 4 5 Model shows a binary counter, stored as an array of bits with the 2 i place stored at index i, undergoing
More informationUniversity of Illinois at Urbana-Champaign Department of Computer Science. Final Examination
University of Illinois at Urbana-Champaign Department of Computer Science Final Examination CS 225 Data Structures and Software Principles Spring 2010 7-10p, Wednesday, May 12 Name: NetID: Lab Section
More informationModule 1: Asymptotic Time Complexity and Intro to Abstract Data Types
Module 1: Asymptotic Time Complexity and Intro to Abstract Data Types Dr. Natarajan Meghanathan Professor of Computer Science Jackson State University Jackson, MS 39217 E-mail: natarajan.meghanathan@jsums.edu
More informationComputer Science 62. Bruce/Mawhorter Fall 16. Midterm Examination. October 5, Question Points Score TOTAL 52 SOLUTIONS. Your name (Please print)
Computer Science 62 Bruce/Mawhorter Fall 16 Midterm Examination October 5, 2016 Question Points Score 1 15 2 10 3 10 4 8 5 9 TOTAL 52 SOLUTIONS Your name (Please print) 1. Suppose you are given a singly-linked
More informationCSE373: Data Structures & Algorithms Lecture 11: Implementing Union-Find. Lauren Milne Spring 2015
CSE: Data Structures & Algorithms Lecture : Implementing Union-Find Lauren Milne Spring 05 Announcements Homework due in ONE week Wednesday April 9 th! TA sessions Catie will be back on Monday. The plan
More informationCS 310: ArrayList Implementation
CS 310: ArrayList Implementation Chris Kauffman Week 2-2 Logistics At Home Read Weiss Ch 5: Big-O Read Weiss Ch 15: ArrayList implementation Reminder to DrJava Users Consider Using GMU Edition of DrJava
More informationCS61B Lecture #17. Last modified: Mon Oct 1 13:40: CS61B: Lecture #17 1
CS61B Lecture #17 Last modified: Mon Oct 1 13:40:29 2018 CS61B: Lecture #17 1 Topics Overview of standard Java Collections classes Iterators, ListIterators Containers and maps in the abstract Amortized
More informationContext: Weighted, connected, undirected graph, G = (V, E), with w : E R.
Chapter 23: Minimal Spanning Trees. Context: Weighted, connected, undirected graph, G = (V, E), with w : E R. Definition: A selection of edges from T E such that (V, T ) is a tree is called a spanning
More information(I m not printing out these notes! Take your own.)
PT1420 Week 2: Software Program Design I (I m not printing out these notes! Take your own.) Today we'll be discussing designing programs: Algorithms and errors Flowcharts and pseudocode Sequence structures
More informationBasic Data Structures
Basic Data Structures Some Java Preliminaries Generics (aka parametrized types) is a Java mechanism that enables the implementation of collection ADTs that can store any type of data Stack s1
More informationCSE 373: AVL trees. Michael Lee Friday, Jan 19, 2018
CSE 373: AVL trees Michael Lee Friday, Jan 19, 2018 1 Warmup Warmup: What is an invariant? What are the AVL tree invariants, exactly? Discuss with your neighbor. 2 AVL Trees: Invariants Core idea: add
More informationRepresentations of Weighted Graphs (as Matrices) Algorithms and Data Structures: Minimum Spanning Trees. Weighted Graphs
Representations of Weighted Graphs (as Matrices) A B Algorithms and Data Structures: Minimum Spanning Trees 9.0 F 1.0 6.0 5.0 6.0 G 5.0 I H 3.0 1.0 C 5.0 E 1.0 D 28th Oct, 1st & 4th Nov, 2011 ADS: lects
More informationASYMPTOTIC COMPLEXITY
Simplicity is a great virtue but it requires hard work to achieve it and education to appreciate it. And to make matters worse: complexity sells better. - Edsger Dijkstra ASYMPTOTIC COMPLEXITY Lecture
More informationAnalysis of Algorithms. 5-Dec-16
Analysis of Algorithms 5-Dec-16 Time and space To analyze an algorithm means: developing a formula for predicting how fast an algorithm is, based on the size of the input (time complexity), and/or developing
More informationFaculty of Science FINAL EXAMINATION COMP-250 A Introduction to Computer Science School of Computer Science, McGill University
NAME: STUDENT NUMBER:. Faculty of Science FINAL EXAMINATION COMP-250 A Introduction to Computer Science School of Computer Science, McGill University Examimer: Prof. Mathieu Blanchette December 8 th 2005,
More informationCS:3330 (22c:31) Algorithms
What s an Algorithm? CS:3330 (22c:31) Algorithms Introduction Computer Science is about problem solving using computers. Software is a solution to some problems. Algorithm is a design inside a software.
More informationStacks, Queues (cont d)
Stacks, Queues (cont d) CSE 2011 Winter 2007 February 1, 2007 1 The Adapter Pattern Using methods of one class to implement methods of another class Example: using List to implement Stack and Queue 2 1
More information