AlgoAnalysis

# AlgoAnalysis - Analysis of Algorithms Introduction and the...

This preview shows pages 1–7. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Analysis of Algorithms Introduction and the Asymptotic Notation c 2011 Aybar C. Acar & C ¸i˘ gdem G¨und¨uz Demir Compiled on: February 6, 2011 Analysis of Algorithms Introduction Analysis of Algorithms The theoretical study of the time and resource usage of a computer program. i.e. the analysis of performance Why is performance important? Can you think of anything more important than performance? Correctness Features Ease-of-use & user-friendliness Maintainability Development & operating cost Stability Then, why study algorithms and performance? Analysis of Algorithms Importance of Performance Performance is the currency you use to pay for more important things: Features Cheaper (less time & memory) features mean more features on the same hardware. Cost Faster and leaner programs require less hardware Faster algorithms require less programmer effort You can use high-level languages like Java or Python instead of, say, assembly (ouch!) User Friendliness If you have fast and lean algorithms you can build user-friendly features, like: GUI Spell-checkers and auto-complete Speech recognition Face detection Correctness & Stability Fast and well-analyzed algorithms are easier to verify. Analysis of Algorithms Sorting The problem of sorting: Oldest problem in the book. Given a sequence of items < a 1 , a 2 , . . . , a n > , Find a new permutation < a 1 , a 2 , . . . , a n > such that the new permutation is monotonically increasing ( a i- 1 ≤ a i ). Example You are dealt a set of playing cards. What is the first thing you do? Analysis of Algorithms Algorithm Definition An Algorithm is a finite list of specific instructions for calculating a desired output given a well-defined input value (or set of values). Formally, an algorithm has to be provably correct : must terminate successfully on all well-formed inputs (i.e., all instances of the problem), must produce the expected output for any given input, Correctness is verified by using invariants : An invariant is a condition that is true both at the beginning and end of a sequence of instructions. Analysis of Algorithms Insertion Sort Given a 0-indexed array of numbers, A , of length n , the algorithm InsertionSort ( A ) is: for j ← 1 to n- 1 do key ← A [ j ] i ← j- 1 while i ≥ 0 and A [ i ] > key do A [ i + 1] ← A [ i ] A [ i ] ← key i ← i- 1 end while end for Example What is the loop invariant for the outer loop?...
View Full Document

## This note was uploaded on 10/23/2011 for the course ENGINEERIN 102 taught by Professor Pablo during the Spring '11 term at Bilkent University.

### Page1 / 26

AlgoAnalysis - Analysis of Algorithms Introduction and the...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online