Master Theorem, Introduction to Graphs
|
|
- Aldous Leonard
- 5 years ago
- Views:
Transcription
1 Master Theorem, Introduction to Graphs CSE21 Winter 2017, Day 10 (B00), Day 6-7 (A00) February 1,
2 Divide & Conquer: General Strategy Divide the problem of size n into a subproblems of size n/b. Recursively solve each subproblem. Conquer the problem of size n by combining solutions of subproblems. Rosen 5.4 has more examples
3 Divide & Conquer: General Strategy Divide the problem of size n into a subproblems of size n/b. Recursively solve each subproblem. Conquer the problem of size n by combining solutions of subproblems. T(n) = time to solve problem of size n T(1)=constant g(n) = time to do the conquer step to solve problem of size n Recurrence for T(n)? A. T(n) = a*t(n/b) + a*g(n) C. T(n) = a*t(n/b) + g(n) B. T(n) = T(a*n/b) + g(n) D. T(n) = g(n)*a*t(n/b)
4 Solving Divide and Conquer Recurrence Relations Divide and conquer algorithms have recurrences of the form T(n) = a*t(n/b) + g(n). If g(n) is a polynomial, there is a nice theorem called the Master Theorem that allows us to quickly estimate the time complexity of many divide and conquer algorithms. T(n) = time to solve problem of size n T(1)=constant g(n) = time to do the conquer step to solve problem of size n
5 Master Theorem
6 Master Theorem a log b n Size 1
7 Master Theorem for Mergesort If T MS (n) is runtime of MergeSort on list of size n, T MS (0) = c 0 T MS (1) = c' T MS (n) = 2T MS (n/2) + cn where c 0, c, c' are some constants a=2, b=2, d=1 so a=b d O(n 1 log n)
8 Master Theorem for Mergesort If T MS (n) is runtime of MergeSort on list of size n, T MS (0) = c 0 T MS (1) = c' T MS (n) = 2T MS (n/2) + cn where c 0, c, c' are some constants Not much work! a=2, b=2, d=1 so a=b d O(n 1 log n)
9 Master Theorem for Binary Search Do one comparison to decide which half to search in. Then repeat on a list of half the size. T(0) = c 0 T(1) = c' T(n) = T(n/2) + c where c 0, c, c' are some constants a=1, b=2, d=0 so a=b d O(n 0 log n) = O(log n)
10 Divide & Conquer Wins Big Mergesort Dividing into two subproblems each with half the size is a big win over other sorting algorithms. Binary Search Dividing into one subproblem with half the size is a big win over linear search. Will this work in other contexts?
11 Multiplication: WHAT Given two n-digit (or bit) integers a = a n-1 a 1 a 0 and b = b n-1 b 1 b 0 return the decimal (or binary) representation of their product. Rosen p x
12 Multiplication: HOW Given two n-digit (or bit) integers a = a n-1 a 1 a 0 and b = b n-1 b 1 b 0 return the decimal (or binary) representation of their product. Rosen p x Compute partial products (using single digit multiplications), shift, then add. How many operations?
13 Multiplication: HOW Given two n-digit (or bit) integers a = a n-1 a 1 a 0 and b = b n-1 b 1 b 0 return the decimal (or binary) representation of their product. Rosen p x Compute partial products (using single digit multiplications), shift, then add. How many operations? O(n 2 )
14 Multiplication: HOW Divide and conquer? Divide n-digit numbers into two n/2-digit numbers. If a = and b = , we can write To multiply: a = (1234) * (5678) b = (2468) * (1357) ((1234) * (5678))((2468) * (1357))= (1234)(2468) * (1234)(1357) * (2468)(5678) * (1357)(5678)
15 One 8-digit multiplication Multiplication: WHEN ( )( )=((1234) * (5678))((2468) * (1357))= (1234)(2468) * (1234)(1357) * (2468)(5678) * (1357)(5678) Four 4-digit multiplications (plus some shifts, sums)
16 One 8-digit multiplication Multiplication: WHEN ( )( )=((1234) * (5678))((2468) * (1357))= (1234)(2468) * (1234)(1357) * (2468)(5678) * (1357)(5678) Four 4-digit multiplications (plus some shifts, sums) A. a = 4, b=4, d=0 C. a=4, b=2, d=1 B. a = 4, b=4, d=1 D. a=4, b=2, d=0
17 Multiplication: WHEN a=4, b=2, d=1 so a>b d O(n log_2(4) ) = O(n 2 )
18 Multiplication: WHEN a=4, b=2, d=1 so a>b d O(n log_2(4) ) = O(n 2 ) A. This is good news! B. This is bad news! C. I m not sure.
19 Enter Anatoly Karatsuba... Rosen p. 528 Insight: replace one (of the 4) multiplications by (linear time) subtraction
20 Karatsuba Multiplication: HOW Rosen p. 528 ( )( )=((1234) * (5678))((2468) * (1357))= (1234)(2468) * (1234)(1357) * (2468)(5678) * (1357)(5678) (1234)(2468) * ( ) + [(1234) - (5678)][ (1357)-(2468) ] * (1357)(5678) * ( ) Insight: replace one (of the 4) multiplications by (linear time) subtraction
21
22 Karatsuba Multiplication: WHEN Instead of T(n) = 4 T(n/2) + cn T K (n) = 3 T K (n/2) + pn with c a constant, now we have with p a constant. Rosen p. 528 a=3, b=2, d=1 so a>b d O(n log_2(3) ) = O(n )
23 Karatsuba Multiplication: WHEN Rosen p. 528 n 1.58 is better than n 2 Progress since then This is good news! 1963: Toom and Cook develop series of algorithms that are time O(n 1+ ). 2007: Furer uses number theory to achieve the best known time for multiplication. 2016: Still open whether there is a linear time algorithm for multiplication.
24 What is a graph? A (directed) graph G is A nonempty set of vertices V, also called nodes and A set of edges E, each pointing from one (tail) vertex to another (head) vertex. (A directed edge is denoted with an arrow ) head tail
25 Variants of graphs Undirected graph: no arrows on edges. Rosen p. 644 If there s an edge between v and w then there's an edge between w and v. (More precisely: an edge e vw connects the unordered pair of vertices {v,w}.) Multigraph: undirected graph that may have multiple edges between a pair of nodes. Such edges are sometimes called parallel edges. Simple graph: undirected graph with no self-loops (edge from v to v) and no parallel edges. Mixed graph: directed graph that may have multiple edges between a pair of nodes as well as self-loops.
26 Graphs are everywhere
27 Graphs are everywhere The internet graph
28 Map coloring Graphs are everywhere
29 Path planning for robots Graphs are everywhere
30 Graphs are everywhere
31 Are these the same graph? A. Yes: the set of vertices is the same. B. Yes: we can rearrange the vertices so that the pictures look the same. C. No: the pictures are different. D. No: the left graph has a crossing and the right one doesn't. E. None of the above.
32 Representing directed graphs Diagrams with vertices and edges How many vertices? For each ordered pair of vertices (v,w) how many edges go from v to w?
33 Representing directed graphs Diagrams with vertices and edges How many vertices? n For each ordered pair of vertices (v,w) how many edges go from v to w? How many ordered pairs of vertices are there? A. n B. 2n C. n 2 D. n(n-1)/2 E. 2 n
34 Representing directed graphs Diagrams with vertices and edges How many vertices? n For each ordered pair of vertices (v,w) how many edges go from v to w? Need to store n 2 ints
35 Representing directed graphs Adjacency matrix n x n matrix: entry in row i and column j is the number of edges from vertex i to vertex j Rosen p. 669
36 Representing directed graphs Adjacency matrix n x n matrix: entry in row i and column j is the number of edges from vertex i to vertex j What can you say about the adjacency matrix of a loopless graph? A. It has all zeros. B. All the elements below the diagonal are 1. C. All the elements are even. D. All the elements on the diagonal are 0. E. None of the above. Rosen p. 669
37 Representing directed graphs Adjacency matrix n x n matrix: entry in row i and column j is the number of edges from vertex i to vertex j What can you say about the adjacency matrix of a graph with no parallel edges? A. It has no zeros. B. It is symmetric. C. All the entries above the diagonal are 0. D. All entries are either 0 or 1. E. None of the above. Rosen p. 669
38 Representing directed graphs Adjacency matrix n x n matrix: entry in row i and column j is the number of edges from vertex i to vertex j What can you say about the adjacency matrix of an undirected graph? A. It has no zeros. B. It is symmetric. C. All the entries above the diagonal are 0. D. All entries are either 0 or 1. E. None of the above. Rosen p. 669
39 Representing undirected graphs Simple undirected graph: * Only need to store the adjacency matrix above diagonal. What's the maximum number of edges a simple undirected graph with n vertices can have? A. n 2 B. n 2 /2 C. n(n-1)/2 D. n(n+1)/2 E. n
40 Efficiency? When is an adjacency matrix an inefficient way to store a graph? When there is a high density of edges compared to number of vertices??? When there is a low density of edges compared to number of vertices???
41 Representing directed graphs Adjacency list (list of lists): for each vertex v, associate list of all neighbors of v. Rosen p. 668
42 Neighbors The neighbors of a vertex v are all the vertices w for which there is an edge whose endpoints are v,w. If two vertices are neighbors then they are called adjacent to one another. Rosen p. 651
43 Degree The degree of a vertex in an undirected graph is the total number of edges incident with it, except that a loop contributes twice. What's the maximum degree of a vertex in this graph? A. 0. B. 1 C. 2 D. 3 E. None of the above. Rosen p. 652
44 What's the degree of vertex 5? A. 5 B. 3 C. 2 D. 1 E. None of the above. Degree
45 What's the degree of vertex 0? A. 5 B. 3 C. 2 D. 1 E. None of the above. Degree
46 Handshakes If there are n people in a room, and each shakes hands with d people, how many handshakes take place? A. n B. d C. nd D. (nd)/2 E. None of the above.
47 Handshakes If there are n people in a room, and each shakes hands with d people, how many handshakes take place? A. n B. d C. nd D. (nd)/2 E. None of the above. Don't double-count each handshake!
48 Handshakes "in" graphs If a simple graph has n vertices and each vertex has degree d, how many edges are there? 2 E = n*d
49 Handshakes in graphs If any graph has n vertices, then 2 E = sum of degrees of all vertices
50 Handshakes "in" graphs If any graph has n vertices, then 2 E = sum of degrees of all vertices What can we conclude? A. Every degree in the graph is even. B. The number of edges is even. C. The number of vertices with odd degree is even. D. The number self loops is even. E. None of the above.
51 Puzzles
52 Tartaglia's Pouring Problem Large cup: contains 8 ounces, can hold more. Medium cup: is empty, has 5 ounce capacity. Small cup: is empty, has 3 ounce capacity You can pour from one cup to another until the first is empty or the second is full. Can we divide the coffee in half? How? A. Yes B. No
53 Tartaglia's Pouring Problem Large cup: contains 8 ounces, can hold more. Medium cup: is empty, has 5 ounce capacity. Small cup: is empty, has 3 ounce capacity You can pour from one cup to another until the first is empty or the second is full. Can we divide the coffee in half? How? Hint: configurations (l,m,s) code # ounces in each cup A. Yes B. No
54 Tartaglia's Pouring Problem
55 Tartaglia's Pouring Problem Rephrasing the problem: Looking for path from (8,0,0) to (4,4,0)
56 Path Sequence (v 0, e 1, v 1, e 2, v 2,, e k, v k ) describes a route through the graph from to start vertex v 0 end vertex v k
57 Tartaglia's Pouring Problem Rephrasing the problem: (1) Is there a path from (8,0,0) to (4,4,0)? (2) If so, what's the best path? "Best" means "shortest length"
58 What's the shortest length of a path from (8,0,0) to (4,4,0)? A. 7 B. 8 C. 14 D. 16 E. None of the above. Tartaglia's Pouring Problem
59 Algorithmic questions related to paths Reachability: // decision Does there exist a path from vertex v to vertex w? Path: // construction Find a path from vertex v to vertex w. Distance: // optimization What s the length of the shortest path from vertex v to vertex w?
60 Seating Chart to be posted on Website Good luck! Exam Announcements Exam on Monday Covers through Day 9 (no graphs) Bring student ID. One handwritten note sheet (8.5 x 11, both sides). Look up seat assignment. No calculators. No blue books. Review Session covering the Practice Midterm Saturday 1-3pm Sunday 12-2pm (selected by Piazza vote)
Introduction to Graphs
Introduction to Graphs CSE21 Winter 2017, Day 10 (B00), Day 6-7 (A00) February 1, 2017 http://vlsicad.ucsd.edu/courses/cse21-w17 What is a graph? A (directed) graph G is A nonempty set of vertices V, also
More informationIntroduction to Graphs
Introduction to Graphs Russell Impagliazzo and Miles Jones Thanks to Janine Tiefenbruck http://cseweb.ucsd.edu/classes/sp16/cse21-bd/ April 18, 2016 1 What is a graph? A (directed) graph G is A nonempty
More informationGraphs and Puzzles. Eulerian and Hamiltonian Tours.
Graphs and Puzzles. Eulerian and Hamiltonian Tours. CSE21 Winter 2017, Day 11 (B00), Day 7 (A00) February 3, 2017 http://vlsicad.ucsd.edu/courses/cse21-w17 Exam Announcements Seating Chart on Website Good
More informationUCSD CSE 21, Spring 2014 [Section B00] Mathematics for Algorithm and System Analysis
UCSD CSE 21, Spring 2014 [Section B00] Mathematics for Algorithm and System Analysis Lecture 16 Class URL: http://vlsicad.ucsd.edu/courses/cse21-s14/ Lecture 16 Notes Goals for this week Graph basics Types
More informationNotes slides from before lecture. CSE 21, Winter 2017, Section A00. Lecture 10 Notes. Class URL:
Notes slides from before lecture CSE 21, Winter 2017, Section A00 Lecture 10 Notes Class URL: http://vlsicad.ucsd.edu/courses/cse21-w17/ Notes slides from before lecture Notes February 13 (1) HW5 is due
More informationEulerian Tours and Fleury s Algorithm
Eulerian Tours and Fleury s Algorithm CSE21 Winter 2017, Day 12 (B00), Day 8 (A00) February 8, 2017 http://vlsicad.ucsd.edu/courses/cse21-w17 Vocabulary Path (or walk):describes a route from one vertex
More informationEulerian Tours and Fleury s Algorithm
Eulerian Tours and Fleury s Algorithm CSE21 Winter 2017, Day 12 (B00), Day 8 (A00) February 8, 2017 http://vlsicad.ucsd.edu/courses/cse21-w17 Vocabulary Path (or walk): describes a route from one vertex
More informationEncoding/Decoding, Counting graphs
Encoding/Decoding, Counting graphs Russell Impagliazzo and Miles Jones Thanks to Janine Tiefenbruck http://cseweb.ucsd.edu/classes/sp16/cse21-bd/ May 13, 2016 11-avoiding binary strings Let s consider
More informationNotes slides from before lecture. CSE 21, Winter 2017, Section A00. Lecture 9 Notes. Class URL:
Notes slides from before lecture CSE 21, Winter 2017, Section A00 Lecture 9 Notes Class URL: http://vlsicad.ucsd.edu/courses/cse21-w17/ Notes slides from before lecture Notes February 8 (1) HW4 is due
More informationCSE 20 DISCRETE MATH WINTER
CSE 20 DISCRETE MATH WINTER 2016 http://cseweb.ucsd.edu/classes/wi16/cse20-ab/ Today's learning goals Explain the steps in a proof by (strong) mathematical induction Use (strong) mathematical induction
More informationDIVIDE & CONQUER. Problem of size n. Solution to sub problem 1
DIVIDE & CONQUER Definition: Divide & conquer is a general algorithm design strategy with a general plan as follows: 1. DIVIDE: A problem s instance is divided into several smaller instances of the same
More informationEulerian tours. Russell Impagliazzo and Miles Jones Thanks to Janine Tiefenbruck. April 20, 2016
Eulerian tours Russell Impagliazzo and Miles Jones Thanks to Janine Tiefenbruck http://cseweb.ucsd.edu/classes/sp16/cse21-bd/ April 20, 2016 Seven Bridges of Konigsberg Is there a path that crosses each
More informationCSE Winter 2015 Quiz 2 Solutions
CSE 101 - Winter 2015 Quiz 2 s January 27, 2015 1. True or False: For any DAG G = (V, E) with at least one vertex v V, there must exist at least one topological ordering. (Answer: True) Fact (from class)
More informationPESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of MCA
INTERNAL ASSESSMENT TEST 2 Date : 30/3/15 Max Marks : 50 Name of faculty : Sabeeha Sultana Subject & Code : ADA(13MCA41) Answer any five full question: 1.Illustrate Mergesort for the dataset 8,3,2,9,7,1,5,4.
More informationCSE 421 Closest Pair of Points, Master Theorem, Integer Multiplication
CSE 421 Closest Pair of Points, Master Theorem, Integer Multiplication Shayan Oveis Gharan 1 Finding the Closest Pair of Points Closest Pair of Points (non geometric) Given n points and arbitrary distances
More informationDivide and Conquer 1
Divide and Conquer A Useful Recurrence Relation Def. T(n) = number of comparisons to mergesort an input of size n. Mergesort recurrence. T(n) if n T n/2 T n/2 solve left half solve right half merging n
More informationCSE 202 Divide-and-conquer algorithms. Fan Chung Graham UC San Diego
CSE 22 Divide-and-conquer algorithms Fan Chung Graham UC San Diego Announcements Homework due today before the class. About homework, write your own homework, allowing oral discussion with one fixed partner.
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 informationUnit-2 Divide and conquer 2016
2 Divide and conquer Overview, Structure of divide-and-conquer algorithms, binary search, quick sort, Strassen multiplication. 13% 05 Divide-and- conquer The Divide and Conquer Paradigm, is a method of
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 25 Pearson-Addison Wesley. All rights reserved. Divide-and-Conquer Divide-and-conquer. Break up problem into several parts. Solve each part
More informationDivide-and-Conquer. Combine solutions to sub-problems into overall solution. Break up problem of size n into two equal parts of size!n.
Chapter 5 Divide and Conquer Slides by Kevin Wayne. Copyright 25 Pearson-Addon Wesley. All rights reserved. Divide-and-Conquer Divide-and-conquer. Break up problem into several parts. Solve each part recursively.
More informationDivide-and-Conquer. Dr. Yingwu Zhu
Divide-and-Conquer Dr. Yingwu Zhu Divide-and-Conquer The most-well known algorithm design technique: 1. Divide instance of problem into two or more smaller instances 2. Solve smaller instances independently
More informationCSE 101, Winter Discussion Section Week 1. January 8 - January 15
CSE 101, Winter 2018 Discussion Section Week 1 January 8 - January 15 Important Annotations were added (post-lecture) to the tablet slides, to fill in a few gaps (Lecture 1) Look through Additional Resources
More informationCSC Design and Analysis of Algorithms
CSC 8301- Design and Analysis of Algorithms Lecture 6 Divide and Conquer Algorithm Design Technique Divide-and-Conquer The most-well known algorithm design strategy: 1. Divide a problem instance into two
More informationCSC Design and Analysis of Algorithms. Lecture 6. Divide and Conquer Algorithm Design Technique. Divide-and-Conquer
CSC 8301- Design and Analysis of Algorithms Lecture 6 Divide and Conquer Algorithm Design Technique Divide-and-Conquer The most-well known algorithm design strategy: 1. Divide a problem instance into two
More informationUCSD CSE 101 MIDTERM 1, Winter 2008
UCSD CSE 101 MIDTERM 1, Winter 2008 Andrew B. Kahng / Evan Ettinger Feb 1, 2008 Name: }{{} Student ID: }{{} Read all of the following information before starting the exam. This test has 3 problems totaling
More information17 February Given an algorithm, compute its running time in terms of O, Ω, and Θ (if any). Usually the big-oh running time is enough.
Midterm Review CSE 2011 Winter 2011 17 February 2011 1 Algorithm Analysis Given an algorithm, compute its running time in terms of O, Ω, and Θ (if any). Usually the big-oh running time is enough. Given
More informationParallel Sorting Algorithms
CSC 391/691: GPU Programming Fall 015 Parallel Sorting Algorithms Copyright 015 Samuel S. Cho Sorting Algorithms Review Bubble Sort: O(n ) Insertion Sort: O(n ) Quick Sort: O(n log n) Heap Sort: O(n log
More informationAn Introduction to Graph Theory
An Introduction to Graph Theory CIS008-2 Logic and Foundations of Mathematics David Goodwin david.goodwin@perisic.com 12:00, Friday 17 th February 2012 Outline 1 Graphs 2 Paths and cycles 3 Graphs and
More informationChapter 4. Divide-and-Conquer. Copyright 2007 Pearson Addison-Wesley. All rights reserved.
Chapter 4 Divide-and-Conquer Copyright 2007 Pearson Addison-Wesley. All rights reserved. Divide-and-Conquer The most-well known algorithm design strategy: 2. Divide instance of problem into two or more
More informationNotes slides from before lecture. CSE 21, Winter 2017, Section A00. Lecture 4 Notes. Class URL:
Notes slides from before lecture CSE 21, Winter 2017, Section A00 Lecture 4 Notes Class URL: http://vlsicad.ucsd.edu/courses/cse21-w17/ Notes slides from before lecture Notes January 23 (1) HW2 due tomorrow
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 informationCSE 202 Divide-and-conquer algorithms. Fan Chung Graham UC San Diego
CSE 22 Divide-and-conquer algorithms Fan Chung Graham UC San Diego A useful fact about trees Any tree on n vertices contains a vertex v whose removal separates the remaining graph into two parts, one of
More informationSolving Linear Recurrence Relations (8.2)
EECS 203 Spring 2016 Lecture 18 Page 1 of 10 Review: Recurrence relations (Chapter 8) Last time we started in on recurrence relations. In computer science, one of the primary reasons we look at solving
More informationRecursive Algorithms II
Recursive Algorithms II Margaret M. Fleck 23 October 2009 This lecture wraps up our discussion of algorithm analysis (section 4.4 and 7.1 of Rosen). 1 Recap Last lecture, we started talking about mergesort,
More informationCHAPTER 2. Graphs. 1. Introduction to Graphs and Graph Isomorphism
CHAPTER 2 Graphs 1. Introduction to Graphs and Graph Isomorphism 1.1. The Graph Menagerie. Definition 1.1.1. A simple graph G = (V, E) consists of a set V of vertices and a set E of edges, represented
More informationTrees and Intro to Counting
Trees and Intro to Counting CSE21 Winter 2017, Day 15 (B00), Day 10/11 (A00) February 15, 2017 http://vlsicad.ucsd.edu/courses/cse21-w17 Another Special Type of Graph: Trees (Rooted) Trees: definitions
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 informationEncoding/Decoding and Lower Bound for Sorting
Encoding/Decoding and Lower Bound for Sorting CSE21 Winter 2017, Day 19 (B00), Day 13 (A00) March 1, 2017 http://vlsicad.ucsd.edu/courses/cse21-w17 Announcements HW #7 assigned Due: Tuesday 2/7 11:59pm
More informationMidterm solutions. n f 3 (n) = 3
Introduction to Computer Science 1, SE361 DGIST April 20, 2016 Professors Min-Soo Kim and Taesup Moon Midterm solutions Midterm solutions The midterm is a 1.5 hour exam (4:30pm 6:00pm). This is a closed
More informationRandomized Algorithms: Element Distinctness
Randomized Algorithms: Element Distinctness CSE21 Winter 2017, Day 24 (B00), Day 16-17 (A00) March 13, 2017 http://vlsicad.ucsd.edu/courses/cse21-w17 Element Distinctness: WHAT Given list of positive integers
More informationDEFINITION OF GRAPH GRAPH THEORY GRAPHS ACCORDING TO THEIR VERTICES AND EDGES EXAMPLE GRAPHS ACCORDING TO THEIR VERTICES AND EDGES
DEFINITION OF GRAPH GRAPH THEORY Prepared by Engr. JP Timola Reference: Discrete Math by Kenneth H. Rosen A graph G = (V,E) consists of V, a nonempty set of vertices (or nodes) and E, a set of edges. Each
More informationTest 1 Review Questions with Solutions
CS3510 Design & Analysis of Algorithms Section A Test 1 Review Questions with Solutions Instructor: Richard Peng Test 1 in class, Wednesday, Sep 13, 2017 Main Topics Asymptotic complexity: O, Ω, and Θ.
More informationCSE 421 Algorithms: Divide and Conquer
CSE 42 Algorithms: Divide and Conquer Larry Ruzzo Thanks to Paul Beame, Kevin Wayne for some slides Outline: General Idea algorithm design paradigms: divide and conquer Review of Merge Sort Why does it
More informationElements of Graph Theory
Elements of Graph Theory Quick review of Chapters 9.1 9.5, 9.7 (studied in Mt1348/2008) = all basic concepts must be known New topics we will mostly skip shortest paths (Chapter 9.6), as that was covered
More informationGraphs & Digraphs Tuesday, November 06, 2007
Graphs & Digraphs Tuesday, November 06, 2007 10:34 PM 16.1 Directed Graphs (digraphs) like a tree but w/ no root node & no guarantee of paths between nodes consists of: nodes/vertices - a set of elements
More informationGraphs. Pseudograph: multiple edges and loops allowed
Graphs G = (V, E) V - set of vertices, E - set of edges Undirected graphs Simple graph: V - nonempty set of vertices, E - set of unordered pairs of distinct vertices (no multiple edges or loops) Multigraph:
More informationAlgorithms: Lecture 7. Chalmers University of Technology
Algorithms: Lecture 7 Chalmers University of Technology Today s Lecture Divide & Conquer Counting Inversions Closest Pair of Points Multiplication of large integers Intro to the forthcoming problems Graphs:
More informationCS 61B Summer 2005 (Porter) Midterm 2 July 21, SOLUTIONS. Do not open until told to begin
CS 61B Summer 2005 (Porter) Midterm 2 July 21, 2005 - SOLUTIONS Do not open until told to begin This exam is CLOSED BOOK, but you may use 1 letter-sized page of notes that you have created. Problem 0:
More informationOutline for Today. How can we speed up operations that work on integer data? A simple data structure for ordered dictionaries.
van Emde Boas Trees Outline for Today Data Structures on Integers How can we speed up operations that work on integer data? Tiered Bitvectors A simple data structure for ordered dictionaries. van Emde
More informationOutline for Today. How can we speed up operations that work on integer data? A simple data structure for ordered dictionaries.
van Emde Boas Trees Outline for Today Data Structures on Integers How can we speed up operations that work on integer data? Tiered Bitvectors A simple data structure for ordered dictionaries. van Emde
More informationDivide-and-Conquer. The most-well known algorithm design strategy: smaller instances. combining these solutions
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. Obtain solution to original
More informationCS171 Midterm Exam. October 29, Name:
CS171 Midterm Exam October 29, 2012 Name: You are to honor the Emory Honor Code. This is a closed-book and closed-notes exam. You have 50 minutes to complete this exam. Read each problem carefully, and
More informationDivide and Conquer 4-0
Divide and Conquer 4-0 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. Obtain
More informationBinomial Coefficient Identities and Encoding/Decoding
Binomial Coefficient Identities and Encoding/Decoding CSE21 Winter 2017, Day 18 (B00), Day 12 (A00) February 24, 2017 http://vlsicad.ucsd.edu/courses/cse21-w17 MT2 Review Sessions Today and Tomorrow! TODAY
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 informationCS61BL. Lecture 5: Graphs Sorting
CS61BL Lecture 5: Graphs Sorting Graphs Graphs Edge Vertex Graphs (Undirected) Graphs (Directed) Graphs (Multigraph) Graphs (Acyclic) Graphs (Cyclic) Graphs (Connected) Graphs (Disconnected) Graphs (Unweighted)
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 informationGraph Coloring. Margaret M. Fleck. 3 May This lecture discusses the graph coloring problem (section 9.8 of Rosen).
Graph Coloring Margaret M. Fleck 3 May 2010 This lecture discusses the graph coloring problem (section 9.8 of Rosen). 1 Announcements Makeup quiz last day of classes (at the start of class). Your room
More informationMath.3336: Discrete Mathematics. Chapter 10 Graph Theory
Math.3336: Discrete Mathematics Chapter 10 Graph Theory Instructor: Dr. Blerina Xhabli Department of Mathematics, University of Houston https://www.math.uh.edu/ blerina Email: blerina@math.uh.edu Fall
More informationVarying Applications (examples)
Graph Theory Varying Applications (examples) Computer networks Distinguish between two chemical compounds with the same molecular formula but different structures Solve shortest path problems between cities
More informationCOE428 Lecture Notes Week 1 (Week of January 9, 2017)
COE428 Lecture Notes: Week 1 1 of 10 COE428 Lecture Notes Week 1 (Week of January 9, 2017) Table of Contents COE428 Lecture Notes Week 1 (Week of January 9, 2017)...1 Announcements...1 Topics...1 Informal
More information7.3 Divide-and-Conquer Algorithm and Recurrence Relations
73 Divide-and-Conquer Algorithm and Recurrence Relations Many recursive algorithms take a problem with a given input and divide it into one or more smaller problems This reduction is repeatedly applied
More informationGraphs. The ultimate data structure. graphs 1
Graphs The ultimate data structure graphs 1 Definition of graph Non-linear data structure consisting of nodes & links between them (like trees in this sense) Unlike trees, graph nodes may be completely
More informationSorting Algorithms. + Analysis of the Sorting Algorithms
Sorting Algorithms + Analysis of the Sorting Algorithms Insertion Sort What if first k elements of array are already sorted? 4, 7, 12, 5, 19, 16 We can shift the tail of the sorted elements list down and
More informationLecture 22 Tuesday, April 10
CIS 160 - Spring 2018 (instructor Val Tannen) Lecture 22 Tuesday, April 10 GRAPH THEORY Directed Graphs Directed graphs (a.k.a. digraphs) are an important mathematical modeling tool in Computer Science,
More information1KOd17RMoURxjn2 CSE 20 DISCRETE MATH Fall
CSE 20 https://goo.gl/forms/1o 1KOd17RMoURxjn2 DISCRETE MATH Fall 2017 http://cseweb.ucsd.edu/classes/fa17/cse20-ab/ Today's learning goals Explain the steps in a proof by mathematical and/or structural
More informationGraphs. The ultimate data structure. graphs 1
Graphs The ultimate data structure graphs 1 Definition of graph Non-linear data structure consisting of nodes & links between them (like trees in this sense) Unlike trees, graph nodes may be completely
More information1. (a) O(log n) algorithm for finding the logical AND of n bits with n processors
1. (a) O(log n) algorithm for finding the logical AND of n bits with n processors on an EREW PRAM: See solution for the next problem. Omit the step where each processor sequentially computes the AND of
More informationLecture 4 CS781 February 3, 2011
Lecture 4 CS78 February 3, 2 Topics: Data Compression-Huffman Trees Divide-and-Conquer Solving Recurrence Relations Counting Inversions Closest Pair Integer Multiplication Matrix Multiplication Data Compression
More informationSection 8.2 Graph Terminology. Undirected Graphs. Definition: Two vertices u, v in V are adjacent or neighbors if there is an edge e between u and v.
Section 8.2 Graph Terminology Undirected Graphs Definition: Two vertices u, v in V are adjacent or neighbors if there is an edge e between u and v. The edge e connects u and v. The vertices u and v are
More informationLecture 3: Sorting 1
Lecture 3: Sorting 1 Sorting Arranging an unordered collection of elements into monotonically increasing (or decreasing) order. S = a sequence of n elements in arbitrary order After sorting:
More informationDiscrete Mathematics for CS Spring 2008 David Wagner Note 13. An Introduction to Graphs
CS 70 Discrete Mathematics for CS Spring 2008 David Wagner Note 13 An Introduction to Graphs Formulating a simple, precise specification of a computational problem is often a prerequisite to writing a
More informationMarch 20/2003 Jayakanth Srinivasan,
Definition : A simple graph G = (V, E) consists of V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements of V called edges. Definition : In a multigraph G = (V, E) two or
More informationCS 161 Fall 2015 Final Exam
CS 161 Fall 2015 Final Exam Name: Student ID: 1: 2: 3: 4: 5: 6: 7: 8: Total: 1. (15 points) Let H = [24, 21, 18, 15, 12, 9, 6, 3] be an array of eight numbers, interpreted as a binary heap with the maximum
More informationQuestion Points Score TOTAL 50
UCSD CSE 101 Section B00, Winter 2015 MIDTERM February 5, 2015 NAME: Student ID: Question Points Score 1 10 2 10 3 10 4 10 5 10 TOTAL 50 INSTRUCTIONS. Be clear and concise. Write your answers in the space
More informationThe Matrix-Tree Theorem and Its Applications to Complete and Complete Bipartite Graphs
The Matrix-Tree Theorem and Its Applications to Complete and Complete Bipartite Graphs Frankie Smith Nebraska Wesleyan University fsmith@nebrwesleyan.edu May 11, 2015 Abstract We will look at how to represent
More informationCS171 Final Practice Exam
CS171 Final Practice Exam Name: You are to honor the Emory Honor Code. This is a closed-book and closed-notes exam. You have 150 minutes to complete this exam. Read each problem carefully, and review your
More informationCS Divide and Conquer
CS483-07 Divide and Conquer Instructor: Fei Li Room 443 ST II Office hours: Tue. & Thur. 1:30pm - 2:30pm or by appointments lifei@cs.gmu.edu with subject: CS483 http://www.cs.gmu.edu/ lifei/teaching/cs483_fall07/
More informationCOMP 352 FALL Tutorial 10
1 COMP 352 FALL 2016 Tutorial 10 SESSION OUTLINE Divide-and-Conquer Method Sort Algorithm Properties Quick Overview on Sorting Algorithms Merge Sort Quick Sort Bucket Sort Radix Sort Problem Solving 2
More informationn = 1 What problems are interesting when n is just 1?
What if n=1??? n = 1 What problems are interesting when n is just 1? Sorting? No Median finding? No Addition? How long does it take to add one pair of numbers? Multiplication? How long does it take to
More informationUNIT-2 DIVIDE & CONQUER
Overview: Divide and Conquer Master theorem Master theorem based analysis for Binary Search Merge Sort Quick Sort Divide and Conquer UNIT-2 DIVIDE & CONQUER Basic Idea: 1. Decompose problems into sub instances.
More informationSecond Midterm Exam, CMPSC 465, Spring 2009 Practice problems
Second idterm Exam, S 465, Spring 2009 ractice problems idterm will be on Tuesday, arch 31, 8:15, in 60 and 61 Willard. This will be open book exam, you can also have notes (several sheets or one notebook).
More informationGraphs. Introduction To Graphs: Exercises. Definitions:
Graphs Eng.Jehad Aldahdooh Introduction To Graphs: Definitions: A graph G = (V, E) consists of V, a nonempty set of vertices (or nodes) and E, a set of edges. Each edge has either one or two vertices associated
More informationCSE 373 Spring 2010: Midterm #1 (closed book, closed notes, NO calculators allowed)
Name: Email address: CSE 373 Spring 2010: Midterm #1 (closed book, closed notes, NO calculators allowed) Instructions: Read the directions for each question carefully before answering. We may give partial
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 informationGraph Theory S 1 I 2 I 1 S 2 I 1 I 2
Graph Theory S I I S S I I S Graphs Definition A graph G is a pair consisting of a vertex set V (G), and an edge set E(G) ( ) V (G). x and y are the endpoints of edge e = {x, y}. They are called adjacent
More informationAlgorithms Exam TIN093/DIT600
Algorithms Exam TIN093/DIT600 Course: Algorithms Course code: TIN 093 (CTH), DIT 600 (GU) Date, time: 22nd October 2016, 14:00 18:00 Building: M Responsible teacher: Peter Damaschke, Tel. 5405 Examiner:
More informationIntroduction to Graphs
Graphs Introduction to Graphs Graph Terminology Directed Graphs Special Graphs Graph Coloring Representing Graphs Connected Graphs Connected Component Reading (Epp s textbook) 10.1-10.3 1 Introduction
More informationMergesort again. 1. Split the list into two equal parts
Quicksort Mergesort again 1. Split the list into two equal parts 5 3 9 2 8 7 3 2 1 4 5 3 9 2 8 7 3 2 1 4 Mergesort again 2. Recursively mergesort the two parts 5 3 9 2 8 7 3 2 1 4 2 3 5 8 9 1 2 3 4 7 Mergesort
More informationGraph Algorithms (part 3 of CSC 282),
Graph Algorithms (part of CSC 8), http://www.cs.rochester.edu/~stefanko/teaching/11cs8 Homework problem sessions are in CSB 601, 6:1-7:1pm on Oct. (Wednesday), Oct. 1 (Wednesday), and on Oct. 19 (Wednesday);
More informationCSE 332 Winter 2015: Midterm Exam (closed book, closed notes, no calculators)
_ UWNetID: Lecture Section: A CSE 332 Winter 2015: Midterm Exam (closed book, closed notes, no calculators) Instructions: Read the directions for each question carefully before answering. We will give
More informationDiscrete Mathematics (2009 Spring) Graphs (Chapter 9, 5 hours)
Discrete Mathematics (2009 Spring) Graphs (Chapter 9, 5 hours) Chih-Wei Yi Dept. of Computer Science National Chiao Tung University June 1, 2009 9.1 Graphs and Graph Models What are Graphs? General meaning
More informationHomework 2. Sample Solution. Due Date: Thursday, May 31, 11:59 pm
Homework Sample Solution Due Date: Thursday, May 31, 11:59 pm Directions: Your solutions should be typed and submitted as a single pdf on Gradescope by the due date. L A TEX is preferred but not required.
More informationCSE 20 DISCRETE MATH. Winter
CSE 20 DISCRETE MATH Winter 2017 http://cseweb.ucsd.edu/classes/wi17/cse20-ab/ Final exam The final exam is Saturday March 18 8am-11am. Lecture A will take the exam in GH 242 Lecture B will take the exam
More informationDivide & Conquer Design Technique
Divide & Conquer Design Technique Adnan YAZICI Dept. of Computer Engineering Middle East Technical Univ. Ankara - TURKEY 1 The Divide & Conquer strategy can be described in general terms as follows: A
More informationCSE 20 DISCRETE MATH. Fall
CSE 20 DISCRETE MATH Fall 2017 http://cseweb.ucsd.edu/classes/fa17/cse20-ab/ Final exam The final exam is Saturday December 16 11:30am-2:30pm. Lecture A will take the exam in Lecture B will take the exam
More informationCSE 332 Spring 2013: Midterm Exam (closed book, closed notes, no calculators)
Name: Email address: Quiz Section: CSE 332 Spring 2013: Midterm Exam (closed book, closed notes, no calculators) Instructions: Read the directions for each question carefully before answering. We will
More informationCSC Design and Analysis of Algorithms. Lecture 6. Divide and Conquer Algorithm Design Technique. Divide-and-Conquer
CSC 8301- Design and Analysis of Algorithms Lecture 6 Divide and Conuer Algorithm Design Techniue Divide-and-Conuer The most-well known algorithm design strategy: 1. Divide a problem instance into two
More information(5.2) 151 Math Exercises. Graph Terminology and Special Types of Graphs. Malek Zein AL-Abidin
King Saud University College of Science Department of Mathematics 151 Math Exercises (5.2) Graph Terminology and Special Types of Graphs Malek Zein AL-Abidin ه Basic Terminology First, we give some terminology
More information