I Advanced Algorithms Analysis. What is Algorithm?  A computer algorithm is a detailed step-by-step method for solving a problem by using a computer.

Slides:



Advertisements
Similar presentations
Analysis of Computer Algorithms
Advertisements

Razdan with contribution from others 1 Algorithm Analysis What is the Big ‘O Bout? Anshuman Razdan Div of Computing.
Computational Complexity 1. Time Complexity 2. Space Complexity.
What is an Algorithm? (And how do we analyze one?)
Introduction to Analysis of Algorithms
Complexity Analysis (Part I)
1 Data Structures A program solves a problem. A program solves a problem. A solution consists of: A solution consists of:  a way to organize the data.
Cmpt-225 Algorithm Efficiency.
CS3381 Des & Anal of Alg ( SemA) City Univ of HK / Dept of CS / Helena Wong 2. Analysis of Algorithms - 1 Analysis.
Analysis of Algorithms COMP171 Fall Analysis of Algorithms / Slide 2 Introduction * What is Algorithm? n a clearly specified set of simple instructions.
Design & Analysis of Algorithms Introduction. Introduction Algorithms are the ideas behind computer programs. An algorithm is the thing which stays the.
Instructor Neelima Gupta
Time Complexity Dr. Jicheng Fu Department of Computer Science University of Central Oklahoma.
Program Performance & Asymptotic Notations CSE, POSTECH.
CSC 201 Analysis and Design of Algorithms Lecture 03: Introduction to a CSC 201 Analysis and Design of Algorithms Lecture 03: Introduction to a lgorithms.
Week 2 CS 361: Advanced Data Structures and Algorithms
Lecture 2 Computational Complexity
Algorithm Efficiency CS 110: Data Structures and Algorithms First Semester,
Mathematics Review and Asymptotic Notation
1 Computer Algorithms Lecture 3 Asymptotic Notation Some of these slides are courtesy of D. Plaisted, UNC and M. Nicolescu, UNR.
Algorithm Analysis An algorithm is a clearly specified set of simple instructions to be followed to solve a problem. Three questions for algorithm analysis.
Analysis of Algorithms
CS 221 Analysis of Algorithms Instructor: Don McLaughlin.
Analysis of Algorithms These slides are a modified version of the slides used by Prof. Eltabakh in his offering of CS2223 in D term 2013.
Analyzing algorithms & Asymptotic Notation BIO/CS 471 – Algorithms for Bioinformatics.
CMPT 438 Algorithms. Why Study Algorithms? Necessary in any computer programming problem ▫Improve algorithm efficiency: run faster, process more data,
Major objective of this course is: Design and analysis of modern algorithms Different variants Accuracy Efficiency Comparing efficiencies Motivation thinking.
Design & Analysis of Algorithms Lecture 1 Introduction.
Program Efficiency & Complexity Analysis. Algorithm Review An algorithm is a definite procedure for solving a problem in finite number of steps Algorithm.
MS 101: Algorithms Instructor Neelima Gupta
MS 101: Algorithms Instructor Neelima Gupta
Algorithm Analysis CS 400/600 – Data Structures. Algorithm Analysis2 Abstract Data Types Abstract Data Type (ADT): a definition for a data type solely.
Algorithms and data structures: basic definitions An algorithm is a precise set of instructions for solving a particular task. A data structure is any.
CSC – 332 Data Structures Generics Analysis of Algorithms Dr. Curry Guinn.
Introduction to Analysis of Algorithms CS342 S2004.
COSC 3101A - Design and Analysis of Algorithms 2 Asymptotic Notations Continued Proof of Correctness: Loop Invariant Designing Algorithms: Divide and Conquer.
1 Algorithms  Algorithms are simply a list of steps required to solve some particular problem  They are designed as abstractions of processes carried.
Asymptotic Notations By Er. Devdutt Baresary. Introduction In mathematics, computer science, and related fields, big O notation describes the limiting.
1/6/20161 CS 3343: Analysis of Algorithms Lecture 2: Asymptotic Notations.
Asymptotic Performance. Review: Asymptotic Performance Asymptotic performance: How does algorithm behave as the problem size gets very large? Running.
E.G.M. PetrakisAlgorithm Analysis1  Algorithms that are equally correct can vary in their utilization of computational resources  time and memory  a.
Lecture # 1 Introduction Analysis of Algorithm by Qamar Abbas Analysis of Algorithms.
Onlinedeeneislam.blogspot.com1 Design and Analysis of Algorithms Slide # 1 Download From
Big O David Kauchak cs302 Spring Administrative Assignment 1: how’d it go? Assignment 2: out soon… Lab code.
BITS Pilani Pilani Campus Data Structure and Algorithms Design Dr. Maheswari Karthikeyan Lecture1.
1 Chapter 2 Algorithm Analysis Reading: Chapter 2.
Complexity of Algorithms Fundamental Data Structures and Algorithms Ananda Guna January 13, 2005.
Ch03-Algorithms 1. Algorithms What is an algorithm? An algorithm is a finite set of precise instructions for performing a computation or for solving a.
Chapter 3 Chapter Summary  Algorithms o Example Algorithms searching for an element in a list sorting a list so its elements are in some prescribed.
1.  A step by step process to solve any problem is called algorithm.  Algorithm is a process which take some values as input and provide us output.
GC 211:Data Structures Week 2: Algorithm Analysis Tools Slides are borrowed from Mr. Mohammad Alqahtani.
Advanced Algorithms Analysis and Design
FURQAN MAJEED ALGORITHMS. A computer algorithm is a detailed step-by-step method for solving a problem by using a computer. An algorithm is a sequence.
Data Structures I (CPCS-204) Week # 2: Algorithm Analysis tools Dr. Omar Batarfi Dr. Yahya Dahab Dr. Imtiaz Khan.
CMPT 438 Algorithms.
Design and Analysis of Algorithms
Advanced Algorithms Analysis and Design
Analysis of Algorithms
Introduction to Algorithms
Algorithms Furqan Majeed.
CS 3343: Analysis of Algorithms
Algorithm Analysis (not included in any exams!)
Objective of This Course
CSC 413/513: Intro to Algorithms
Introduction to Algorithms Analysis
Chapter 2.
Algorithm Analysis and Design
Algorithm Analysis, Asymptotic notations CISC4080 CIS, Fordham Univ.
David Kauchak cs161 Summer 2009
Estimating Algorithm Performance
Presentation transcript:

I Advanced Algorithms Analysis

What is Algorithm?  A computer algorithm is a detailed step-by-step method for solving a problem by using a computer.  An algorithm is a sequence of unambiguous instructions for solving a problem in a finite amount of time.  An Algorithm is well defined computational procedure that takes some value, or set of values, as input and produces some value, or set of values as output.  More generally, an Algorithm is any well defined computational procedure that takes collection of elements as input and produces a collection of elements as output.

Popular Algorithms, Factors of Dependence  Most basic and popular algorithms are  Sorting algorithms  Searching algorithms Which algorithm is best?  Mainly, it depends upon various factors, for example in case of Sorting :  The number of items to be sorted  The extent to which the items are already sorted  Possible restrictions on the item values  The kind of storage device to be used etc.

One Problem, Many Algorithms Problem  The statement of the problem specifies, in general terms, the desired input/output relationship. Algorithm  The algorithm describes a specific computational procedure for achieving input/output relationship. Example  One might need to sort a sequence of numbers into non- decreasing order. Algorithms  Various algorithms e.g. Merge sort, Quick sort, Heap sort etc.

Roadmap  Different problems  Sorting  Searching  String processing  Graph problems  Geometric problems  Numerical problems Different design paradigms – Divide-and-conquer – Incremental – Dynamic programming – Greedy algorithms – Randomized/probabilistic – NP Completeness

Important Designing Techniques  Brute Force  Straightforward, naive approach  Mostly expensive  Divide-and-Conquer  Divide into smaller sub-problems  Iterative Improvement  Improve one change at a time  Decrease-and-Conquer  Decrease instance size  Transform-and-Conquer  Modify problem first and then solve it  Space and Time Tradeoffs  Use more space now to save time later

Important Designing Techniques  Greedy Approach  Locally optimal decisions, can not change once made.  Efficient  Easy to implement  The solution is expected to be optimal  Every problem may not have greedy solution  Dynamic programming  Decompose into sub-problems like divide and conquer  Sub-problems are dependant  Record results of smaller sub-problems  Re-use it for further occurrence  Mostly reduces complexity exponential to polynomial

Problem Solving Phases  Analysis  How does system work?  Breaking a system down to known components  How components (processes) relate to each other  Breaking a process down to known functions  Synthesis  Building tools  Building functions with supporting tools  Composing functions to form a process  How components should be put together?  Final solution

Problem Solving Process  Problem  Strategy  Algorithm  Input  Output  Steps  Analysis  Correctness  Time & Space  Optimality  Implementation  Verification

Analyzing Algorithms  Predict the amount of resources required: memory: how much space is needed? computational time: how fast the algorithm runs?  FACT: running time grows with the size of the input  Input size (number of elements in the input)  Size of an array, polynomial degree, # of elements in a matrix, # of bits in the binary representation of the input, vertices and edges in a graph Def: Running time = the number of primitive operations (steps) executed before termination  Arithmetic operations (+, -, *), data movement, control, decision making (if, while), comparison

Algorithm Efficiency vs. Speed E.g.: sorting n numbers Friend’s computer-A = 10 9 instructions/second Friend’s algorithm = 2 n 2 instructions Your computer-B = 10 7 instructions/second Your algorithm = 50 nlgn instructions Your friend = You = Sort 10 6 numbers! 20 times better!!

Model of Computation (Assumptions)  Design assumption  Level of abstraction which meets our requirements  Neither more nor less e.g. [0, 1] infinite continuous interval  Analysis independent of the variations in  Machine  Operating system  Programming languages  Compiler etc.  Low-level details will not be considered  Our model will be an abstraction of a standard generic single- processor machine, called a random access machine or RAM.

Model of Computation (Assumptions)  A RAM is assumed to be an idealized machine  Infinitely large random-access memory  Instructions execute sequentially  Every instruction is in fact a basic operation on two values in the machines memory which takes unit time.  These might be characters or integers.  Example of basic operations include  Assigning a value to a variable  Arithmetic operation (+, -, ×, /) on integers  Performing any comparison e.g. a < b  Boolean operations  Accessing an element of an array.

Model of Computation (Assumptions)  In theoretical analysis, computational complexity  Estimated in asymptotic sense, i.e.  Estimating for large inputs  Big O, Omega, Theta etc. notations are used to compute the complexity  Asymptotic notations are used because different implementations of algorithm may differ in efficiency  Efficiencies of two given algorithm are related  By a constant multiplicative factor  Called hidden constant.

Algorithm Analysis: Example  Alg.: MIN ( a[1], …, a[n] ) m ← a[1]; for i ← 2 to n if a[i] < m then m ← a[i];  Running time:  the number of primitive operations (steps) executed before termination T(n) =1 [first step] + (n) [for loop] + (n-1) [if condition] + (n-1) [the assignment in then] = 3n - 1  Order (rate) of growth:  The leading term of the formula  Expresses the asymptotic behavior of the algorithm

Typical Running Time Functions  1 (constant running time):  Instructions are executed once or a few times  logN (logarithmic)  A big problem is solved by cutting the original problem in smaller sizes, by a constant fraction at each step  N (linear)  A small amount of processing is done on each input element  N logN  A problem is solved by dividing it into smaller problems, solving them independently and combining the solution

Typical Running Time Functions  N 2 (quadratic)  Typical for algorithms that process all pairs of data items (double nested loops)  N 3 (cubic)  Processing of triples of data (triple nested loops)  N K (polynomial)  2 N (exponential)  Few exponential algorithms are appropriate for practical use

Some rules of thumb  Multiplicative constants can be omitted  14n 2 becomes n 2  7 log n become log n  Lower order functions can be omitted  n + 5 becomes n  n 2 + n becomes n 2  n a dominates n b if a > b  n 2 dominates n, so n 2 +n becomes n 2  n 1.5 dominates n 1.4

Some rules of thumb  a n dominates b n if a > b  3 n dominates 2 n  Any exponential dominates any polynomial  3 n dominates n 5  2 n dominates n c  Any polynomial dominates any logorithm  n dominates log n or log log n  n 2 dominates n log n  n 1/2 dominates log n  Do not omit lower order terms of different variables (n 2 + m) does not become n 2

Why Faster Algorithms? InputlogNNlogNN^2N^32^N

Drawbacks in Model of Computation First poor assumption  We assumed that each basic operation takes constant time, i.e. model allows  Adding  Multiplying  Comparing etc. two numbers of any length in constant time  Addition of two numbers takes a unit time!  Not good because numbers may be arbitrarily  Addition and multiplication both take unit time!  Again very bad assumption

Model of Computation  But with all these weaknesses, RAM model is not so bad because we have to give the  Comparison not the absolute analysis of any algorithm.  We have to deal with large inputs not with the small size  Model seems to work well, describing computational power of modern nonparallel machines Can we do Exact Measure of Efficiency ?  Exact measure of efficiency can be sometimes computed but it usually requires certain assumptions concerning implementation

Model of Computation  Analysis will be performed with respect to this computational model for comparison of algorithms  We will give asymptotic analysis not detailed comparison i.e. for large inputs  We will use generic uniprocessor random-access machine (RAM) in analysis  All memory equally expensive to access  No concurrent operations  All reasonable instructions take unit time, except, of course, function calls

Asymptotic Notation  Running time of an algorithm as a function of input size n for large n.  Define a set of functions; in practice used to compare two function sizes.  The notations describe different rate-of-growth relations between the defining function and the defined set of functions. 24

O - Notation  Asymptotic Less than and Equal  For function g(n), we define O(g(n)), big-O of n, as:  Set of all functions whose rate of growth is the same as or lower than that of g(n).  g(n) is an asymptotically upper bound for f(n).  f(n) ≤ g(n) 25

O - Notation 26 20n nlgn + 5= O(n 3 ) 3lgn + lg(lgn)= O(lgn) = O(1)

Rules to Manipulate Big-O If T1(n) = O(f(n)) and T2(n) = O(g(n)) then T1(n) + T2(n) = max(O(f(n)), O(g(n))) and T1(n) * T2(n) = O(f(n) * g(n)) 27

 - Notation  Asymptotic Equality  For function g(n), we define  (g(n)), big-Theta of n, as:  Set of all functions that have the same rate of growth as g(n).  g(n) is an asymptotically tight bound for f(n).  f(n) = g(n)old concept  f(n)  g(n)new concept 28

 - Notation 29 Θ(n 3 ):n 3 5n 3 + 4n 105n 3 + 4n 2 + 6n Θ(n 2 ):n 2 5n 2 + 4n + 6 n Θ(log n):log n log n 2 log (n + n 3 )

 - Notation  Asymptotic Lower bound  For function g(n), we define  (g(n)), big- Omega of n, as:  Set of all functions whose rate of growth is the same as or higher than that of g(n).  f(n) = g(n)old concept  f(n)  g(n)new concept 30

Examples  5n 2 =  (n)  n =  (2n), n 3 =  (n 2 ), n =  (logn)  c, n 0 such that: 0  cn  5n 2  cn  5n 2  c = 1 and n 0 = 1

Relations Between , O, 

Development of Notation  Drop insignificant terms and constants  Say function is of O(n 2 ) called Big-O of n 2  Common Big-O functions in algorithm analysis  g(n) = 1 (growth is constant)  g(n) = log 2 n (growth is logarithmic)  g(n) = n (growth is linear)  g(n) = n log 2 n (growth is faster than linear)  g(n) = n 2 (growth is quadratic)  g(n) = 2 n (growth is exponential)

Conclusion  What, Why and Where Algorithms?  Designing Techniques  Problem solving Phases and Procedure  Model of computations:  Major assumptions at design and analysis level  Merits and demerits, justification of assumptions taken  We proved that algorithm is a technology  Discussed importance of algorithms  In almost all areas of computer science and engineering  Algorithms make difference in users and developers  Asymptotic Notations