+ All Categories
Home > Documents > TIME COMPLEXITY

TIME COMPLEXITY

Date post: 23-Jan-2016
Category:
Upload: orrin
View: 24 times
Download: 1 times
Share this document with a friend
Description:
TIME COMPLEXITY. Pages 247 - 256. Introduction. Even when a problem: is decidable and computationally solvable it may not be solvable in practice if the solution requires an inordinate amount of time or memory. Objectives. investigation of the: time , memory , or - PowerPoint PPT Presentation
30
TIME COMPLEXITY 1
Transcript
Page 1: TIME COMPLEXITY

1

TIME COMPLEXITY

Page 2: TIME COMPLEXITY

2

Pages 247 - 256

Page 3: TIME COMPLEXITY

3

Introduction

• Even when a problem:- is decidable and- computationally solvable

• it may not be solvable in practice if the solution requires an inordinate amount of time or memory.

Page 4: TIME COMPLEXITY

4

Objectives

• investigation of the:- time, - memory, or - Other resources required for solving

computational problems.

• to present the basics of time complexity theory.

Page 5: TIME COMPLEXITY

5

Objectives (cont.)

• First - introduce a way of measuring the time used to solve a problem.

• Then - show how to classify problems according to the amount of time required.

• After - discuss the possibility that certain decidable problems require enormous amounts of time and how to determine when you are faced with such a problem.

Page 6: TIME COMPLEXITY

6

MEASURING COMPLEXITY

The language

Page 7: TIME COMPLEXITY

7

MEASURING COMPLEXITY (cont.)

• How much time does a single-tape Turing machine need to decide A?

Page 8: TIME COMPLEXITY

8

• The number of steps that an algorithm uses on a particular input may depend on several parameters: (if the input is a graph)

- the number of steps may depend on :- the number of nodes, - the number of edges, and - the maximum degree of the graph, or - some combination of these and/or other

factors.

MEASURING COMPLEXITY (cont.)

Page 9: TIME COMPLEXITY

9

Analysis

• worst-case analysis - consider the longest running time of all inputs of a particular length.

• average-case analysis - consider the average of all the running times of inputs of a particular length.

Page 10: TIME COMPLEXITY

10

Page 11: TIME COMPLEXITY

11

BIG-O AND SMALL-O NOTATION

• Exact running time of an algorithm often is a complex expression. (estimation)

• Asymptotic analysis - seek to understand the running time of the algorithm when it is run on large inputs.

The asymptotic notation or big-O notation fordescribing this relationship is

Page 12: TIME COMPLEXITY

12

Self study

• EXAMPLE 7.3

• EXAMPLE 7.4

Page 13: TIME COMPLEXITY

13

BIG-O AND SMALL-O NOTATION (cont.)

• Performing this scan uses n steps. • Typically use n to represent the length of the

input. • Repositioning the head at the left-hand end of

the tape uses another n steps. • The total used in this stage is 2n steps.

In stage 1

Page 14: TIME COMPLEXITY

14

BIG-O AND SMALL-O NOTATION (cont.)

In stage 4 the machine makes a single scan to decide whether to accept or reject. The time taken in this stage is at most O(n).

Page 15: TIME COMPLEXITY

15

• Thus the total time of M1 on an input of length n is

O(n) + O(n2 ) + O(n) or O(n2 ).

In other words, it's running time is O(n2 ), which completes the time analysis of this machine.

BIG-O AND SMALL-O NOTATION (cont.)

Page 16: TIME COMPLEXITY

16

Page 17: TIME COMPLEXITY

17

Is there a machine that decides A asymptotically more quickly?

Page 18: TIME COMPLEXITY

18

Executed Time

• Stages 1 and 5 are executed once, taking a total of O(n) time.

• Stage 4 crosses off at least half the 0s and 1s is each time it is executed, so at most 1+log2 n.

• the total time of stages 2, 3, and 4 is (1 + log2 n)O(n), or O(n log n).

• The running time of M2 is O(n) + O (n logn) = O(n log n).

Page 19: TIME COMPLEXITY

19

COMPLEXITY RELATIONSHIPS AMONG MODELS

• We consider three models: - the single-tape Turing machine;- the multi-tape Turing machine; and - the nondeterministic Turing machine

Page 20: TIME COMPLEXITY

20

• convert any multi-tape TM into a single-tape TM that simulates it.

• Analyze that simulation to determine how much additional time it requires.

• simulating each step of the multi-tape machine uses at most O(t(n)) steps on the single-tape machine.

• the total time used is O(t2 (n)) steps.O(n) + O(t2 (n)) running time O(t2 (n))

COMPLEXITY RELATIONSHIPS AMONG MODELS (cont.)

Page 21: TIME COMPLEXITY

21

SPACE COMPLEXITY I N T R A C T A B I L I T Y

Page 22: TIME COMPLEXITY

22

Pages 303 – 308

Page 23: TIME COMPLEXITY

23

Objective

• Consider the complexity of computational problems in terms of the amount of space, or memory, that they require.

• Time and space are two of the most important considerations when we seek practical solutions to many computational problems.

• Space complexity shares many of the features of time complexity and serves as a further way of classifying problems according to their computational difficulty.

Page 24: TIME COMPLEXITY

24

Introduction

• select a model for measuring the space used by an algorithm.

• Turing machines are mathematically simple and close enough to real computers to give meaningful results.

Page 25: TIME COMPLEXITY

25

Page 26: TIME COMPLEXITY

26

Estimation the space complexity

• We typically estimate the space complexity of Turing machines by using asymptotic notation.

• EXAMPLE 8.3

Page 27: TIME COMPLEXITY

27

EXAMPLE 8.4

Page 28: TIME COMPLEXITY

28

SAVITCH'S THEOREM read only

Page 29: TIME COMPLEXITY

29

Pages 335 - 338

I N T R A C T A B I L I T Y

Page 30: TIME COMPLEXITY

30

• Certain computational problems are solvable in principle, but the solutions require so much time or space that they can't be used in practice. Such problems are called intractable.

• Turing machines should be able to decide more languages in time n3 than they can in time n2. The hierarchy theorems prove that .


Recommended