This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full 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 Easeofuse & userfriendliness 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 highlevel languages like Java or Python instead of, say, assembly (ouch!) User Friendliness If you have fast and lean algorithms you can build userfriendly features, like: GUI Spellcheckers and autocomplete Speech recognition Face detection Correctness & Stability Fast and wellanalyzed 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 welldefined input value (or set of values). Formally, an algorithm has to be provably correct : must terminate successfully on all wellformed 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 0indexed 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.
 Spring '11
 Pablo
 Algorithms

Click to edit the document details