design and analysis of algorithms - abstract view

12
Design and Analysis of Algorithms Waqas Nawaz, Ph.D. Innopolis University, Russia

Upload: waqas-nawaz

Post on 19-Jan-2017

313 views

Category:

Education


0 download

TRANSCRIPT

Page 1: Design and analysis of algorithms - Abstract View

Design and Analysis of AlgorithmsWaqas Nawaz, Ph.D.Innopolis University, Russia

Page 2: Design and analysis of algorithms - Abstract View

2 Outline

Introduction Motivation Designing an Algorithm Analysis of Algorithms Conclusion References

Page 3: Design and analysis of algorithms - Abstract View

3 Introduction Algorithm

A set of well defined rules to solve a computation problem Specific examples: Find Minimum! and Multiplication

Design: the description of algorithm (pseudo language) and proof of its correctness

Analysis: performance evaluation (complexity analysis)

AlgorithmInput Output

American British

input

output

N1 N2

Page 4: Design and analysis of algorithms - Abstract View

4 Motivation: Algorithm Efficiency vs. CPU Speed Task: Sort n=106 numbers

Computer A = 109 instructions/second Algorithm A = 2n2 instructions

Computer B = 107 instructions/second Algorithm B = 50nlgn instructions

A =

B =

seconds2000second/nsinstructio10nsinstructio102

9

26

seconds100second/nsinstructio10

nsinstructiolg1010507

66

20 times better!!

Page 5: Design and analysis of algorithms - Abstract View

5 Algorithm Design Techniques

Brute Force & Exhaustive Search follow definition / try all

possibilities Divide & Conquer

break problem into distinct subproblems

Transformation convert problem to another

one

Dynamic Programming break problem into overlapping

subproblems Greedy

repeatedly do what is best now Iterative Improvement

repeatedly improve current solution

Randomization use random numbers

Page 6: Design and analysis of algorithms - Abstract View

6 Analysis of Algorithms Worst case: (e.g. cards reversely

ordered) Provides an upper bound on running time An absolute guarantee that the algorithm

would not run longer, no matter what the inputs are

Best case: (e.g., cards already ordered) Input is the one for which the algorithm runs

the fastest Average case: (general case)

Provides a prediction about the running time Assumes that the input is random

2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K, A

Page 7: Design and analysis of algorithms - Abstract View

7 Conclusion We studied the importance of designing and analysis of

algorithm Different methods and approaches are discussed to create and

evaluate an algorithm It helps us to utilize resources effectively to achieve desired

results in a reasonable time

Related Study Materials Text Books

Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest and Clifford Stein, Introduction to Algorithms, Third Edition, 2009.

Kleinberg and Tardos, Algorithm Design, 2005. Online Lectures by Tim Roughgarden on Algorithms: Design and

Analysis, Part 1, Stanford University

Page 8: Design and analysis of algorithms - Abstract View

8 References

1. Adil Khan, Course slides on Data structure and algorithms, Innopolis University, 2016.

2. Monica Nicolescu, course slides on Analysis of AlgorithmsCS 477/677.

3. Arjun Dasgupta et. al., CSE5311, DESIGN AND ANALYSIS OF ALGORITHMS.

4. Jennifer Welch, CSCE 411, Design and Analysis of Algorithms, 2013.

5. Anany Levitin, Fundamentals of the Analysis of Algorithm Efficiency, 2nd edition, chapter 2.

Page 9: Design and analysis of algorithms - Abstract View

9 Appendix: Farmer Crosses River Puzzle A farmer wants to cross a river

and take with him a wolf, a goat, and a cabbage.

There is a boat that can fit himself plus either the wolf, the goat, or the cabbage. If the wolf and the goat are alone on

one shore, the wolf will eat the goat. If the goat and the cabbage are

alone on the shore, the goat will eat the cabbage.

How can the farmer bring the wolf, the goat, and the cabbage across the river?

Page 10: Design and analysis of algorithms - Abstract View

10 Appendix: Our Machine Model

RAM: Generic Random Access Machine Executes operations sequentially Set of primitive operations:

Arithmetic. Logical, Comparisons, Function calls

Simplifying assumption: all ops cost 1 unit Eliminates dependence on the speed of our computer,

otherwise impossible to verify and to compare

Page 11: Design and analysis of algorithms - Abstract View

Sample Algorithm

FINDING LARGEST NUMBERINPUT: unsorted array ‘A[n]’of n numbersOUTPUT: largest number----------------------------------------------------------1 large ← A[j]2 for j ← 2 to length[A]3 if large < A[j]4 large ← A[j]5 end

Page 12: Design and analysis of algorithms - Abstract View

Space and Time Analysis(Largest Number Scan Algorithm)

SPACE S(n): One “word” is required to run the algorithm (step 1…to store variable ‘large’)

TIME T(n): n-1 comparisons are required to find the largest (every comparison takes one cycle)

running timeexecution timefor basic operation

Number of times basic op-eration is exe-cuted

input size

T(n) ≈ copC(n)