CS 310 – Fall 2006 Pacific University CS310 Complexity Section 7.1 November 27, 2006.

Slides:



Advertisements
Similar presentations
Measuring Time Complexity
Advertisements

CSE 373: Data Structures and Algorithms Lecture 5: Math Review/Asymptotic Analysis III 1.
INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011.
Estimating Running Time Algorithm arrayMax executes 3n  1 primitive operations in the worst case Define a Time taken by the fastest primitive operation.
The diagonalization method The halting problem is undecidable Decidability.
Computability and Complexity 22-1 Computability and Complexity Andrei Bulatov Hierarchy Theorem.
Measuring Time Complexity Sipser 7.1 (pages )
P and NP Sipser (pages ). CS 311 Fall Polynomial time P = ∪ k TIME(n k ) … P = ∪ k TIME(n k ) … TIME(n 3 ) TIME(n 2 ) TIME(n)
More Turing Machines Sipser 3.2 (pages ). CS 311 Fall Multitape Turing Machines Formally, we need only change the transition function to.
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY Read sections 7.1 – 7.3 of the book for next time.
CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT Lecture 8+9 Time complexity 1 Jan Maluszynski, IDA, 2007
CS 310 – Fall 2006 Pacific University CS310 P vs NP the steel cage death match Section 7.2 November 29, 2006.
Asymptotic Analysis Motivation Definitions Common complexity functions
Data Structures and Algorithms1 Basics -- 2 From: Data Structures and Their Algorithms, by Harry R. Lewis and Larry Denenberg (Harvard University: Harper.
Prof. Amr Goneid, AUC1 Analysis & Design of Algorithms (CSCE 321) Prof. Amr Goneid Department of Computer Science, AUC Part 2. Types of Complexities.
Lecture 3 Feb 7, 2011 Goals: Chapter 2 (algorithm analysis) Examples: Selection sorting rules for algorithm analysis Image representation Image processing.
Algorithm analysis and design Introduction to Algorithms week1
CS 461 – Nov. 21 Sections 7.1 – 7.2 Measuring complexity Dividing decidable languages into complexity classes. Algorithm complexity depends on what kind.
Week 2 CS 361: Advanced Data Structures and Algorithms
Mathematics Review and Asymptotic Notation
Lower Bounds on the Time-complexity of Non-regular Languages on One-tape Turing Machine Miaohua Xu For Theory of Computation II Professor: Geoffrey S.
Analysis of Algorithms
Mathematical Preliminaries The Factorial Function Permutations Logarithms Summations Recurrence Relations Algorithm Analysis.
CS 221 Analysis of Algorithms Instructor: Don McLaughlin.
Asymptotic Analysis-Ch. 3
Computer Language Theory
Analysis of Algorithms [ Section 4.1 ] Examples of functions important in CS: the constant function:f(n) =
Introduction to Programming (in C++) Complexity Analysis of Algorithms
Algorithm Analysis CS 400/600 – Data Structures. Algorithm Analysis2 Abstract Data Types Abstract Data Type (ADT): a definition for a data type solely.
Measuring complexity Section 7.1 Giorgi Japaridze Theory of Computability.
General rules: Find big-O f(n) = k = O(1) f(n) = a k n k + a k-1 n k a 1 n 1 + a 0 = O(n k ) Other functions, try to find the dominant term according.
Hierarchy theorems Section 9.1 Giorgi Japaridze Theory of Computability.
13 February 2016 Asymptotic Notation, Review of Functions & Summations.
A Introduction to Computing II Lecture 5: Complexity of Algorithms Fall Session 2000.
Computability Sort homework. Formal definitions of time complexity. Big 0. Homework: Exercises. Searching. Shuffling.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
1 Section 5.6 Comparing Rates of Growth We often need to compare functions ƒ and g to see whether ƒ(n) and g(n) are about the same or whether one grows.
Complexity of Algorithms Fundamental Data Structures and Algorithms Ananda Guna January 13, 2005.
CSE 3358 NOTE SET 2 Data Structures and Algorithms 1.
Theory of Computational Complexity TA : Junichi Teruyama Iwama lab. D3
CSCI 2670 Introduction to Theory of Computing November 15, 2005.
 2005 SDU Lecture14 Mapping Reducibility, Complexity.
CSCI 2670 Introduction to Theory of Computing
Analysis of Algorithms
Time complexity Here we will consider elements of computational complexity theory – an investigation of the time (or other resources) required for solving.
Analysis of Algorithms
Asymptotic Analysis.
Introduction to Algorithms
Algorithm Analysis (not included in any exams!)
CSCI 2670 Introduction to Theory of Computing
Intro to Theory of Computation
Complexity Analysis of Algorithms
Asymptotic Analysis.
Chapter 2: Fundamentals of the Analysis of Algorithm Efficiency
Chapter 14 Time Complexity.
Analysis of Algorithms
Advanced Analysis of Algorithms
CS21 Decidability and Tractability
Theory of Computability
CSE 373, Copyright S. Tanimoto, 2002 Asymptotic Analysis -
CS154, Lecture 12: Time Complexity
CSC 4170 Theory of Computation Time complexity Section 7.1.
At the end of this session, learner will be able to:
Theory of Computability
CSE 373, Copyright S. Tanimoto, 2001 Asymptotic Analysis -
CSCI 2670 Introduction to Theory of Computing
Advanced Analysis of Algorithms
CSC 4170 Theory of Computation Time complexity Section 7.1.
Analysis of Algorithms
Intro to Theory of Computation
Presentation transcript:

CS 310 – Fall 2006 Pacific University CS310 Complexity Section 7.1 November 27, 2006

CS 310 – Fall 2006 Pacific University Running time A = {0 K 1 K | k >=0 } –TM, M, can decide this language –how long (how many steps?) will it take a single-tape TM to accept or reject a string? The running time of M is a function where f(n) is the max. number of steps that M requires on any input of length n –worst case running time M is a “f(n) time TM” –TM is our model for computation, so –TM  algorithm

CS 310 – Fall 2006 Pacific University Example f(n) = 5n 3 + 4n 2 + 6n + 1 –for large n, 5n 3 dominates this equation –coefficient 5 is immaterial –we say f(n) = n 3 –the goal here is to see how the running time grows as n increases

CS 310 – Fall 2006 Pacific University Big Oh Asymptotic analysis –estimate runtime of algorithm (or TM) on large inputs –only look at highest order term –allows us to compare runtime of two algorithms

CS 310 – Fall 2006 Pacific University Definition: Big Oh f, g are functions: f,g: N  R + f(n) = O(g(n)) if positive ints c and n 0 exist such that for every int n >= n 0 f(n) <= c*g(n) g(n) is an asymptotic upper bound for f(n) some constant multiple of g(n) eventually dominates f(n)

CS 310 – Fall 2006 Pacific University Example f(n) = 5n 3 + 2n n + 6 O(f(n)) = n 3 let c = 6 and n 0 = 10 5n 3 + 2n n + 6 <= 6n 3 –for every n >= n 0 O(f(n)) = n 4 as well, but we want the tightest upper bound

CS 310 – Fall 2006 Pacific University Logarithms if x = log 2 n then 2 x = n so log b 2 x = log b n so x log b 2 = log b n so x = (log b n) / (log b 2) so log b (n) = O(log 2 n) for any base because log b 2 is a constant

CS 310 – Fall 2006 Pacific University Example f(n) = 3n log 2 n + 5nlog 2 (log 2 n) + 2 f(n) = O(g(n)) = ? Since log 2 n <= n then log 2 (log 2 n) <= log 2 (n) so f(n) = O(n log 2 n)

CS 310 – Fall 2006 Pacific University Analyzing Algorithms A = {0 k 1 k | k>=0} on input of length n: 1) scan, reject if 0 found to right of a 1 2) if both 0’s and 1’s remain, scan, cross off single 0, single 1 3) if 0’s remain after 1’s crossed off or conversely, reject. otherwise accept.

CS 310 – Fall 2006 Pacific University Analysis Step 1: scan, verify: n steps forward, n steps back: 2n steps so O(n) Step 2: scan, cross off 0 and 1 each scan. Each scan uses O(n) steps, n/2 scans at most, so O(n 2 ) Step 3: Scan, accept or reject O(n) Total: O(n) + O(n 2 ) + O(n) –O(n 2 )

CS 310 – Fall 2006 Pacific University Algorithm Can we write an algorithm that runs better than O(n 2 )? 1) Scan across the tape, reject is a 0 is found to the right of a 1 2) Repeat as long as some 0s and 1s remain: 2a) Scan across the tape checking if the total number of 1s and 0s is even or odd. if odd, reject. 2b) Scan across the tape, crossing off every other 0 starting with the first 0 and then crossing off every other 1 starting with the first 1. 3) if no 0s and no 1s remain, accept. Otherwise reject. Analysis?

CS 310 – Fall 2006 Pacific University Algorithm If we had a two tape TM, could we do this in O(n)? –linear time?

CS 310 – Fall 2006 Pacific University Complexity relationships between models Theorem 7.8: let t(n) >= n, every t(n) time multitape TM has an equivalent O((t(n) 2 ) time single-tape TM. Theorem 7.9: Every t(n) >= n time ND single tape TM has an equivalent 2 O(t(n)) time deterministic single tape TM