Algorithms (IX) Guoqiang Li. School of Software, Shanghai Jiao Tong University
|
|
- Aileen Wiggins
- 6 years ago
- Views:
Transcription
1 Algorithms (IX) Guoqiang Li School of Software, Shanghai Jiao Tong University
2 Q: What we have learned in Algorithm?
3 Algorithm Design
4 Algorithm Design
5 Basic methodologies: Algorithm Design
6 Algorithm Design Basic methodologies: Divide and Conquer (Chapter 2)
7 Algorithm Design Basic methodologies: Divide and Conquer (Chapter 2) Master Theorem
8 Algorithm Design Basic methodologies: Divide and Conquer (Chapter 2) Master Theorem Recursion (Chapter 0 & 1)
9 Algorithm Design Basic methodologies: Divide and Conquer (Chapter 2) Master Theorem Recursion (Chapter 0 & 1) Advanced topics:
10 Algorithm Design Basic methodologies: Divide and Conquer (Chapter 2) Master Theorem Recursion (Chapter 0 & 1) Advanced topics: Dynamic Programming (Chapter 6)
11 Algorithm Design Basic methodologies: Divide and Conquer (Chapter 2) Master Theorem Recursion (Chapter 0 & 1) Advanced topics: Dynamic Programming (Chapter 6) Filling in Squares.
12 Algorithm Design Basic methodologies: Divide and Conquer (Chapter 2) Master Theorem Recursion (Chapter 0 & 1) Advanced topics: Dynamic Programming (Chapter 6) Filling in Squares. Complexity.
13 Algorithm Design Basic methodologies: Divide and Conquer (Chapter 2) Master Theorem Recursion (Chapter 0 & 1) Advanced topics: Dynamic Programming (Chapter 6) Filling in Squares. Complexity. Greedy Algorithm (Chapter 5)
14 Algorithm Design Basic methodologies: Divide and Conquer (Chapter 2) Master Theorem Recursion (Chapter 0 & 1) Advanced topics: Dynamic Programming (Chapter 6) Filling in Squares. Complexity. Greedy Algorithm (Chapter 5) Linear Programming (Chapter 7)
15 Algorithm Design Basic methodologies: Divide and Conquer (Chapter 2) Master Theorem Recursion (Chapter 0 & 1) Advanced topics: Dynamic Programming (Chapter 6) Filling in Squares. Complexity. Greedy Algorithm (Chapter 5) Linear Programming (Chapter 7) Simplex.
16 Algorithm Design Basic methodologies: Divide and Conquer (Chapter 2) Master Theorem Recursion (Chapter 0 & 1) Advanced topics: Dynamic Programming (Chapter 6) Filling in Squares. Complexity. Greedy Algorithm (Chapter 5) Linear Programming (Chapter 7) Simplex. System Design.
17 Algorithm Design Basic methodologies: Divide and Conquer (Chapter 2) Master Theorem Recursion (Chapter 0 & 1) Advanced topics: Dynamic Programming (Chapter 6) Filling in Squares. Complexity. Greedy Algorithm (Chapter 5) Linear Programming (Chapter 7) Simplex. System Design. Duality.
18 Algorithm Design Basic methodologies: Divide and Conquer (Chapter 2) Master Theorem Recursion (Chapter 0 & 1) Advanced topics: Dynamic Programming (Chapter 6) Filling in Squares. Complexity. Greedy Algorithm (Chapter 5) Linear Programming (Chapter 7) Simplex. System Design. Duality. Randomized Algorithm
19 Algorithm Design Basic methodologies: Divide and Conquer (Chapter 2) Master Theorem Recursion (Chapter 0 & 1) Advanced topics: Dynamic Programming (Chapter 6) Filling in Squares. Complexity. Greedy Algorithm (Chapter 5) Linear Programming (Chapter 7) Simplex. System Design. Duality. Randomized Algorithm Approximation Algorithm
20 Algorithm Analysis
21 Algorithm Analysis
22 Basic Knowledge Algorithm Analysis
23 Algorithm Analysis Basic Knowledge Big-O Notation (Chapter 0)
24 Algorithm Analysis Basic Knowledge Big-O Notation (Chapter 0) Recursion and Loop (Chapter 1)
25 Algorithm Analysis Basic Knowledge Big-O Notation (Chapter 0) Recursion and Loop (Chapter 1) geometrical Analysis (Chapter 2)
26 Algorithm Analysis Basic Knowledge Big-O Notation (Chapter 0) Recursion and Loop (Chapter 1) geometrical Analysis (Chapter 2) Advanced Methodology:
27 Algorithm Analysis Basic Knowledge Big-O Notation (Chapter 0) Recursion and Loop (Chapter 1) geometrical Analysis (Chapter 2) Advanced Methodology: Probability Analysis (Chapter 1)
28 Algorithm Analysis Basic Knowledge Big-O Notation (Chapter 0) Recursion and Loop (Chapter 1) geometrical Analysis (Chapter 2) Advanced Methodology: Probability Analysis (Chapter 1) Amortized Analysis (Chapter 5)
29 Algorithm Analysis Basic Knowledge Big-O Notation (Chapter 0) Recursion and Loop (Chapter 1) geometrical Analysis (Chapter 2) Advanced Methodology: Probability Analysis (Chapter 1) Amortized Analysis (Chapter 5) Competition Analysis (Chapter 9)
30 Standard Algorithm
31 Standard Algorithms
32 Standard Algorithms Arithmetic Algorithm
33 Standard Algorithms Arithmetic Algorithm Sorting
34 Standard Algorithms Arithmetic Algorithm Sorting Searching Strongly Connected Components
35 Standard Algorithms Arithmetic Algorithm Sorting Searching Strongly Connected Components Finding shortest paths in graphs
36 Standard Algorithms Arithmetic Algorithm Sorting Searching Strongly Connected Components Finding shortest paths in graphs Minimum spanning trees in graphs
37 Standard Algorithms Arithmetic Algorithm Sorting Searching Strongly Connected Components Finding shortest paths in graphs Minimum spanning trees in graphs Matchings in bipartite graphs
38 Standard Algorithms Arithmetic Algorithm Sorting Searching Strongly Connected Components Finding shortest paths in graphs Minimum spanning trees in graphs Matchings in bipartite graphs Maximum flows in networks
39 Advanced Data Structure
40 Advanced Data Structure
41 Advanced Data Structure Trees, Graphs
42 Advanced Data Structure Trees, Graphs Kripke Structure, Automata
43 Advanced Data Structure Trees, Graphs Kripke Structure, Automata Priority Queue (Chapter 4)
44 Advanced Data Structure Trees, Graphs Kripke Structure, Automata Priority Queue (Chapter 4) Disjoint Set (Chapter 5)
45 What Is Important in Algorithm under My Concern?
46 I. Proof and Witness
47 Mathematical Induction. Proof and Witness
48 Proof and Witness Mathematical Induction. Proof of iff, =,
49 Proof and Witness Mathematical Induction. Proof of iff, =, Deduction.
50 Examples log n! = Θ(n log n)
51 Examples log n! = Θ(n log n) A directed graph has a cycle if and only if its depth-first search reveals a back edge.
52 Examples log n! = Θ(n log n) A directed graph has a cycle if and only if its depth-first search reveals a back edge. An undirected graph is bipartite if and only if it contains no cycles of odd length.
53 II. Reductions
54 Bipartite Matching BOYS Al Bob Chet Dan GIRLS Alice Beatrice Carol Danielle
55 Bipartite Matching Al Alice s Bob Chet Beatrice Carol t Dan Danielle
56 Reductions We want to solve Problem P. We already have an algorithm that solves Problem Q. If any subroutine for Q can also be used to solve P, we say P reduces to Q. Often, P is solvable by a single call to Q s subroutine, which means any instance x of P can be transformed into an instance y of Q such that P(x) can be deduced from Q(y).
57 III. Divide-and-Conquer Vs. Dynamic Programming
58 Master Theorem If T(n) = at( n/b ) + O(n d ) for some constants a > 0, b > 1 and d 0, then O(n d ) if d > log b a T(n) = O(n d log n) if d = log b a O(n log b a ) if d < log b a
59 The Proof of the Theorem Proof: Assume that n is a power of b. The size of the subproblems decreases by a factor of b with each level of recursion, and therefore reaches the base case after log b n levels - the the height of the recursion tree. Its branching factor is a, so the k-th level of the tree is made up of a k subproblems, each of size n/b k. a k O( n b k )d = O(n d ) ( a b d )k k goes from 0 to log b n, these numbers form a geometric series with ratio a/b d, comes down to three cases.
60 The Proof of the Theorem The ratio is less than 1. Then the series is decreasing, and its sum is just given by its first term, O(n d ). The ratio is greater than 1. The series is increasing and its sum is given by its last term, O(n log b a ) The ratio is exactly 1. In this case all O(log n) terms of the series are equal to O(n d ).
61 The Problem When a spell checker encounters a possible misspelling, it looks in its dictionary for other words that are close by. S N O W Y S U N N Y Cost: 3 S N O W Y S U N N Y Cost: 5
62 The Problem When a spell checker encounters a possible misspelling, it looks in its dictionary for other words that are close by. Q: What is the appropriate notion of closeness in this case? S N O W Y S U N N Y Cost: 3 S N O W Y S U N N Y Cost: 5
63 The Problem When a spell checker encounters a possible misspelling, it looks in its dictionary for other words that are close by. Q: What is the appropriate notion of closeness in this case? A natural measure of the distance between two strings is the extent to which they can be aligned, or matched up. S N O W Y S U N N Y Cost: 3 S N O W Y S U N N Y Cost: 5
64 The Problem When a spell checker encounters a possible misspelling, it looks in its dictionary for other words that are close by. Q: What is the appropriate notion of closeness in this case? A natural measure of the distance between two strings is the extent to which they can be aligned, or matched up. Technically, an alignment is simply a way of writing the strings one above the other. S N O W Y S U N N Y Cost: 3 S N O W Y S U N N Y Cost: 5
65 The Problem The cost of an alignment is the number of columns in which the letters differ. S N O W Y S U N N Y Cost: 3 S N O W Y S U N N Y Cost: 5
66 The Problem The cost of an alignment is the number of columns in which the letters differ. And the edit distance between two strings is the cost of their best possible alignment. S N O W Y S U N N Y Cost: 3 S N O W Y S U N N Y Cost: 5
67 The Problem The cost of an alignment is the number of columns in which the letters differ. And the edit distance between two strings is the cost of their best possible alignment. Edit distance is so named because it can also be thought of as the minimum number of edits S N O W Y S U N N Y Cost: 3 S N O W Y S U N N Y Cost: 5
68 The Problem The cost of an alignment is the number of columns in which the letters differ. And the edit distance between two strings is the cost of their best possible alignment. Edit distance is so named because it can also be thought of as the minimum number of edits insertions, deletions, and substitutions of characters needed to transform the first string into the second. S N O W Y S U N N Y Cost: 3 S N O W Y S U N N Y Cost: 5
69 A Dynamic Programming Solution When solving a problem by dynamic programming, the most crucial question is,
70 A Dynamic Programming Solution When solving a problem by dynamic programming, the most crucial question is, What are the subproblems?
71 A Dynamic Programming Solution When solving a problem by dynamic programming, the most crucial question is, What are the subproblems? Our goal is to find the edit distance between two strings x[1,..., m] and y[1,..., n].
72 A Dynamic Programming Solution When solving a problem by dynamic programming, the most crucial question is, What are the subproblems? Our goal is to find the edit distance between two strings x[1,..., m] and y[1,..., n]. For every i, j with 1 i m and 1 j n, let
73 A Dynamic Programming Solution When solving a problem by dynamic programming, the most crucial question is, What are the subproblems? Our goal is to find the edit distance between two strings x[1,..., m] and y[1,..., n]. For every i, j with 1 i m and 1 j n, let E(i, j): the edit distance between some prefix of the first string, x[1,..., i], and some prefix of the second, y[1,..., j].
74 A Dynamic Programming Solution When solving a problem by dynamic programming, the most crucial question is, What are the subproblems? Our goal is to find the edit distance between two strings x[1,..., m] and y[1,..., n]. For every i, j with 1 i m and 1 j n, let E(i, j): the edit distance between some prefix of the first string, x[1,..., i], and some prefix of the second, y[1,..., j]. E(i, j) = min{1 + E(i 1, j), 1 + E(i, j 1), diff(i, j) + E(i 1, j 1)}, where diff(i, j) is defined to be 0 if x[i] = y[j] and 1 otherwise.
75 An Example Edit distance between EXPONENTIAL and POLYNOMIAL, subproblem E(4, 3) corresponds to the prefixes EXPO and POL. The rightmost column of their best alignment must be one of the following: O or Thus, E(4, 3) = min{1 + E(3, 3), 1 + E(4, 2); 1 + E(3, 2)}. (a) i 1 i m j 1 j n GOAL L (b) or O L P O L Y N O M I A L E X P O N E N T I A L
76 Chapter by Chapter
77 Chapter 0 Prologue
78 Big-O Notation Multiplicative constants can be omitted: 14n 2 becomes n 2. n a dominates n b if a > b, for instance, n 2 dominates n a n dominates b n if a > b, for instance, 3 n dominates 2 n Any exponential dominates any polynomial: 3 n dominates n 5 Any polynomial dominates any logarithm: n dominates (log n) 3. This also means, for example, that n 2 dominates n log n.
79 An Example 0.1. Ineachofthefollowingsituations,indicatewhether f = O(g),or f = Ω(g),orboth(inwhichcase 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) 2 (d) n log n 10n log10n (e) log 2n log 3n (f) 10 logn log(n 2 ) (g) n 1.01 n log 2 n (h) n 2 / logn n(log n) 2
80 An Example (i) n 0.1 (log n) 10 (j) (log n) log n n/ logn (k) n (log n) 3 (l) n 1/2 5 log 2 n (m) n2 n 3 n (n) 2 n 2 n+1 (o) n! 2 n (p) (log n) log n 2 (log 2 n)2 n (q) i=1 ik n k+1
81 Chapter 1 Algorithms with Numbers
82 Recursion Analysis MODEXP(x, y, N); Two n-bit integers x and N, and an integer exponent y; if y = 0 then return 1; z=modexp (x, y/2, N); if y is even then return z 2 mod N; else return x z 2 (mod N); end Another formulation: x y (mod N) = { (x y/2 ) 2 (mod N) if y is even x (x y/2 ) 2 (mod N) if y is odd
83 Arithmetic Algorithm What is the GCD of 42 and 96? Can you prove it?
84 Chapter 2. Divide-and-Conquer
85 An Example Foo(x); if x > 1 then Printf( Hello World ); Foo(x/4); Foo(x/4); Foo(x/4); end
86 Chapter 3. Decompositions of Graphs
87 Our Tools and Weapons
88 DFS (Explore) Our Tools and Weapons
89 Our Tools and Weapons DFS (Explore) DAG, Linearization
90 Our Tools and Weapons DFS (Explore) DAG, Linearization SCC
91 Exercise 1 Suppose a CS curriculum consists of n courses, all of them mandatory. The prerequisite graph G hasanodeforeachcourse,andanedgefromcourse vtocourse wifandonlyif visaprerequisite for w. Find an algorithm that works directly with this graph representation, and computes the minimum number of semesters necessary to complete the curriculum(assume that a student cantakeanynumberofcoursesinonesemester).therunningtimeofyouralgorithmshouldbe linear.
92 Exercise Giveanefficientalgorithmwhichtakesasinputadirectedgraph G = (V, E),anddetermines whetherornotthereisavertex s V fromwhichallotherverticesarereachable.
93 Exercise 3 A bipartite graph is a graph G = (V, E) whose vertices can be partitioned into two sets (V = V 1 V 2 and V 1 V 2 = ) such that there are no edges between vertices in the same set (for instance, if u, v V 1, then there is no edge between u and v). (a) Give a linear-time algorithm to determine whether an undirected graph is bipartite. (b) Prove that an undirected graph is bipartite if and only if it contains no cycles of odd length. (c) At most how many colors are needed to color in an undirected graph with exactly one odd length cycle?
94 Exercise 4 Prove that given a connected undirected graph G = (V, E), there exists a node v V, such that G is still connected after deleting v.
95 Exercise 5 Given a directed graph, work out an efficient algorithm, to find all cross edges in DFS searching.
96 Chapter 4. Path in Graphs
97 Our Tools and Weapons
98 BFS Our Tools and Weapons
99 Our Tools and Weapons BFS Shortest Path
100 Our Tools and Weapons BFS Shortest Path Shortest Path in DAG
101 Exercise 1 You are given a strongly connected directed graph G = (V, E) with positive edge weights along withaparticularnode v 0 V.Giveanefficientalgorithmforfindingshortestpathsbetweenall pairsofnodes,withtheonerestrictionthatthesepathsmustallpassthrough v 0.
102 Exercise 2 Give an efficient algorithm that takes as input a directed acyclic graph G = (V, E), and two vertices s, t V, and outputs the number of different directed paths from s to t in G.
103 Exercise 3 Give an efficient algorithm to solve: Input Given an undirected graph G = (V, E),every edge is assigned a weight l e > 0, and given a specific edge e E. Output the length of that shortest circle that contains e.
104 Exercise 4 Given an undirected graph with n nodes and the degree of each node is 1, there must exists a circle, and the number of nodes with degree 3 is less than 2 log 2 n
105 Chapter 5. Greedy Algorithms
106 Our Tools and Weapons
107 MST Our Tools and Weapons
108 Our Tools and Weapons MST Cut Theorem
109 Chapter 6. Dynamic Programming
110 Exercise Youaregoingonalongtrip. Youstartontheroadatmilepost0. Alongthewaythereare n hotels,atmileposts a 1 < a 2 < < a n,whereeach a iismeasuredfromthestartingpoint.the onlyplacesyouareallowedtostopareatthesehotels,butyoucanchoosewhichofthehotels youstopat.youmuststopatthefinalhotel(atdistance a n),whichisyourdestination. You dideallyliketotravel200milesaday,butthismaynotbepossible(dependingonthespacing ofthehotels).ifyoutravel xmilesduringaday,thepenaltyforthatdayis (200 x) 2.Youwant toplanyourtripsoastominimizethetotalpenalty thatis,thesum,overalltraveldays,ofthe daily penalties. Give an efficient algorithm that determines the optimal sequence of hotels at which to stop.
111 Exercise 2 Given two strings x = x 1 x 2... x n and y = y 1 y 2... y m, we wish to find the length of their longest common subsequence. Show how to do this in time O(mn).
112 Chapter 7. Linear Programming
113 An Example max x + 2y 1 2x + y 3 x + 3y 5 x, y 0
Algorithms (I) Introduction. Guoqiang Li. School of Software, Shanghai Jiao Tong University
Algorithms (I) Introduction Guoqiang Li School of Software, Shanghai Jiao Tong University Instructor and Teaching Assistants Guoqiang LI Instructor and Teaching Assistants Guoqiang LI Homepage: http://basics.sjtu.edu.cn/
More informationDesign and Analysis of Algorithms (I)
Design and Analysis of Algorithms (I) Introduction Guoqiang Li School of Software, Shanghai Jiao Tong University Instructor and Teaching Assistants Guoqiang LI Instructor and Teaching Assistants Guoqiang
More informationAlgorithms IV. Dynamic Programming. Guoqiang Li. School of Software, Shanghai Jiao Tong University
Algorithms IV Dynamic Programming Guoqiang Li School of Software, Shanghai Jiao Tong University Dynamic Programming Shortest Paths in Dags, Revisited Shortest Paths in Dags, Revisited The special distinguishing
More informationCS521 \ Notes for the Final Exam
CS521 \ Notes for final exam 1 Ariel Stolerman Asymptotic Notations: CS521 \ Notes for the Final Exam Notation Definition Limit Big-O ( ) Small-o ( ) Big- ( ) Small- ( ) Big- ( ) Notes: ( ) ( ) ( ) ( )
More informationDepartment of Computer Applications. MCA 312: Design and Analysis of Algorithms. [Part I : Medium Answer Type Questions] UNIT I
MCA 312: Design and Analysis of Algorithms [Part I : Medium Answer Type Questions] UNIT I 1) What is an Algorithm? What is the need to study Algorithms? 2) Define: a) Time Efficiency b) Space Efficiency
More informationExercise 1. D-ary Tree
CSE 101: Design and Analysis of Algorithms Winter 2018 Homework 1 Solutions Due: 01/19/2018, 11.59 PM Exercise 1. D-ary Tree A d-ary tree is a rooted tree in which each node has at most d children. Show
More informationPlotting run-time graphically. Plotting run-time graphically. CS241 Algorithmics - week 1 review. Prefix Averages - Algorithm #1
CS241 - week 1 review Special classes of algorithms: logarithmic: O(log n) linear: O(n) quadratic: O(n 2 ) polynomial: O(n k ), k 1 exponential: O(a n ), a > 1 Classifying algorithms is generally done
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 informationL.J. Institute of Engineering & Technology Semester: VIII (2016)
Subject Name: Design & Analysis of Algorithm Subject Code:1810 Faculties: Mitesh Thakkar Sr. UNIT-1 Basics of Algorithms and Mathematics No 1 What is an algorithm? What do you mean by correct algorithm?
More informationIntroduction to Algorithms Third Edition
Thomas H. Cormen Charles E. Leiserson Ronald L. Rivest Clifford Stein Introduction to Algorithms Third Edition The MIT Press Cambridge, Massachusetts London, England Preface xiü I Foundations Introduction
More informationCS161 - Final Exam Computer Science Department, Stanford University August 16, 2008
CS161 - Final Exam Computer Science Department, Stanford University August 16, 2008 Name: Honor Code 1. The Honor Code is an undertaking of the students, individually and collectively: a) that they will
More informationThe Limits of Sorting Divide-and-Conquer Comparison Sorts II
The Limits of Sorting Divide-and-Conquer Comparison Sorts II CS 311 Data Structures and Algorithms Lecture Slides Monday, October 12, 2009 Glenn G. Chappell Department of Computer Science University of
More informationProblem 1. Which of the following is true of functions =100 +log and = + log? Problem 2. Which of the following is true of functions = 2 and =3?
Multiple-choice Problems: Problem 1. Which of the following is true of functions =100+log and =+log? a) = b) =Ω c) =Θ d) All of the above e) None of the above Problem 2. Which of the following is true
More informationDESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMS QUESTION BANK Module 1 OBJECTIVE: Algorithms play the central role in both the science and the practice of computing. There are compelling reasons to study algorithms.
More informationLecture 3: Graphs and flows
Chapter 3 Lecture 3: Graphs and flows Graphs: a useful combinatorial structure. Definitions: graph, directed and undirected graph, edge as ordered pair, path, cycle, connected graph, strongly connected
More informationData Structures and Algorithms
Berner Fachhochschule - Technik und Informatik Data Structures and Algorithms Topic 1: Algorithm Analysis Philipp Locher FS 2018 Outline Course and Textbook Overview Analysis of Algorithm Pseudo-Code and
More informationEND-TERM EXAMINATION
(Please Write your Exam Roll No. immediately) Exam. Roll No... END-TERM EXAMINATION Paper Code : MCA-205 DECEMBER 2006 Subject: Design and analysis of algorithm Time: 3 Hours Maximum Marks: 60 Note: Attempt
More informationR10 SET - 1. Code No: R II B. Tech I Semester, Supplementary Examinations, May
www.jwjobs.net R10 SET - 1 II B. Tech I Semester, Supplementary Examinations, May - 2012 (Com. to CSE, IT, ECC ) Time: 3 hours Max Marks: 75 *******-****** 1. a) Which of the given options provides the
More informationCS 341: Algorithms. Douglas R. Stinson. David R. Cheriton School of Computer Science University of Waterloo. February 26, 2019
CS 341: Algorithms Douglas R. Stinson David R. Cheriton School of Computer Science University of Waterloo February 26, 2019 D.R. Stinson (SCS) CS 341 February 26, 2019 1 / 296 1 Course Information 2 Introduction
More informationLeast Squares; Sequence Alignment
Least Squares; Sequence Alignment 1 Segmented Least Squares multi-way choices applying dynamic programming 2 Sequence Alignment matching similar words applying dynamic programming analysis of the algorithm
More informationCS4800: Algorithms & Data Jonathan Ullman
CS4800: Algorithms & Data Jonathan Ullman Lecture 12: Graph Search: BFS Applications, DFS Feb 20, 2018 BFS Review BFS Algorithm: Input: source node! " # =! " % = all neighbors of " # " & = all neighbors
More informationCOMP 251 Winter 2017 Online quizzes with answers
COMP 251 Winter 2017 Online quizzes with answers Open Addressing (2) Which of the following assertions are true about open address tables? A. You cannot store more records than the total number of slots
More informationTopics. Trees Vojislav Kecman. Which graphs are trees? Terminology. Terminology Trees as Models Some Tree Theorems Applications of Trees CMSC 302
Topics VCU, Department of Computer Science CMSC 302 Trees Vojislav Kecman Terminology Trees as Models Some Tree Theorems Applications of Trees Binary Search Tree Decision Tree Tree Traversal Spanning Trees
More informationIntroduction to Algorithms
Introduction to Algorithms 6.046J/18.401J LECTURE 12 Dynamic programming Longest common subsequence Optimal substructure Overlapping subproblems Prof. Charles E. Leiserson Dynamic programming Design technique,
More informationECE250: Algorithms and Data Structures Final Review Course
ECE250: Algorithms and Data Structures Final Review Course Ladan Tahvildari, PEng, SMIEEE Professor Software Technologies Applied Research (STAR) Group Dept. of Elect. & Comp. Eng. University of Waterloo
More informationU.C. Berkeley CS170 : Algorithms, Fall 2013 Midterm 1 Professor: Satish Rao October 10, Midterm 1 Solutions
U.C. Berkeley CS170 : Algorithms, Fall 2013 Midterm 1 Professor: Satish Rao October 10, 2013 Midterm 1 Solutions 1 True/False 1. The Mayan base 20 system produces representations of size that is asymptotically
More informationCISC 320 Midterm Exam
Name: CISC 320 Midterm Exam Wednesday, Mar 25, 2015 There are 19 questions. The first 15 questions count 4 points each. For the others, points are individually shown. The total is 100 points. Multiple
More informationSankalchand Patel College of Engineering - Visnagar Department of Computer Engineering and Information Technology. Assignment
Class: V - CE Sankalchand Patel College of Engineering - Visnagar Department of Computer Engineering and Information Technology Sub: Design and Analysis of Algorithms Analysis of Algorithm: Assignment
More informationComputer Algorithms. Introduction to Algorithm
Computer Algorithms Introduction to Algorithm CISC 4080 Yanjun Li 1 What is Algorithm? An Algorithm is a sequence of well-defined computational steps that transform the input into the output. These steps
More informationAlgorithm Analysis. (Algorithm Analysis ) Data Structures and Programming Spring / 48
Algorithm Analysis (Algorithm Analysis ) Data Structures and Programming Spring 2018 1 / 48 What is an Algorithm? An algorithm is a clearly specified set of instructions to be followed to solve a problem
More informationDesign and Analysis of Algorithms - - Assessment
X Courses» Design and Analysis of Algorithms Week 1 Quiz 1) In the code fragment below, start and end are integer values and prime(x) is a function that returns true if x is a prime number and false otherwise.
More informationFINAL EXAM SOLUTIONS
COMP/MATH 3804 Design and Analysis of Algorithms I Fall 2015 FINAL EXAM SOLUTIONS Question 1 (12%). Modify Euclid s algorithm as follows. function Newclid(a,b) if a
More informationFinal. Name: TA: Section Time: Course Login: Person on Left: Person on Right: U.C. Berkeley CS170 : Algorithms, Fall 2013
U.C. Berkeley CS170 : Algorithms, Fall 2013 Final Professor: Satish Rao December 16, 2013 Name: Final TA: Section Time: Course Login: Person on Left: Person on Right: Answer all questions. Read them carefully
More informationOutline. Graphs. Divide and Conquer.
GRAPHS COMP 321 McGill University These slides are mainly compiled from the following resources. - Professor Jaehyun Park slides CS 97SI - Top-coder tutorials. - Programming Challenges books. Outline Graphs.
More informationMultiple-choice (35 pt.)
CS 161 Practice Midterm I Summer 2018 Released: 7/21/18 Multiple-choice (35 pt.) 1. (2 pt.) Which of the following asymptotic bounds describe the function f(n) = n 3? The bounds do not necessarily need
More informationCS1800 Discrete Structures Fall 2016 Profs. Aslam, Gold, Ossowski, Pavlu, & Sprague December 16, CS1800 Discrete Structures Final
CS1800 Discrete Structures Fall 2016 Profs. Aslam, Gold, Ossowski, Pavlu, & Sprague December 16, 2016 Instructions: CS1800 Discrete Structures Final 1. The exam is closed book and closed notes. You may
More informationAlgorithms and Data Structures, or
Algorithms and Data Structures, or... Classical Algorithms of the 50s, 60s and 70s Mary Cryan A&DS Lecture 1 1 Mary Cryan Our focus Emphasis is Algorithms ( Data Structures less important). Most of the
More informationCSE Winter 2015 Quiz 1 Solutions
CSE 101 - Winter 2015 Quiz 1 Solutions January 12, 2015 1. What is the maximum possible number of vertices in a binary tree of height h? The height of a binary tree is the length of the longest path from
More informationUNIT 1 BASICS OF AN ALGORITHM
UNIT 1 BASICS OF AN ALGORITHM Basics of an Algorithm Structure Page Nos. 1.0 Introduction 5 1.1 Objectives 6 1.2. Analysis and Complexity of Algorithms 6 1.3 Basic Technique for Design of Efficient Algorithms
More informationCMPSCI 311: Introduction to Algorithms Practice Final Exam
CMPSCI 311: Introduction to Algorithms Practice Final Exam Name: ID: Instructions: Answer the questions directly on the exam pages. Show all your work for each question. Providing more detail including
More informationU.C. Berkeley CS170 : Algorithms Midterm 1 Lecturers: Alessandro Chiesa and Satish Rao September 18, Midterm 1
U.C. Berkeley CS170 : Algorithms Lecturers: Alessandro Chiesa and Satish Rao September 18, 2018 1 Connectivity in Graphs No justification is required on this problem. A B C D E F G H I J (a) (2 points)
More informationReference Sheet for CO142.2 Discrete Mathematics II
Reference Sheet for CO14. Discrete Mathematics II Spring 017 1 Graphs Defintions 1. Graph: set of N nodes and A arcs such that each a A is associated with an unordered pair of nodes.. Simple graph: no
More informationContents. CS 124 Final Exam Practice Problem 5/6/17. 1 Format and Logistics 2
CS 124 Final Exam Practice Problem 5/6/17 Contents 1 Format and Logistics 2 2 Topics Covered 2 2.1 Math Fundamentals.................................... 2 2.2 Graph Search........................................
More informationModule 2: Classical Algorithm Design Techniques
Module 2: Classical Algorithm Design Techniques Dr. Natarajan Meghanathan Associate Professor of Computer Science Jackson State University Jackson, MS 39217 E-mail: natarajan.meghanathan@jsums.edu Module
More informationCS60020: Foundations of Algorithm Design and Machine Learning. Sourangshu Bhattacharya
CS60020: Foundations of Algorithm Design and Machine Learning Sourangshu Bhattacharya Dynamic programming Design technique, like divide-and-conquer. Example: Longest Common Subsequence (LCS) Given two
More informationNotes for Lecture 24
U.C. Berkeley CS170: Intro to CS Theory Handout N24 Professor Luca Trevisan December 4, 2001 Notes for Lecture 24 1 Some NP-complete Numerical Problems 1.1 Subset Sum The Subset Sum problem is defined
More informationGreedy algorithms. Given a problem, how do we design an algorithm that solves the problem? There are several strategies:
Greedy algorithms Input Algorithm Goal? Given a problem, how do we design an algorithm that solves the problem? There are several strategies: 1. Try to modify an existing algorithm. 2. Construct an algorithm
More informationThomas H. Cormen Charles E. Leiserson Ronald L. Rivest. Introduction to Algorithms
Thomas H. Cormen Charles E. Leiserson Ronald L. Rivest Introduction to Algorithms Preface xiii 1 Introduction 1 1.1 Algorithms 1 1.2 Analyzing algorithms 6 1.3 Designing algorithms 1 1 1.4 Summary 1 6
More informationSolutions to relevant spring 2000 exam problems
Problem 2, exam Here s Prim s algorithm, modified slightly to use C syntax. MSTPrim (G, w, r): Q = V[G]; for (each u Q) { key[u] = ; key[r] = 0; π[r] = 0; while (Q not empty) { u = ExtractMin (Q); for
More informationStudent number: Datenstrukturen & Algorithmen page 1
Student number: Datenstrukturen & Algorithmen page 1 Problem 1. / 15 P Please note: 1) In this problem, you have to provide solutions only. You can write them right on this sheet. 2) If you use algorithms
More informationDATA STRUCTURES AND ALGORITHMS
DATA STRUCTURES AND ALGORITHMS For COMPUTER SCIENCE DATA STRUCTURES &. ALGORITHMS SYLLABUS Programming and Data Structures: Programming in C. Recursion. Arrays, stacks, queues, linked lists, trees, binary
More informationCS781 Lecture 2 January 13, Graph Traversals, Search, and Ordering
CS781 Lecture 2 January 13, 2010 Graph Traversals, Search, and Ordering Review of Lecture 1 Notions of Algorithm Scalability Worst-Case and Average-Case Analysis Asymptotic Growth Rates: Big-Oh Prototypical
More informationReview for Midterm Exam
Review for Midterm Exam 1 Policies and Overview midterm exam policies overview of problems, algorithms, data structures overview of discrete mathematics 2 Sample Questions on the cost functions of algorithms
More informationIN101: Algorithmic techniques Vladimir-Alexandru Paun ENSTA ParisTech
IN101: Algorithmic techniques Vladimir-Alexandru Paun ENSTA ParisTech License CC BY-NC-SA 2.0 http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Outline Previously on IN101 Python s anatomy Functions,
More informationDynamic Programming Homework Problems
CS 1510 Dynamic Programming Homework Problems 1. Consider the recurrence relation T(0) = T(1) = 2 and for n > 1 n 1 T(n) = T(i)T(i 1) i=1 We consider the problem of computing T(n) from n. (a) Show that
More informationComplexity, Induction, and Recurrence Relations. CSE 373 Help Session 4/7/2016
Complexity, Induction, and Recurrence Relations CSE 373 Help Session 4/7/2016 Big-O Definition Definition: g(n) is in O( f(n) ) if there exist positive constants c and n0 such that g(n) c f(n) for all
More informationData Structures and Algorithms CSE 465
Data Structures and Algorithms CSE 465 LECTURE 4 More Divide and Conquer Binary Search Exponentiation Multiplication Sofya Raskhodnikova and Adam Smith Review questions How long does Merge Sort take on
More informationCSE 421 Applications of DFS(?) Topological sort
CSE 421 Applications of DFS(?) Topological sort Yin Tat Lee 1 Precedence Constraints In a directed graph, an edge (i, j) means task i must occur before task j. Applications Course prerequisite: course
More informationAlgorithms and Data Structures
Algorithm Analysis Page 1 - Algorithm Analysis Dr. Fall 2008 Algorithm Analysis Page 2 Outline Textbook Overview Analysis of Algorithm Pseudo-Code and Primitive Operations Growth Rate and Big-Oh Notation
More informationData Structures and Algorithms CMPSC 465
Data Structures and Algorithms CMPSC 465 LECTURES 7-8 More Divide and Conquer Multiplication Adam Smith S. Raskhodnikova and A. Smith; based on slides by E. Demaine and C. Leiserson John McCarthy (1927
More informationGreedy algorithms is another useful way for solving optimization problems.
Greedy Algorithms Greedy algorithms is another useful way for solving optimization problems. Optimization Problems For the given input, we are seeking solutions that must satisfy certain conditions. These
More information17/05/2018. Outline. Outline. Divide and Conquer. Control Abstraction for Divide &Conquer. Outline. Module 2: Divide and Conquer
Module 2: Divide and Conquer Divide and Conquer Control Abstraction for Divide &Conquer 1 Recurrence equation for Divide and Conquer: If the size of problem p is n and the sizes of the k sub problems are
More informationAlgorithm Design Techniques part I
Algorithm Design Techniques part I Divide-and-Conquer. Dynamic Programming DSA - lecture 8 - T.U.Cluj-Napoca - M. Joldos 1 Some Algorithm Design Techniques Top-Down Algorithms: Divide-and-Conquer Bottom-Up
More informationDiscrete Mathematics SECOND EDITION OXFORD UNIVERSITY PRESS. Norman L. Biggs. Professor of Mathematics London School of Economics University of London
Discrete Mathematics SECOND EDITION Norman L. Biggs Professor of Mathematics London School of Economics University of London OXFORD UNIVERSITY PRESS Contents PART I FOUNDATIONS Statements and proofs. 1
More informationCOL351: Analysis and Design of Algorithms (CSE, IITD, Semester-I ) Name: Entry number:
Name: Entry number: There are 6 questions for a total of 75 points. 1. Consider functions f(n) = 10n2 n + 3 n and g(n) = n3 n. Answer the following: (a) ( 1 / 2 point) State true or false: f(n) is O(g(n)).
More informationExam Sample Questions CS3212: Algorithms and Data Structures
Exam Sample Questions CS31: Algorithms and Data Structures NOTE: the actual exam will contain around 0-5 questions. 1. Consider a LinkedList that has a get(int i) method to return the i-th element in the
More informationCMPS 2200 Fall Dynamic Programming. Carola Wenk. Slides courtesy of Charles Leiserson with changes and additions by Carola Wenk
CMPS 00 Fall 04 Dynamic Programming Carola Wenk Slides courtesy of Charles Leiserson with changes and additions by Carola Wenk 9/30/4 CMPS 00 Intro. to Algorithms Dynamic programming Algorithm design technique
More informationCS 350 Final Algorithms and Complexity. It is recommended that you read through the exam before you begin. Answer all questions in the space provided.
It is recommended that you read through the exam before you begin. Answer all questions in the space provided. Name: Answer whether the following statements are true or false and briefly explain your answer
More informationINDIAN STATISTICAL INSTITUTE
INDIAN STATISTICAL INSTITUTE Mid Semestral Examination M. Tech (CS) - I Year, 2016-2017 (Semester - II) Design and Analysis of Algorithms Date : 21.02.2017 Maximum Marks : 60 Duration : 3.0 Hours Note:
More informationGRAPHS Lecture 17 CS2110 Spring 2014
GRAPHS Lecture 17 CS2110 Spring 2014 These are not Graphs 2...not the kind we mean, anyway These are Graphs 3 K 5 K 3,3 = Applications of Graphs 4 Communication networks The internet is a huge graph Routing
More information4.1.2 Merge Sort Sorting Lower Bound Counting Sort Sorting in Practice Solving Problems by Sorting...
Contents 1 Introduction... 1 1.1 What is Competitive Programming?... 1 1.1.1 Programming Contests.... 2 1.1.2 Tips for Practicing.... 3 1.2 About This Book... 3 1.3 CSES Problem Set... 5 1.4 Other Resources...
More informationCS583 Lecture 01. Jana Kosecka. some materials here are based on Profs. E. Demaine, D. Luebke A.Shehu, J-M. Lien and Prof. Wang s past lecture notes
CS583 Lecture 01 Jana Kosecka some materials here are based on Profs. E. Demaine, D. Luebke A.Shehu, J-M. Lien and Prof. Wang s past lecture notes Course Info course webpage: - from the syllabus on http://cs.gmu.edu/
More informationFundamental Graph Algorithms Part Four
Fundamental Graph Algorithms Part Four Announcements Problem Set One due right now. Due Friday at 2:15PM using one late period. Problem Set Two out, due next Friday, July 12 at 2:15PM. Play around with
More informationCS 373: Combinatorial Algorithms, Spring 1999
CS 373: Combinatorial Algorithms, Spring 1999 Final Exam (May 7, 1999) Name: Net ID: Alias: This is a closed-book, closed-notes exam! If you brought anything with you besides writing instruments and your
More informationReview of course COMP-251B winter 2010
Review of course COMP-251B winter 2010 Lecture 1. Book Section 15.2 : Chained matrix product Matrix product is associative Computing all possible ways of parenthesizing Recursive solution Worst-case running-time
More informationLecture 13. Reading: Weiss, Ch. 9, Ch 8 CSE 100, UCSD: LEC 13. Page 1 of 29
Lecture 13 Connectedness in graphs Spanning trees in graphs Finding a minimal spanning tree Time costs of graph problems and NP-completeness Finding a minimal spanning tree: Prim s and Kruskal s algorithms
More informationWe will give examples for each of the following commonly used algorithm design techniques:
Review This set of notes provides a quick review about what should have been learned in the prerequisite courses. The review is helpful to those who have come from a different background; or to those who
More informationCS2 Algorithms and Data Structures Note 10. Depth-First Search and Topological Sorting
CS2 Algorithms and Data Structures Note 10 Depth-First Search and Topological Sorting In this lecture, we will analyse the running time of DFS and discuss a few applications. 10.1 A recursive implementation
More informationAlgorithms (V) Path in Graphs. Guoqiang Li. School of Software, Shanghai Jiao Tong University
Algorithms (V) Path in Graphs Guoqiang Li School of Software, Shanghai Jiao Tong University Review of the Previous Lecture Exploring Graphs EXPLORE(G, v) input : G = (V, E) is a graph; v V output: visited(u)
More informationCS 310 Advanced Data Structures and Algorithms
CS 0 Advanced Data Structures and Algorithms Weighted Graphs July 0, 07 Tong Wang UMass Boston CS 0 July 0, 07 / Weighted Graphs Each edge has a weight (cost) Edge-weighted graphs Mostly we consider only
More informationChapter 6. Dynamic Programming
Chapter 6 Dynamic Programming CS 573: Algorithms, Fall 203 September 2, 203 6. Maximum Weighted Independent Set in Trees 6..0. Maximum Weight Independent Set Problem Input Graph G = (V, E) and weights
More informationGreedy Algorithms 1 {K(S) K(S) C} For large values of d, brute force search is not feasible because there are 2 d {1,..., d}.
Greedy Algorithms 1 Simple Knapsack Problem Greedy Algorithms form an important class of algorithmic techniques. We illustrate the idea by applying it to a simplified version of the Knapsack Problem. Informally,
More informationIV/IV B.Tech (Regular) DEGREE EXAMINATION. Design and Analysis of Algorithms (CS/IT 414) Scheme of Evaluation
IV/IV B.Tech (Regular) DEGREE EXAMINATION Design and Analysis of Algorithms (CS/IT 414) Scheme of Evaluation Maximum: 60 Marks 1. Write briefly about the following 1*12= 12 Marks a) Give the characteristics
More informationGraphs and Network Flows ISE 411. Lecture 7. Dr. Ted Ralphs
Graphs and Network Flows ISE 411 Lecture 7 Dr. Ted Ralphs ISE 411 Lecture 7 1 References for Today s Lecture Required reading Chapter 20 References AMO Chapter 13 CLRS Chapter 23 ISE 411 Lecture 7 2 Minimum
More informationIntroduction to Automata Theory. BİL405 - Automata Theory and Formal Languages 1
Introduction to Automata Theory BİL405 - Automata Theory and Formal Languages 1 Automata, Computability and Complexity Automata, Computability and Complexity are linked by the question: What are the fundamental
More informationChapter 1 Programming: A General Overview
Chapter 1 Programming: A General Overview 2 Introduction This class is an introduction to the design, implementation, and analysis of algorithms. Examples: sorting large amounts of data organizing information
More informationAlgorithm Design and Analysis
Algorithm Design and Analysis LECTURE 4 Graphs Definitions Traversals Adam Smith 9/8/10 Exercise How can you simulate an array with two unbounded stacks and a small amount of memory? (Hint: think of a
More informationLecture 1. Introduction
Lecture 1 Introduction 1 Lecture Contents 1. What is an algorithm? 2. Fundamentals of Algorithmic Problem Solving 3. Important Problem Types 4. Fundamental Data Structures 2 1. What is an Algorithm? Algorithm
More informationDr. Amotz Bar-Noy s Compendium of Algorithms Problems. Problems, Hints, and Solutions
Dr. Amotz Bar-Noy s Compendium of Algorithms Problems Problems, Hints, and Solutions Chapter 1 Searching and Sorting Problems 1 1.1 Array with One Missing 1.1.1 Problem Let A = A[1],..., A[n] be an array
More information[Ch 6] Set Theory. 1. Basic Concepts and Definitions. 400 lecture note #4. 1) Basics
400 lecture note #4 [Ch 6] Set Theory 1. Basic Concepts and Definitions 1) Basics Element: ; A is a set consisting of elements x which is in a/another set S such that P(x) is true. Empty set: notated {
More informationAnnouncements. CSEP 521 Applied Algorithms. Announcements. Polynomial time efficiency. Definitions of efficiency 1/14/2013
Announcements CSEP 51 Applied Algorithms Richard Anderson Winter 013 Lecture Reading Chapter.1,. Chapter 3 Chapter Homework Guidelines Prove that your algorithm works A proof is a convincing argument Give
More informationCopyright 2000, Kevin Wayne 1
Chapter 3 - Graphs Undirected Graphs Undirected graph. G = (V, E) V = nodes. E = edges between pairs of nodes. Captures pairwise relationship between objects. Graph size parameters: n = V, m = E. Directed
More informationINDEX. Cambridge University Press How to Think About Algorithms Jeff Edmonds Index More information
INDEX 439 abstract data type (ADT), 1, 43 exercise solutions, 414 functions vs., 43 merging with queue, 56 specifications/implementations, 44 dictionary, 47 graphs, 47 link list implementation, 51 list,
More informationCpt S 223 Course Overview. Cpt S 223, Fall 2007 Copyright: Washington State University
Cpt S 223 Course Overview 1 Course Goals Learn about new/advanced data structures Be able to make design choices on the suitable data structure for different application/problem needs Analyze (objectively)
More information! Addition! Multiplication! Bigger Example - RSA cryptography
! Addition! Multiplication! Bigger Example - RSA cryptography Modular Arithmetic Modular Exponentiation Primality Testing (Fermat s little theorem) Probabilistic algorithm Euclid s Algorithm for gcd (greatest
More informationProblem set 2. Problem 1. Problem 2. Problem 3. CS261, Winter Instructor: Ashish Goel.
CS261, Winter 2017. Instructor: Ashish Goel. Problem set 2 Electronic submission to Gradescope due 11:59pm Thursday 2/16. Form a group of 2-3 students that is, submit one homework with all of your names.
More informationWe augment RBTs to support operations on dynamic sets of intervals A closed interval is an ordered pair of real
14.3 Interval trees We augment RBTs to support operations on dynamic sets of intervals A closed interval is an ordered pair of real numbers ], with Interval ]represents the set Open and half-open intervals
More informationCS/ENGRD 2110 Object-Oriented Programming and Data Structures Spring 2012 Thorsten Joachims. Lecture 25: Review and Open Problems
CS/ENGRD 2110 Object-Oriented Programming and Data Structures Spring 2012 Thorsten Joachims Lecture 25: Review and Open Problems Course Overview Programming Concepts Object-Oriented Programming Interfaces
More informationCMPSCI611: The SUBSET-SUM Problem Lecture 18
CMPSCI611: The SUBSET-SUM Problem Lecture 18 We begin today with the problem we didn t get to at the end of last lecture the SUBSET-SUM problem, which we also saw back in Lecture 8. The input to SUBSET-
More informationAlgorithms Dr. Haim Levkowitz
91.503 Algorithms Dr. Haim Levkowitz Fall 2007 Lecture 4 Tuesday, 25 Sep 2007 Design Patterns for Optimization Problems Greedy Algorithms 1 Greedy Algorithms 2 What is Greedy Algorithm? Similar to dynamic
More information