Circuits. CSE 373 Data Structures

Similar documents
Data Structures in Java

NP-Completeness. CptS 223 Advanced Data Structures. Larry Holder School of Electrical Engineering and Computer Science Washington State University

P, NP, NP-Complete. Ruth Anderson

Data Structures in Java. Session 22 Instructor: Bert Huang

Intro to Contemporary Math

Automata Theory CS Complexity Theory I: Polynomial Time

NP-Completeness. Until now we have been designing algorithms for specific problems

Data Structures and Algorithms

Hamiltonian Cycle. Zero Knowledge Proof

NP-Complete and Non-Computable Problems. COMP385 Dr. Ken Williams

Limitations of Algorithm Power

CS/COE

Algorithms and Theory of Computation. Lecture 22: NP-Completeness (2)

CSE 326: Data Structures NP Completeness

8.3 Hamiltonian Paths and Circuits

Informatique Fondamentale IMA S8

Lecture 24: How to become Famous with P and NP

CS 320, Fall Dr. Geri Georg, Instructor 320 NP 1

D1 Discrete Mathematics The Travelling Salesperson problem. The Nearest Neighbour Algorithm The Lower Bound Algorithm The Tour Improvement Algorithm

Computer Science 385 Analysis of Algorithms Siena College Spring Topic Notes: Limitations of Algorithms

Easy Problems vs. Hard Problems. CSE 421 Introduction to Algorithms Winter Is P a good definition of efficient? The class P

Some Algebra Problems (Algorithmic) CSE 417 Introduction to Algorithms Winter Some Problems. A Brief History of Ideas

BBM402-Lecture 11: The Class NP

LECTURE 1: INTRODUCTION

6 Euler Circuits and Hamiltonian Cycles

Optimization Prof. A. Goswami Department of Mathematics Indian Institute of Technology, Kharagpur. Lecture - 20 Travelling Salesman Problem

CS 301: Complexity of Algorithms (Term I 2008) Alex Tiskin Harald Räcke. Hamiltonian Cycle. 8.5 Sequencing Problems. Directed Hamiltonian Cycle

NP Completeness. CS 374: Algorithms & Models of Computation, Spring Lecture 23. November 19, 2015

CS Algorithms and Complexity

Complexity, P and NP

More on NP and Reductions

The P versus NP Problem. Ker-I Ko. Stony Brook, New York

CS 583: Algorithms. NP Completeness Ch 34. Intractability

Hamiltonian Graphs Graphs

CS 350 Algorithms and Complexity

NP-complete problems. CSE 101: Design and Analysis of Algorithms Lecture 20

Unit 7 Day 4 Section 4.5 & Practice Hamiltonian Circuits and Paths

CS 350 Algorithms and Complexity

Bounds on the Traveling Salesman Problem

COSE215: Theory of Computation. Lecture 20 P, NP, and NP-Complete Problems

CHAPTER 3 FUNDAMENTALS OF COMPUTATIONAL COMPLEXITY. E. Amaldi Foundations of Operations Research Politecnico di Milano 1

Graduate Algorithms CS F-21 NP & Approximation Algorithms

NP and Computational Intractability

Outline. 1 NP-Completeness Theory. 2 Limitation of Computation. 3 Examples. 4 Decision Problems. 5 Verification Algorithm

Polynomial-Time Reductions

VIII. NP-completeness

Computational Complexity

Chapter 8. NP and Computational Intractability. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

The P = NP Problem Bristol Teachers Circle, June P.D.Welch, University of Bristol

Instructor N.Sadagopan Scribe: P.Renjith

Travelling Salesman Problem

Some Algebra Problems (Algorithmic) CSE 417 Introduction to Algorithms Winter Some Problems. A Brief History of Ideas

CSC 8301 Design & Analysis of Algorithms: Lower Bounds

Preliminaries. Graphs. E : set of edges (arcs) (Undirected) Graph : (i, j) = (j, i) (edges) V = {1, 2, 3, 4, 5}, E = {(1, 3), (3, 2), (2, 4)}

8.5 Sequencing Problems

NP-Completeness. Subhash Suri. May 15, 2018

CS6901: review of Theory of Computation and Algorithms

NP-Complete Problems. More reductions

Introduction. An Introduction to Algorithms and Data Structures

Computability and Complexity Theory: An Introduction

July 18, Approximation Algorithms (Travelling Salesman Problem)

Lecture 4: NP and computational intractability

NP-Completeness. Andreas Klappenecker. [based on slides by Prof. Welch]

CSCI3390-Lecture 14: The class NP

P is the class of problems for which there are algorithms that solve the problem in time O(n k ) for some constant k.

AC64/AT64/ AC115/AT115 DESIGN & ANALYSIS OF ALGORITHMS

1 Reductions and Expressiveness

Correctness of Dijkstra s algorithm

(tree searching technique) (Boolean formulas) satisfying assignment: (X 1, X 2 )

Traveling Salesman Problem (TSP) - Visit every city and then go home.

CISC 4090 Theory of Computation

Nondeterministic Polynomial Time

Week Cuts, Branch & Bound, and Lagrangean Relaxation

In complexity theory, algorithms and problems are classified by the growth order of computation time as a function of instance size.

Unit 1A: Computational Complexity

Analysis of Algorithms. Unit 5 - Intractable Problems

Complexity Theory Part I

CS3719 Theory of Computation and Algorithms

Instructor N.Sadagopan Scribe: P.Renjith. Lecture- Complexity Class- P and NP

Data Structures and Algorithms

NP-completeness. Chapter 34. Sergey Bereg

NP-Complete problems

Algorithms Design & Analysis. Approximation Algorithm

Theory of Computation Time Complexity

Friday Four Square! Today at 4:15PM, Outside Gates

8. INTRACTABILITY I. Lecture slides by Kevin Wayne Copyright 2005 Pearson-Addison Wesley. Last updated on 2/6/18 2:16 AM

R ij = 2. Using all of these facts together, you can solve problem number 9.

Exam EDAF May 2011, , Vic1. Thore Husfeldt

NP and NP-Completeness

13.1 Nondeterministic Polynomial Time

ENEE 459E/CMSC 498R In-class exercise February 10, 2015

P,NP, NP-Hard and NP-Complete

} } } Lecture 23: Computational Complexity. Lecture Overview. Definitions: EXP R. uncomputable/ undecidable P C EXP C R = = Examples

CSC 421: Algorithm Design & Analysis. Spring 2018

Geometric Steiner Trees

University of Toronto Department of Electrical and Computer Engineering. Final Examination. ECE 345 Algorithms and Data Structures Fall 2016

CSE 105 THEORY OF COMPUTATION

Computational Intractability 2010/4/15. Lecture 2

P versus NP. Math 40210, Spring September 16, Math (Spring 2012) P versus NP September 16, / 9

8.5 Sequencing Problems. Chapter 8. NP and Computational Intractability. Hamiltonian Cycle. Hamiltonian Cycle

Transcription:

Circuits CSE 373 Data Structures

Readings Reading Alas not in your book. So it won t be on the final! Circuits 2

Euler Euler (1707-1783): might be the most prolific mathematician of all times (analysis, differential geometry, number theory etc.) For example, e, the natural base for logarithms, is named after him; he introduced the notation f(x), the notation for complex numbers (a + i b). Contributions in optics, mechanics, magnetism, electricity Read Euler, read Euler, he is our master in everything (Quote from Laplace a 19 th Century French mathematician) Circuits 3

Euler and Graph Theory Circuits 4

The Seven Bridges Problem Each area is a vertex Each bridge is an edge Find a path that traverses each edge exactly once Circuits 5

Related Problems: Puzzles A B C Two problems: 1) Can you draw these without lifting your pen, drawing each line only once 2) Can you start and end at the same point. Circuits 6

Related Problems: Puzzles Puzzle A: 1) yes and 2) yes Puzzle B: 1) yes if you start at lowest right (or left) corner and 2) no Puzzle C: 1) no and 2) no Circuits 7

Euler Paths and Circuits Given G(V,E), an Euler path is a path that contains each edge once (Problem 1) Given G(V,E) an Euler circuit is an Euler path that starts and ends at the same vertex (Problem 2) Circuits 8

An Euler Circuit for Puzzle A 8 1 2 9 5 7 4 10 6 3 Circuits 9

Euler Circuit Property A graph has an Euler circuit if and only if it is connected and all its vertices have even degrees (cf. Puzzle A) Necessary condition (only if): a vertex has to be entered and left, hence need an even number of edges at each vertex Sufficient condition: by construction (linear time algorithm) Circuits 10

Euler Path Property A graph has an Euler path if and only if it is connected and exactly two of its vertices have odd degrees (cf. Puzzle B) One of the vertices will be the start point and the other one will be the end point to construct it, add an edge (start,end). Now all vertices have even degrees. Build the Euler circuit starting from start and at the end delete the edge (start,end). Circuits 11

Back to Euler Seven Bridges Sorry, no Euler Circuit (not all vertices have even degrees) Sorry, no Euler path (more than 2 vertices have odd degrees) Circuits 12

Finding an Euler Circuit Check than one exists (all vertices have even degrees) Starting from a vertex v i (at random) While all edges have not been marked DFS(v i ) using unmarked edges (and marking them) until back to v i Pick a vertex v j on the (partial) circuit with a remaining unmarked edge and repeat the loop; Splice this new circuit in the old one and repeat. Circuits 13

Example A Pick vertex A B G C DFS(A) yields circuit ABCA and edges (A,B),(B,C) and (C,A) are marked D F E Pick a vertex in circuit with an unmarked edge, say B Circuits 14

Example (ct d) A ABCA B D G F C E Picking B yields circuit BDECGB (note that when we reached C, we had to go to G since (C,B), (C,A) and (C,E) were marked Slice the green circuit in the blue one ABDECGBCA Circuits 15

Example (end) A ABDECGBCA B G C Pick vertex with unmarked edge D DFS(D) yields DFEGD D E Splicing yields Euler circuit ABDFEGDECGBCA F Circuits 16

Euler Circuit Complexity Find degrees of vertices: O(m) Mark each edge once (in each direction) thus traverse each edge once: O(m) This might require slightly improved adjacency list Splice the circuits:at most n cycles (use linked lists: O(n)) Linear time O(n+m) Circuits 17

Hamiltonian Circuit A Graph G(V,E) has an hamiltonian circuit if there exists a path which goes through each vertex exactly once Seems closely related to Euler circuit It is NOT! Euler circuit can be solved in linear time Hamiltonian circuit requires exhaustive search (exponential time) in the worse case Circuits 18

Sir William Hamilton Irish mathematician (1805-1865) Circuits 19

Examples Does Graph I have an Euler circuit? an Hamiltonian circuit? Does Graph II have an Euler circuit? an Hamiltonian circuit? Circuits 20

Finding Hamiltonian Circuits Apparently easier Yes or No question: Does G contain an Hamiltonian circuit? NO known easy algorithm, i.e., no algorithm that runs in O(n p ), or polynomial time in the number of vertices Requires exhaustive search (brute force) Circuits 21

Example of Exhaustive Search How many paths? Let B be the average branching factor at each node for DFS Total number of paths to be examined B.B.B.B = O(B n ) Exponential time! Circuits 22

Time Complexity of Algorithms If one has to process n elements, can t have algorithms running (worse case) in less than O(n) But what about binary search, deletemin in a heap, insert in an AVL tree etc.? The input has been preprocessed Array sorted for binary search, buildheap for the heap, AVL tree already has AVL property etc. all ops that took at least O(n) Circuits 23

The Complexity Class P Most of the algorithms we have seen have been polynomial time O(n p ) Searching (build the search structure and search it), sorting, many graph algorithms such as topological sort, shortest-path, Euler circuit They form the class P of algorithms that can be solved (worse case) in polynomial time Circuits 24

Are There Problems not in P? For some problems, there are no known algorithms that run (worse case) in polynomial time Hamiltonian circuit Circuit satisfiability Given a Boolean formula find an assignment of variables such that the formula is true (even if only 3 variables) Traveling Salesman problem Given a complete weighted graph G and an integer K, is there a circuit that visits all vertices only once of cost less than K Etc. Circuits 25

Undecidability There are problems that cannot be solved algorithmically: they are undecidable The most well-known one is the Turing Halting Problem Turing proved that it is impossible to write a computer program that can read another computer program, and, if that program will run forever without stopping, tell us, after some finite (but unbounded) time this fact. Circuits 26