Design and Analysis of Algorithms

Slides:



Advertisements
Similar presentations
Analysis of Algorithms CS 477/677
Advertisements

CSE 373: Data Structures and Algorithms Lecture 5: Math Review/Asymptotic Analysis III 1.
Razdan with contribution from others 1 Algorithm Analysis What is the Big ‘O Bout? Anshuman Razdan Div of Computing.
A Basic Study on the Algorithm Analysis Chapter 2. Getting Started 한양대학교 정보보호 및 알고리즘 연구실 이재준 담당교수님 : 박희진 교수님 1.
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.
Analysis of Algorithms CS 477/677 Midterm Exam Review Instructor: George Bebis.
Analysis of Algorithms CS 477/677 Recurrences Instructor: George Bebis (Appendix A, Chapter 4)
Analysis of Algorithms CS 477/677
David Luebke 1 8/17/2015 CS 332: Algorithms Asymptotic Performance.
Program Performance & Asymptotic Notations CSE, POSTECH.
Week 2 CS 361: Advanced Data Structures and Algorithms
Computer Algorithms Lecture 1 Introduction
Mathematics Review and Asymptotic Notation
Algorithm Analysis An algorithm is a clearly specified set of simple instructions to be followed to solve a problem. Three questions for algorithm analysis.
1 Time Analysis Analyzing an algorithm = estimating the resources it requires. Time How long will it take to execute? Impossible to find exact value Depends.
Design and Analysis of Algorithms Introduction. Class Policy Grading –Homeworks and quizzes (20%) Programming assignments –First and Second exams (20%
Analysis of Algorithms
CMPT 438 Algorithms. Why Study Algorithms? Necessary in any computer programming problem ▫Improve algorithm efficiency: run faster, process more data,
1Computer Sciences Department. Book: Introduction to Algorithms, by: Thomas H. Cormen Charles E. Leiserson Ronald L. Rivest Clifford Stein Electronic:
Chapter 5 Algorithms (2) Introduction to CS 1 st Semester, 2015 Sanghyun Park.
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 Performance. Review: Asymptotic Performance Asymptotic performance: How does algorithm behave as the problem size gets very large? Running.
Midterm Review 1. Midterm Exam Thursday, October 15 in classroom 75 minutes Exam structure: –TRUE/FALSE questions –short questions on the topics discussed.
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.
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.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 1.
Algorithm Analysis 1.
CMPT 438 Algorithms.
Theoretical analysis of time efficiency
Analysis of Algorithms
Analysis of Algorithms CS 477/677
Analysis of Algorithms
Introduction to the Design and Analysis of Algorithms
Analysis of Algorithms
UNIT- I Problem solving and Algorithmic Analysis
Introduction to Algorithms
CS 3343: Analysis of Algorithms
Analysis of algorithms
Teach A level Computing: Algorithms and Data Structures
Chapter 2 Fundamentals of the Analysis of Algorithm Efficiency
CS 583 Fall 2006 Analysis of Algorithms
CS 3343: Analysis of Algorithms
CS 3343: Analysis of Algorithms
Algorithm Analysis (not included in any exams!)
CS 3343: Analysis of Algorithms
Advance Analysis of Lecture No 9 Institute of Southern Punjab Multan
CSC 413/513: Intro to Algorithms
Introduction to Algorithms Analysis
Data Structures Review Session
CMPT 438 Algorithms Instructor: Tina Tian.
CS 201 Fundamental Structures of Computer Science
Lecture No 6 Advance Analysis of Institute of Southern Punjab Multan
Analysis of Algorithms
Searching, Sorting, and Asymptotic Complexity
Algorithm Analysis, Asymptotic notations CISC4080 CIS, Fordham Univ.
Ch. 2: Getting Started.
Analysis of Algorithms
At the end of this session, learner will be able to:
Analysis of algorithms
David Kauchak cs161 Summer 2009
Algorithms Recurrences.
The Selection Problem.
Estimating Algorithm Performance
Analysis of Algorithms CS 477/677
Analysis of Algorithms
Algorithms and data structures: basic definitions
Presentation transcript:

Design and Analysis of Algorithms Introduction

Class Policy Grading Late homework Homeworks and quizzes (20%) Programming assignments First and Second exams (20% each) Closed books, closed notes Final exam (40%) Late homework 12% penalty for each day of delay, up to 2 days Introduction to Algorithms, Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest and Clifford Stein

Homework Submission Submit all homeworks using the e-learning system http://elearning.just.edu.jo/

Why Study Algorithms? Necessary in any computer programming problem Improve algorithm efficiency: run faster, process more data, do something that would otherwise be impossible Solve problems of significantly large size Technology only improves things by a constant factor Compare algorithms Algorithms as a field of study Learn about a standard set of algorithms New discoveries arise Numerous application areas Learn techniques of algorithm design and analysis Introduction

Applications Multimedia Internet Communication Computers Science CD player, DVD, MP3, JPG, DivX, HDTV Internet Packet routing, data retrieval (Google) Communication Cell-phones, e-commerce Computers Circuit layout, file systems Science Human genome Transportation Airline crew scheduling, ARAMEX and DHL deliveries Introduction

Roadmap Different problems Different design paradigms Searching Sorting Graph problems Different design paradigms Divide-and-conquer Greedy algorithms Dynamic programming Introduction

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 Introduction

Algorithm Efficiency vs. Speed E.g.: Sorting n numbers Friend’s computer = 109 instructions/second Friend’s algorithm = 2n2 instructions Your computer = 107 instructions/second Your algorithm = 50nlgn instructions Your friend = You = Sort 106 numbers! 2000/100 = 20 times better!! Introduction

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 Introduction

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 Introduction

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

Practical Complexity

Practical Complexity

Practical Complexity

Why Faster Algorithms?

Asymptotic Notations A way to describe behavior of functions in the limit Abstracts away low-order terms and constant factors How we indicate running times of algorithms Describe the running time of an algorithm as n grows to  O notation:  notation:  notation: asymptotic “less than and equal”: f(n) “≤” g(n) asymptotic “greater than and equal”:f(n) “≥” g(n) asymptotic “equality”: f(n) “=” g(n) Introduction

Asymptotic Notations - Examples n2/2 – n/2 (6n3 + 1)lgn/(n + 1) n vs. n2  notation n3 vs. n2 n vs. logn = (n2) = (n2lgn) n ≠ (n2) O notation 2n2 vs. n3 n2 vs. n2 n3 vs. nlogn n3 = (n2) 2n2 = O(n3) n = (logn) n2 = O(n2) n (n2) n3 O(nlgn) Introduction

Recursive Algorithms Binary search: for an ordered array A, finds if x is in the array A[lo…hi] Alg.:BINARY-SEARCH (A, lo, hi, x) if (lo > hi) return FALSE mid  (lo+hi)/2 if x = A[mid] return TRUE if ( x < A[mid] ) BINARY-SEARCH (A, lo, mid-1, x) if ( x > A[mid] ) BINARY-SEARCH (A, mid+1, hi, x) 12 11 10 9 7 5 3 2 1 4 6 8 mid lo hi Introduction

Recurrences Def.: Recurrence = an equation or inequality that describes a function in terms of its value on smaller inputs, and one or more base cases E.g.: T(n) = T(n-1) + n Useful for analyzing recurrent algorithms Methods for solving recurrences Iteration method Substitution method Recursion tree method Master method Introduction

Sorting Iterative methods: Insertion sort Bubble sort Selection sort 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K, A Divide and conquer Merge sort Quicksort Non-comparison methods Counting sort Radix sort Bucket sort Introduction

Types of Analysis Worst case (e.g. cards reversely ordered) Best case 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 Input is the one for which the algorithm runs the fastest Average case Provides a prediction about the running time Assumes that the input is random (e.g. cards reversely ordered) (e.g., cards already ordered) (general case) Introduction