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.

Slides:



Advertisements
Similar presentations
Analysis of Computer Algorithms
Advertisements

MATH 224 – Discrete Mathematics
Counting the bits Analysis of Algorithms Will it run on a larger problem? When will it fail?
ALGORITHMS Introduction. Definition Algorithm: Any well-defined computational procedure that takes some value or set of values as input and produces some.
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.
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.
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.
© 2006 Pearson Addison-Wesley. All rights reserved10 A-1 Chapter 10 Algorithm Efficiency and Sorting.
Design & Analysis of Algorithms Introduction. Introduction Algorithms are the ideas behind computer programs. An algorithm is the thing which stays the.
HOW TO SOLVE IT? Algorithms. An Algorithm An algorithm is any well-defined (computational) procedure that takes some value, or set of values, as input.
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.
Lecture 2 Computational Complexity
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.
Analysis of Algorithms
Chapter 3 Sec 3.3 With Question/Answer Animations 1.
Introduction to Algorithms Lecture 1. Introduction The methods of algorithm design form one of the core practical technologies of computer science. The.
ECOE 456/556: Algorithms and Computational Complexity Lecture 1 Serdar Taşıran.
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
Data Structure Introduction.
Review 1 Selection Sort Selection Sort Algorithm Time Complexity Best case Average case Worst case Examples.
Introduction to Algorithms (2 nd edition) by Cormen, Leiserson, Rivest & Stein Chapter 2: Getting Started.
1 Ch. 2: Getting Started. 2 About this lecture Study a few simple algorithms for sorting – Insertion Sort – Selection Sort (Exercise) – Merge Sort Show.
Onlinedeeneislam.blogspot.com1 Design and Analysis of Algorithms Slide # 1 Download From
BITS Pilani Pilani Campus Data Structure and Algorithms Design Dr. Maheswari Karthikeyan Lecture1.
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.
Advanced Algorithms Analysis and Design
Algorithm Complexity is concerned about how fast or slow particular algorithm performs.
Data Structures I (CPCS-204) Week # 2: Algorithm Analysis tools Dr. Omar Batarfi Dr. Yahya Dahab Dr. Imtiaz Khan.
Algorithm Analysis 1.
ECOE 456/556: Algorithms and Computational Complexity
Complexity Analysis (Part I)
CMPT 438 Algorithms.
Design and Analysis of Algorithms
Advanced Algorithms Analysis and Design
Introduction to Algorithms
Introduction to Analysis of Algorithms
Design and Analysis of Algorithms Chapter -2
Analysis of Algorithms
Introduction to Algorithms
Introduction Algorithms Order Analysis of Algorithm
DATA STRUCTURES AND OBJECT ORIENTED PROGRAMMING IN C++
Introduction to Algorithms
Courtsey & Copyright: DESIGN AND ANALYSIS OF ALGORITHMS Courtsey & Copyright:
Algorithm Analysis CSE 2011 Winter September 2018.
Course Description Algorithms are: Recipes for solving problems.
DATA STRUCTURES Introduction: Basic Concepts and Notations
Algorithms Furqan Majeed.
Algorithm Analysis (not included in any exams!)
Algorithm An algorithm is a finite set of steps required to solve a problem. An algorithm must have following properties: Input: An algorithm must have.
Objective of This Course
Introduction to Algorithms Analysis
Algorithm Analysis and Design
Asst. Dr.Surasak Mungsing
Introduction to Algorithms
Algorithm Efficiency and Sorting
Ch. 2: Getting Started.
Course Description Algorithms are: Recipes for solving problems.
Design and Analysis of Algorithms
Algorithms Presented By:- Mr. Anup Ashok Shinde BBA (C.A) Dept.
Complexity Analysis (Part I)
Design and Analysis of Algorithms
Complexity Analysis (Part I)
Presentation transcript:

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 of unambiguous instructions for solving a problem in a finite amount of time. 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. Algorithm Input output What is Algorithm?

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. Popular Algorithms, Factors of Dependence

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 sorts, radix sort, counting sort etc. One Problem, Many Algorithms

Brute Force Straightforward, naïve/simple 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 Some of the Important Designing Techniques

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

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. Model of Computation (Assumptions)

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 Drawbacks in Model of Computation

Finally what about Our Model? But with all these weaknesses, our 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, not asymptotic, measure of efficiency can be sometimes computed but it usually requires certain assumptions concerning implementation Model of Computation not so Bad

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 Summary : Computational Model

DESIGN AND ANALYSIS In order to understand design and analysis procedure we will do an example

SELECTION PROBLEM Suppose you want to purchase a Laptop You want to pick fastest Laptop But fast Laptops are expensive You cannot decide which one is more important price or speed

SELECTION PROBLEM Definitely do not want a Laptop if there is a another Laptop that is both fast and cheaper We say that fast cheap Laptops “dominates” the slow expensive So given a list of Laptops we want those that are not dominated by the other

CRITERION FOR SELECTION Two criterion for selection: Speed Price

MATHEMATICAL MODEL P is in two dimensional space and its coordinates are P=(p.x, p.y) (x,y) x is speed of Laptop y is negation of price We can say about y High value of y mean cheap Laptop and low y means Laptop is expensive A point p is said to be dominated by a point q if p.x <= q.x and p.y <= q.y In an array of points (Laptops) P={p 1,p 2,p 3,….,p n } a maximal point is not dominated by any other point

EXAMPLE (700,15) (500,20) (200,1) (1000,50) (900,35) (800,30) (1400,70) (1500,80) (1200,60)

EXAMPLE Given a set of point P={p 1,p 2,p 3,….,p n } output the maximal points Those points of P such that p i is not dominated by any other point

BRUTE-FORCE ALGORITHM Maximal ( int n, Point p[1……n]) 1 for i = 1 to n 2 maximal = true 3 for j = 1 to n 4 if( i != j ) and (p[i].x <= p [j]. x) and (p [i].y <= p [j].y) 5 maximal = false; 6 break; 7if (maximal == true) 8then output p [i].x, p[i]. y

RUNNING TIME ANALYSIS We can observe that: The running time depends upon the input size. Different input of the same size may result different time

RUNNING TIME ANALYSIS Count the number of steps of the pseudo code that are executed Or count the number of times an element of p is accessed Or number of comparisons that are performed

ANALYSIS OF SELECTION PROBLEM Input size is n We will count how number of steps

BRUTE-FORCE ALGORITHM Maximal(int n, Point p[1……n]) 1 for i = 1 to n 2 maximal = true 3 for j = 1 to n 4 if( i != j ) and (p[i].x <= p [j]. x) and (p [i].y <= p [j].y) 5 maximal = false; 6 break; 7if (maximal == true) 8 output p [i].x, p[i]. y n times 1 time n times 5 times 2 times Worst Case Analysis

ANALYSIS OF SELECTION PROBLEM The outer loop runs n times For each iteration. The inner loop runs n times in the worst case P is accessed four times in the if statement The output statement accesses p 2 times

Maximal(int n, Point p[1……n]) 1 for i = 1 to n 2 maximal = true 3 for j = 1 to n 4 if( i != j ) and (p[i].x <= p [j]. x) and (p [i].y <= p [j].y) 5 maximal = false; 6 break; 7if (maximal == true) 8 output p [i].x, p[i]. y n times 1 time n times 5 times 2 times

ANALYSIS OF SELECTION PROBLEM In the worst case every point is maximal so every point is output Worst-case time is:

ANALYSIS OF SELECTION PROBLEM

Suppose n=50 and We use a computer whose speed is instructions per second Then this computer requires

COMPLEXITY OF THE ALGORITHMS Algorithm complexity is the work done by the algorithm there are following complexities: a.Worst case time b.Average case time c.Best case time d.Expected time

GROWTH OF FUNCTIONS Input SizeTime of T(n)

IMPORTANT We will almost always work with worst case time. Average case time is most difficult to compute Worst case refer to the upper limit on the running time

ANALYSIS OF SELECTION PROBLEM T(n) is Asymptotically equivalent to n 2

DIVIDE & CONQUER A strategy to solve large number of problems. It has following stages:  Divide : divide the problem into small number of pieces  Conquer : Solve each piece by applying divide and conquer recursively  Combine : Rearrange the pieces  Examples: MergeSort, QuickSort