Complexity A decidable problem is computationally solvable. But what resources are needed to solve the problem? –How much time will it require? –How much.

Slides:



Advertisements
Similar presentations
CHAPTER 2 ALGORITHM ANALYSIS 【 Definition 】 An algorithm is a finite set of instructions that, if followed, accomplishes a particular task. In addition,
Advertisements

Lecture # 38 Algorithms & Problem Solving: How Hard Can it Get?
MAT 4 – Kompleks Funktionsteori MATEMATIK 4 INDUKTION OG REKURSION MM 1.5 MM 1.5: Kompleksitet Topics: Computational complexity Big O notation Complexity.
Fall 2006CENG 7071 Algorithm Analysis. Fall 2006CENG 7072 Algorithmic Performance There are two aspects of algorithmic performance: Time Instructions.
Tirgul 2 Asymptotic Analysis. Motivation: Suppose you want to evaluate two programs according to their run-time for inputs of size n. The first has run-time.
Introduction to Analysis of Algorithms
Complexity Analysis (Part I)
CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT Lecture 8+9 Time complexity 1 Jan Maluszynski, IDA, 2007
Tirgul 2 Asymptotic Analysis. Motivation: Suppose you want to evaluate two programs according to their run-time for inputs of size n. The first has run-time.
Analysis of Algorithms COMP171 Fall Analysis of Algorithms / Slide 2 Introduction * What is Algorithm? n a clearly specified set of simple instructions.
David Luebke 1 8/17/2015 CS 332: Algorithms Asymptotic Performance.
DATA STRUCTURES AND ALGORITHMS Lecture Notes 1 Prepared by İnanç TAHRALI.
Algorithm Analysis (Big O)
Algorithm Analysis. Algorithm Def An algorithm is a step-by-step procedure.
Time Complexity Dr. Jicheng Fu Department of Computer Science University of Central Oklahoma.
Analysis of Algorithm Lecture 3 Recurrence, control structure and few examples (Part 1) Huma Ayub (Assistant Professor) Department of Software Engineering.
Program Performance & Asymptotic Notations CSE, POSTECH.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved ADT Implementation:
1 Recursion Algorithm Analysis Standard Algorithms Chapter 7.
Mathematics Review and Asymptotic Notation
Algorithm Analysis An algorithm is a clearly specified set of simple instructions to be followed to solve a problem. Three questions for algorithm analysis.
Complexity Analysis Chapter 1.
Analysis of Algorithms
Analysis of Algorithm Efficiency Dr. Yingwu Zhu p5-11, p16-29, p43-53, p93-96.
1 COMP3040 Tutorial 1 Analysis of algorithms. 2 Outline Motivation Analysis of algorithms Examples Practice questions.
Introduction to Analysis of Algorithms COMP171 Fall 2005.
Algorithms Growth of Functions. Some Notation NNatural numbers RReal numbers N + Positive natural numbers R + Positive real numbers R * Non-negative real.
Program Efficiency & Complexity Analysis. Algorithm Review An algorithm is a definite procedure for solving a problem in finite number of steps Algorithm.
CSC310 © Tom Briggs Shippensburg University Fundamentals of the Analysis of Algorithm Efficiency Chapter 2.
Algorithm Analysis Part of slides are borrowed from UST.
Recursive Algorithms A recursive algorithm calls itself to do part of its work The “call to itself” must be on a smaller problem than the one originally.
Algorithm Analysis Algorithm Analysis Lectures 3 & 4 Resources Data Structures & Algorithms Analysis in C++ (MAW): Chap. 2 Introduction to Algorithms (Cormen,
David Luebke 1 1/6/2016 CS 332: Algorithms Asymptotic Performance.
Asymptotic Performance. Review: Asymptotic Performance Asymptotic performance: How does algorithm behave as the problem size gets very large? Running.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
1 Chapter 2 Algorithm Analysis All sections. 2 Complexity Analysis Measures efficiency (time and memory) of algorithms and programs –Can be used for the.
BITS Pilani Pilani Campus Data Structure and Algorithms Design Dr. Maheswari Karthikeyan Lecture1.
1 Chapter 2 Algorithm Analysis Reading: Chapter 2.
GC 211:Data Structures Week 2: Algorithm Analysis Tools Slides are borrowed from Mr. Mohammad Alqahtani.
CSE 3358 NOTE SET 2 Data Structures and Algorithms 1.
1 ADT Implementation: Recursion, Algorithm Analysis Chapter 10.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Recursion,
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 2.
Mathematical Foundations (Growth Functions) Neelima Gupta Department of Computer Science University of Delhi people.du.ac.in/~ngupta.
Data Structures I (CPCS-204) Week # 2: Algorithm Analysis tools Dr. Omar Batarfi Dr. Yahya Dahab Dr. Imtiaz Khan.
Algorithm Analysis 1.
Chapter 2 Algorithm Analysis
Analysis of Algorithms
GC 211:Data Structures Week 2: Algorithm Analysis Tools
Time complexity Here we will consider elements of computational complexity theory – an investigation of the time (or other resources) required for solving.
Introduction to Algorithms
Introduction Algorithms Order Analysis of Algorithm
GC 211:Data Structures Algorithm Analysis Tools
Recursive Thinking Chapter 9 introduces the technique of recursive programming. As you have seen, recursive programming involves spotting smaller occurrences.
Chapter 2 Fundamentals of the Analysis of Algorithm Efficiency
Recursive Thinking Chapter 9 introduces the technique of recursive programming. As you have seen, recursive programming involves spotting smaller occurrences.
Time Complexity Analysis Neil Tang 01/19/2010
Algorithm Analysis Neil Tang 01/22/2008
Algorithm Analysis (not included in any exams!)
CS 3343: Analysis of Algorithms
GC 211:Data Structures Algorithm Analysis Tools
CSCI 2670 Introduction to Theory of Computing
CSC 413/513: Intro to Algorithms
Introduction to Algorithms Analysis
CS 201 Fundamental Structures of Computer Science
Fundamentals of the Analysis of Algorithm Efficiency
Introduction to Algorithm and its Complexity Lecture 1: 18 slides
At the end of this session, learner will be able to:
Discrete Mathematics 7th edition, 2009
Fundamentals of the Analysis of Algorithm Efficiency
Presentation transcript:

Complexity A decidable problem is computationally solvable. But what resources are needed to solve the problem? –How much time will it require? –How much memory will it require? In this chapter, we study time complexity. Chapter 8 covers the space complexity of a problem. –Space corresponds to memory. –We do not cover space complexity; this topic is rarely covered in introductory theory courses.

Goal: transfer all n disks from peg A to peg C Rules: –move one disk at a time –never place larger disk above smaller one Recursive solution: –transfer n  1 disks from A to B –move largest disk from A to C –transfer n  1 disks from B to C Total number of moves: –T(n)  2T(n  1)  1 Towers of Hanoi

Towers of Hanoi (2) Recurrence relation: T(n)  2 T(n  1)  1 T(1)  1 Solution by unfolding: T(n) =  2 (2 T(n - 2) + 1) + 1 = = 4 T(n - 2) = = 4 (2 T(n - 3) + 1) = = 8 T(n - 3) =... = 2 i T(n - i) + 2 i-1 +2 i the expansion stops when i  n  1 T(n) = 2 n – n – n –

Towers of Hanoi (3) This is a geometric sum, so that we have T(n)  2 n  1 Good or bad news? –the Tibetans were confronted with a tower problem of 64 rings... –Assuming the priests move one ring per second, it would take ~585 billion years to complete the process!

Reasonable vs. Unreasonable Processing 1 elements takes 0.01 sec function/ n n2n2 1/10,000 second 1/2,500 second 1/400 second 1/100 second 9/100 second n5n5 1/10 second 3.2 seconds 5.2 minutes 2.8 hours 28.1 days 2n2n 1/1000 second 1 second 35.7 years 400 trillion centuries a 75 digit- number of centuries n 2.8 hours 3.3 trillion years a 70 digit- number of centuries a 185 digit- number of centuries a 728 digit- number of centuries Exponential Polynomial

Goals Basics of time complexity theory Introduce method for measuring the time needed to solve a problem. Show how to classify problems according to the amount of time required. Show that certain classes of problems require enormous amounts of time. We will also see how to determine whether we have this type of problem.

Language vs. Problem We will use “Language” and “Problem” interchangeably Any Problem can be converted to a Language, and vice-versa –Problem: Determine if a number is prime –Language: L = {p : p is prime } –Problem: Determine if a Turing Machine M halts on an input string w –Language: L = {e(M), e(w) : M halts on w}

Calculating Running Time of a Program To determine the total time  add up the time required for each statement. The running time of a simple statement is O(1). The running time of an if statement is the larger of the running times of the two branches, plus the time required to evaluate the condition The running time of a sequence of statements is the running time of the longest step. The running time of a loop is the time to execute one iteration times the number of iterations.

Why Algorithm Analysis Solve a problem on a computer  seek an algorithm that makes efficient use of the computer resources –time –space Algorithm analysis - mathematical approach to describe (in terms of the problem size): –The amount of resources used by the algorithm Space Computational (running) time –Running time: The number of primitive operations (steps) executed before termination –Order of growth The leading term of a formula Expresses the behavior of a function toward infinity

Slides

Asymptotic upper bound Suppose f and g are two nonnegative functions Definition [Big “oh”]: –f(n)=O(g(n)) iff. there exist positive constants c and n 0 such that f(n)≤ c g(n) for all n, n≥ n 0. Examples –3n+2=O(n) as 3n+2 ≤ 4n for n ≥ 2 –10n 2 +4n+2 = O(n 2 ) as 10n 2 +4n+2 ≤ 11n 2 for n ≥ 5 g(n) should be as small as possible –f(n) = O(n 2 ) –f(n) = O(n)

Logarithms The notation "ln(x)" means loge(x); The notation "lg(x)" means log10(x); The notation "lb(x)" means log2(x).

Logarithms

Towers of Hanoi (3) This is a geometric sum, so that we have T(n)  2 n  1  O(2 n ) The running time of this algorithm is exponential (k n ) rather than polynomial (n k ), where n is input size. Good or bad news? –the Tibetans were confronted with a tower problem of 64 rings... –Assuming the priests move one ring per second, it would take ~585 billion years to complete the process!