- 93 Views
- Uploaded on
- Presentation posted in: General

Algorithm Design and Analysis

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Algorithm Design and Analysis

Liao Minghong

School of Computer Science and Technology of HIT

July, 2003

- Course Name: Algorithm Design and Analysis
- Course Type: Selected Undergraduate Course
- Teaching hours: 30
- Teaching materials: Algorithms Design Techniques and Analysis, M. H. Alsuwaiyel, Publishing House of Electronics Industry, 2003

- Thomas H.Cormen, et al., Introduction to Algorithms, Higher Education Press, The MIT Press, 2002
- 王晓东，算法设计与分析，清华大学出版社，2003.1

- Part 1: Basic Concepts and Introduction to Algorithms
- Part 2: Techniques Based on Recursion
- Part 3: First-Cut Techniques
- Part 4: Complexity of Problems
- Part 5: Coping with Hardness

- Chapter 1:Basic Concepts in Algorithmic Analysis
- Chapter 2: Mathematical Preliminaries
- Chapter 3: Data Structure
- Chapter 4: Heaps and the Disjoint Sets Structures

- Chapter 5: Introduction
- Chapter 6: Divide and Conquer
- Chapter 7: Dynamic Programming

- Chapter 8: The Greedy Approach
- Chapter 9: Graph Traversal

- Chapter 10: NP-Complete Problems
- Chapter 11: Introduction to computational complexity
- Chapter 12: Lower Bounds

- Chapter 13: Backtracking
- Chapter 14: Randomized Algorithms
- Chapter 15: Approximation Algorithms

- Basic Concepts of Algorithms
- Time Complexity
- How to Estimate the running Time of an Algorithm
- Worst case and average case analysis
- Amortized analysis

- Architecture of Computational Science

Process of solving problem

problem

computability

complexity

Algorithms

programming

Software system

Architecture

Computability theory

Computable & non computable

Computational model

Equivalence of model

Complexity theory

Worst case

Best case

Average case

P =? NP

Algorithms design & analysis

Design algorithms

Analysis technique

Optimal algorithms

C language

Java language

…

- Algorithm: is a procedure that consists of a finite set of instructions which, given an input from some set of possible inputs,enables us to obtain an output if such an output exists or else obtain nothing at all if there is no output for that particular input through a systematic execution of the instructions.

- Characteristics of Algorithms
- Corrective
- Concrete steps
- Determinative
- Limited
- Halted

- Linear Search
- Binary Search
- Selection sort
- Insertion sort
- Merge Sort
- Quick sort
- Etc.

- Order of growth
- The O-notation
- The Ω-notation
- The Θ-notation
- The o-notation

- Definition1.1 elementary operation
We denote by an “elementary operation” any computational step whose cost is always upperbounded by a constant amount of time regardless of the input data or the algorithm used.

Fig. 1.5 growth of some typical functions that represent running times

Definition 1.2 The O-notation

Let f(n) and g(n) be the functions from the set of natural numbers to the set of nonnegative real numbers. f(n) is said to be O(g(n)) if there exists a natural number n0 and a constant c>0 such that

n>=n0, f(n)<=cg(n).

Consequently, if lim f(n)/g(n) exists, then

lim , implies f(n)=O(g(n))

Definition 1.3 The Ω-notation

Let f(n) and g(n) be two functions from the set of natural numbers to the set of nonnegative real numbers. f(n) is said to be Ω(g(n)) if there exists a natural number n0 and a constant c>0 such that

n>=n0, f(n)>=cg(n).

Consequently, if lim f(n)/g(n) exists, then

lim , implies f(n)= Ω(g(n))

Definition 1.4 The Θ-notation

Let f(n) and g(n) be two functions from the set of natural numbers to the set of nonnegative real numbers. f(n) is said to be Θ(g(n)) if there exists a natural number n0 and two positive constants c1 and c2 such that

n>=n0, c1g(n)<=f(n)<=c2g(n).

Consequently, if lim f(n)/g(n) exists, then

Lim , implies f(n)= Θ(g(n))

Where c is a constant strictly greater than 0.

Definition 1.5 The o-notation

Let f(n) and g(n) be the functions from the set of natural numbers to the set of nonnegative real numbers. f(n) is said to be o(g(n)) if for every constant c>0 there exists a positive integer n0 such that f(n)<=cg(n) for all n>=n0.

Consequently, if lim f(n)/g(n) exists, then

Lim , implies f(n)=o(g(n))

Definition 1.6 Complexity Classes

Let R be the relation on the set of complexity functions defined by f R g if and only if f(n)= Θ(g(n)). It is easy to see that R is reflexive, symmetric and transitive, i.e., an equivalence relation. The equivalence classes induced by this relation are called complexity classes.

e.g. all polynomials of degree 2 belong to the same complexity class n2 .

Definition 1.7 Space Complexity

We define the space used by an algorithm to be the number of memory cells needed to carry out the computational steps required to solve an instance of the problem excluding the space allocated to hold the input.

All definition of order of growth and asymptotic bounds pertaining to time complexity carry over to space complexity.

Let T(n) and S(n) denote, respectively, the time and space complexity of an algorithm, then S(n)=O(T(n))

- In worst case analysis of time complexity we select the maximum cost among all possible inputs of size n.
- Under the worst case assumption, the notions of upper and lower bounds in many algorithms coincide and, consequently, we may say that an algorithm runs in time Θ(f(n)) in the worst case. But the upper and lower bounds are not always coincide.

- The running time is taken to be the average time over all inputs of size n.
- It is necessary to know the probabilities of all input occurrences.
- The analysis is in many cases complex and lengthy

- Unable to express the time complexity in terms of the Θ-notation,we will be content with the O-notation, but the algorithm may be much faster than our estimate even in the worst case.
- If the operation takes a large amount of time occasionally and runs much faster most of the time, then this is an indication that amortized analysis should be employed.

- In amortized analysis, we average out the time taken by the operation throughout the execution of the algorithm, and refer to this average as the amortized running time of that operation.
- Different with average case analysis:
- The average is taken over all instances of the same size.
- The average need to assume that the probability distribution of the input.

- Example 1.32
We have a doubly linked list that initially consists of one node which contains the integer 0. We have as input an array A[1..n] of n positive integers that are to be processed in the following way. If the current integer x is odd, then append x to the list. If it is even, then first append x and then remove all odd elements before x in the list. Let us analyze the running time of this algorithm.

- The algorithm:
for j = 1 to n

x=a[j]

append x to the list

if x is even then

while pred(x) is odd

delete pred(x)

end while

end if

end for

- Time complexity analysis:
- General analysis: O(n2)
- Amortized analysis: Θ(n)
(number of insertions: n, and the number of deletions: 0~n-1, so the total operations: n~2n-1)