Algorithms and Theory of Computation. Lecture 1: Introduction, Basics of Algorithms

Similar documents
CSEP 521 Applied Algorithms. Richard Anderson Winter 2013 Lecture 1

Data Structures in Java

CS154, Lecture 18: 1

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

Algorithm Design and Analysis

CSE 105 Homework 1 Due: Monday October 9, Instructions. should be on each page of the submission.

CSC 8301 Design & Analysis of Algorithms: Lower Bounds

CSCI3390-Lecture 14: The class NP

Lecture 1: Course Overview and Turing machine complexity

CS 154 Introduction to Automata and Complexity Theory

6.045J/18.400J: Automata, Computability and Complexity Final Exam. There are two sheets of scratch paper at the end of this exam.

6.045 Final Exam Solutions

CS684 Graph Algorithms

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Automata Theory, Computability and Complexity

Show that the following problems are NP-complete

Theory of Computation

Definition: Alternating time and space Game Semantics: State of machine determines who

Algorithms and Programming I. Lecture#1 Spring 2015

1 More finite deterministic automata

2. ALGORITHM ANALYSIS

Turing Machines and the Church-Turing Thesis

CS Automata, Computability and Formal Languages

CSE 105 THEORY OF COMPUTATION

SOLUTION: SOLUTION: SOLUTION:

BBM402-Lecture 11: The Class NP

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

Definition: Alternating time and space Game Semantics: State of machine determines who

CSE 549: Computational Biology. Computer Science for Biologists Biology

1 Computational Problems

Lecture 2: Connecting the Three Models

Parallelism and Machine Models

Final Exam Version A December 16, 2014 Name: NetID: Section: # Total Score

CpE358/CS381. Switching Theory and Logical Design. Summer

Quantum Computing Lecture 8. Quantum Automata and Complexity

NP-Completeness Part II

Theoretical Computer Science

Final Exam (Version B) December 16, 2014 Name: NetID: Section: 1 2 3

POLYNOMIAL SPACE QSAT. Games. Polynomial space cont d

Notes for Lecture Notes 2

Models of Computation

NP Complete Problems. COMP 215 Lecture 20

Solution to CS375 Homework Assignment 11 (40 points) Due date: 4/26/2017

Theory of Computation Lecture 1. Dr. Nahla Belal

CSE 200 Lecture Notes Turing machine vs. RAM machine vs. circuits

Lecture 14 - P v.s. NP 1

CSE 549: Computational Biology. Computer Science for Biologists Biology

CP405 Theory of Computation

CIS519: Applied Machine Learning Fall Homework 5. Due: December 10 th, 2018, 11:59 PM

Intelligent Agents. Formal Characteristics of Planning. Ute Schmid. Cognitive Systems, Applied Computer Science, Bamberg University

Announcements. Problem Set 6 due next Monday, February 25, at 12:50PM. Midterm graded, will be returned at end of lecture.

1.1 Administrative Stuff

Review of Basic Computational Complexity

9. PSPACE 9. PSPACE. PSPACE complexity class quantified satisfiability planning problem PSPACE-complete

Complexity: Some examples

Foundations of Computer Science Lecture 23 Languages: What is Computation?

9. PSPACE. PSPACE complexity class quantified satisfiability planning problem PSPACE-complete

Automata Theory CS S-12 Turing Machine Modifications

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

CSCI3390-Assignment 2 Solutions

Approximation and Randomized Algorithms (ARA) Lecture 1, September 3, 2012

CS103 Handout 22 Fall 2012 November 30, 2012 Problem Set 9

Computer Sciences Department

Foundations II: Data Structures and Algorithms

6.8 The Post Correspondence Problem

COMP-330 Theory of Computation. Fall Prof. Claude Crépeau. Lecture 2 : Regular Expressions & DFAs

Algorithms and Theory of Computation. Lecture 19: Class P and NP, Reduction

Great Theoretical Ideas in Computer Science. Lecture 7: Introduction to Computational Complexity

Midterm II : Formal Languages, Automata, and Computability

6-1 Computational Complexity

Lecture 22: PSPACE

Analysis of Algorithms Fall Basics of Algorithm Analysis Computational Tractability

Economics and Computation

INTRODUCTION TO THE THEORY OF NP-COMPLETENESS

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

Computational Models

DRAFT. Algebraic computation models. Chapter 14

: Cryptography and Game Theory Ran Canetti and Alon Rosen. Lecture 8

Data Structure and Algorithm Homework #1 Due: 2:20pm, Tuesday, March 12, 2013 TA === Homework submission instructions ===

CS5371 Theory of Computation. Lecture 5: Automata Theory III (Non-regular Language, Pumping Lemma, Regular Expression)

Supporting hyperplanes

Computability Theory

COMP-330 Theory of Computation. Fall Prof. Claude Crépeau. Lecture 1 : Introduction

Lecture 22: Quantum computational complexity

Econ 1123: Section 2. Review. Binary Regressors. Bivariate. Regression. Omitted Variable Bias

Announcements. Read Section 2.1 (Sets), 2.2 (Set Operations) and 5.1 (Mathematical Induction) Existence Proofs. Non-constructive

U.C. Berkeley CS278: Computational Complexity Professor Luca Trevisan 9/6/2004. Notes for Lecture 3

Chapter 9. PSPACE: A Class of Problems Beyond NP. Slides by Kevin Wayne Pearson-Addison Wesley. All rights reserved.

P = k T IME(n k ) Now, do all decidable languages belong to P? Let s consider a couple of languages:

CSE 105 THEORY OF COMPUTATION. Spring 2018 review class

CS 580: Algorithm Design and Analysis. Jeremiah Blocki Purdue University Spring 2018

FINAL EXAM CHEAT SHEET/STUDY GUIDE. You can use this as a study guide. You will also be able to use it on the Final Exam on

CS6901: review of Theory of Computation and Algorithms

CS 133 : Automata Theory and Computability

Important Dates. Non-instructional days. No classes. College offices closed.

CSC 1700 Analysis of Algorithms: P and NP Problems

CS151 Complexity Theory. Lecture 1 April 3, 2017

Notes on Space-Bounded Complexity

NP-Completeness. Sections 28.5, 28.6

Decision Problems with TM s. Lecture 31: Halting Problem. Universe of discourse. Semi-decidable. Look at following sets: CSCI 81 Spring, 2012

Transcription:

Algorithms and Theory of Computation Lecture 1: Introduction, Basics of Algorithms Xiaohui Bei MAS 714 August 14, 2017 Nanyang Technological University MAS 714 August 14, 2017 1 / 23

Administration Lectures Monday 10:30am - 12:30am SPMS-TR+17 Tuesday 9:30am - 11:30am SPMS-TR+17 Tutorials Tuesday 10:30am - 11:30am biweekly Exceptions: next week no lectures makeup lecture: time TBD Website: http://www3.ntu.edu.sg/home/xhbei/mas714.html E-mail: xhbei@ntu.edu.sg Office: MAS-05-46 Nanyang Technological University MAS 714 August 14, 2017 2 / 23

Gradings Homework: 20%, Midterm 20%, Final: 60% Homework Submitted by e-mail (as PDF files obtained from L A TEX or Word sources), or by pushing a hard copy under my office door. Solutions will be discussed on tutorials. Homework policy: You are allowed (and encouraged) to discuss with your peers on the questions and solutions. But everyone needs to write and submit their own solutions. No cheating behavior will be tolerated. Nanyang Technological University MAS 714 August 14, 2017 3 / 23

Recommended Reading Kleinberg, Tardos: Algorithm Design Cormen, Leiserson, Rivest, Stein: Introduction to Algorithms Sipser: Introduction to the Theory of Computation Nanyang Technological University MAS 714 August 14, 2017 4 / 23

Course Structure 1 Algorithm Design graph algorithms greedy divide and conquer dynamic programming linear programming network flow 2 Automata Theory regular laguages finite state machines 3 Computability Theory Turing machines undecidability P and NP NP-completeness Nanyang Technological University MAS 714 August 14, 2017 5 / 23

Algorithms Nanyang Technological University MAS 714 August 14, 2017 6 / 23

Algorithms An algorithm is a procedure for performing a computation. Start from an initial state and an input (perhaps empty), eventually produce an output. An algorithm consists of primitive steps/instructions that can be executed mechanically. What is a primitive step? Depends on the model of computation. C++ commands Nanyang Technological University MAS 714 August 14, 2017 6 / 23

Algorithms An algorithm is a procedure for performing a computation. Start from an initial state and an input (perhaps empty), eventually produce an output. An algorithm consists of primitive steps/instructions that can be executed mechanically. What is a primitive step? Depends on the model of computation. C++ commands A computer is a device that can be programmed to carry out primitive steps. can then implement an entire algorithm by keeping track of state model vs. device Nanyang Technological University MAS 714 August 14, 2017 6 / 23

Computers can be Humans! Figure: Women at work tabulating during World War II (Shorpy) Nanyang Technological University MAS 714 August 14, 2017 7 / 23

Complexity How to measure the performance of an algorithm? Nanyang Technological University MAS 714 August 14, 2017 8 / 23

Complexity How to measure the performance of an algorithm? Correctness: a must! the definition of correctness can be discussed Nanyang Technological University MAS 714 August 14, 2017 8 / 23

Complexity How to measure the performance of an algorithm? Correctness: a must! the definition of correctness can be discussed Two most important measures are time and space. Nanyang Technological University MAS 714 August 14, 2017 8 / 23

Complexity How to measure the performance of an algorithm? Correctness: a must! the definition of correctness can be discussed Two most important measures are time and space. Time: number of primitive steps needed to perform the computation. Nanyang Technological University MAS 714 August 14, 2017 8 / 23

Complexity How to measure the performance of an algorithm? Correctness: a must! the definition of correctness can be discussed Two most important measures are time and space. Time: number of primitive steps needed to perform the computation. Space: the amount of storage needed during the computation. Nanyang Technological University MAS 714 August 14, 2017 8 / 23

Algorithm Example Number Addition Given two n-digit numebrs x and y, compute x + y. Nanyang Technological University MAS 714 August 14, 2017 9 / 23

Algorithm Example Number Addition Given two n-digit numebrs x and y, compute x + y. Procedure Algorithm explanined: + write numbers under each other 1 1 3 8 7 3 4 8 4 0 7 5 1 2 2 8 0 9 add number position by position moving a carry forward Nanyang Technological University MAS 714 August 14, 2017 9 / 23

Algorithm Analysis Primitive steps: Nanyang Technological University MAS 714 August 14, 2017 10 / 23

Algorithm Analysis Primitive steps: add two digits read and write Nanyang Technological University MAS 714 August 14, 2017 10 / 23

Algorithm Analysis Primitive steps: add two digits read and write Time complexity: Nanyang Technological University MAS 714 August 14, 2017 10 / 23

Algorithm Analysis Primitive steps: add two digits read and write Time complexity: algorithm requires O(n) primitive steps. Nanyang Technological University MAS 714 August 14, 2017 10 / 23

Algorithm Analysis Primitive steps: add two digits read and write Time complexity: algorithm requires O(n) primitive steps. Space complexity: Nanyang Technological University MAS 714 August 14, 2017 10 / 23

Algorithm Analysis Primitive steps: add two digits read and write Time complexity: algorithm requires O(n) primitive steps. Space complexity: algorithm requires O(n) storage space. Nanyang Technological University MAS 714 August 14, 2017 10 / 23

Model of Computation An idealized mathematical construct that describes the primitive instructions and other details. Turing Machines Circuits Random Access Machine (RAM) etc. Nanyang Technological University MAS 714 August 14, 2017 11 / 23

Model of Computation An idealized mathematical construct that describes the primitive instructions and other details. Turing Machines Circuits Random Access Machine (RAM) etc. Random Access Machine (RAM) read/write from registers arithmetic operation on registers indirect addressing Nanyang Technological University MAS 714 August 14, 2017 11 / 23

Model of Computation An idealized mathematical construct that describes the primitive instructions and other details. Turing Machines Circuits Random Access Machine (RAM) etc. Random Access Machine (RAM) read/write from registers arithmetic operation on registers indirect addressing Within this course, basically, pseudocode/informal language. Nanyang Technological University MAS 714 August 14, 2017 11 / 23

Some Other Examples Number Multiplication Given two n-digit numebrs x and y, compute x y. Nanyang Technological University MAS 714 August 14, 2017 12 / 23

Some Other Examples Number Multiplication Given two n-digit numebrs x and y, compute x y. Procedure 8 7 3 4 7 5 4 3 6 5 6 1 1 1 3 4 9 2 4 1 4 6 7 5 Nanyang Technological University MAS 714 August 14, 2017 12 / 23

Number Multiplication Number of primitive steps: O(n 2 ). Space: O(n 2 ). Nanyang Technological University MAS 714 August 14, 2017 13 / 23

Number Multiplication Number of primitive steps: O(n 2 ). Space: O(n 2 ). Can we do better? Nanyang Technological University MAS 714 August 14, 2017 13 / 23

Number Multiplication Number of primitive steps: O(n 2 ). Space: O(n 2 ). Can we do better? Yes, but highly nontrivial. best known algorithm time: O(n log n 2 O(log n) ) [Furer 2008] previous best time: O(n log n log log n) [Schonhage-Strassen 1971] Conjecture: an O(n log n) time algorithm exists. We don t even understand multiplication well. Nanyang Technological University MAS 714 August 14, 2017 13 / 23

Independent Set Independent Set Input: an undirected graph G = (V, E). A set of nodes S V is independent if no two nodes in S are jointed by an edge. Problem: find an independent set that is as large as possible. Nanyang Technological University MAS 714 August 14, 2017 14 / 23

Independent Set Independent Set Input: an undirected graph G = (V, E). A set of nodes S V is independent if no two nodes in S are jointed by an edge. Problem: find an independent set that is as large as possible. Harder: no efficient algorithm is known. conjecture: no such algorithm exists On the good side: checking the validity of a solution is easy. Nanyang Technological University MAS 714 August 14, 2017 14 / 23

Hex (Board Game) Hex Rules: Players take turn placing a stone (of their color) on an unoccupied cell. Goal: Form a path of their own stones connecting the opposing side of the board marked by their colors. Problem: determine whether a position is a winning position. Nanyang Technological University MAS 714 August 14, 2017 15 / 23

Hex (Board Game) Hex Rules: Players take turn placing a stone (of their color) on an unoccupied cell. Goal: Form a path of their own stones connecting the opposing side of the board marked by their colors. Problem: determine whether a position is a winning position. Even harder: PSPACE-Complete even checking a solution is hard Nanyang Technological University MAS 714 August 14, 2017 15 / 23

Posts Correspondence Problem Posts Correspondence Problem Input: two sequences of strings. e.g. A = [a, ab, bba], B = [baa, aa, bb] Problem: Find a sequence of indices such that the corresponding concatenated strings are the same. e.g. (3, 2, 3, 1) = bba ab bba a = bb aa bb baa Nanyang Technological University MAS 714 August 14, 2017 16 / 23

Posts Correspondence Problem Posts Correspondence Problem Input: two sequences of strings. e.g. A = [a, ab, bba], B = [baa, aa, bb] Problem: Find a sequence of indices such that the corresponding concatenated strings are the same. e.g. (3, 2, 3, 1) = bba ab bba a = bb aa bb baa Even harder: Undecidable no algorithm exists! Nanyang Technological University MAS 714 August 14, 2017 16 / 23

Summary Algorithm design is not a piece of cake. Difficulty varies in different problems. Nanyang Technological University MAS 714 August 14, 2017 17 / 23

Basics of Algorithm Analysis Nanyang Technological University MAS 714 August 14, 2017 18 / 23

What is a good algorithm? Figure: All Rights Reserved http://www.cartoonbank.com Nanyang Technological University MAS 714 August 14, 2017 19 / 23

Algorithm Performance Efficiency What qualifies as an efficient algorithm? Most important factor: running time. Many possibilities: n, n log n, n 2, n 3, n 100, 2 n, n!, etc... Nanyang Technological University MAS 714 August 14, 2017 20 / 23

Algorithm Performance Efficiency What qualifies as an efficient algorithm? Most important factor: running time. Many possibilities: n, n log n, n 2, n 3, n 100, 2 n, n!, etc... Brute force: enumerate every possible solutions that check their validity. Usually takes at least 2 n time, is not considered as efficient. Nanyang Technological University MAS 714 August 14, 2017 20 / 23

Running Time Examples Nanyang Technological University MAS 714 August 14, 2017 21 / 23

Polynomial Running Time Efficient Algorithms An algorithm called efficient if it has a polynomial running time. Nanyang Technological University MAS 714 August 14, 2017 22 / 23

Polynomial Running Time Efficient Algorithms An algorithm called efficient if it has a polynomial running time. What is so good about polynomial running time? Robust, mathematically sound. When input size doubles, the running time only increases by some constant factor C. Works well in practice. Nanyang Technological University MAS 714 August 14, 2017 22 / 23

Polynomial Running Time Efficient Algorithms An algorithm called efficient if it has a polynomial running time. What is so good about polynomial running time? Robust, mathematically sound. When input size doubles, the running time only increases by some constant factor C. Works well in practice. Drawbacks: Polynomials with large constants/exponents are not that practical. 20n 100 or n 1+0.02 ln n? Nanyang Technological University MAS 714 August 14, 2017 22 / 23

Type of Analyses Running Time How to define the running time of an algorithm? Nanyang Technological University MAS 714 August 14, 2017 23 / 23

Type of Analyses Running Time How to define the running time of an algorithm? Worst-case. Running time guarantee for any input of size n. Nanyang Technological University MAS 714 August 14, 2017 23 / 23

Type of Analyses Running Time How to define the running time of an algorithm? Worst-case. Running time guarantee for any input of size n. Average-case. Expected running time for a random input of size n. Probabilistic. Expected running time of a randomized algorithm. Amortized. Worst-case running time for any sequence of n operations. Nanyang Technological University MAS 714 August 14, 2017 23 / 23