design and analysis of algorithms slide # 1 download from
DESCRIPTION
onlinedeeneislam.blogspot.com3 What is an Algorithm? An algorithm is a sequence of unambiguous instructions for solving a problem, i.e., for obtaining a required output for any legitimate input in a finite amount of time.TRANSCRIPT
onlinedeeneislam.blogspot.com 1
Design and Analysis of Algorithms
Slide # 1
Download Fromhttp://onlinedeeneislam.blogspot.com
onlinedeeneislam.blogspot.com 2
What is an Algorithm?• An algorithm is a set of rules for carrying out calculation
either by hand or on a machine. • An algorithm is a finite step-by-step procedure to achieve a
required result.• An algorithm is a sequence of computational steps that
transform the input into the output. • An algorithm is a sequence of operations performed on data
that have to be organized in data structures. • An algorithm is an abstraction of a program to be executed on
a physical machine (model of Computation).
onlinedeeneislam.blogspot.com 3
What is an Algorithm?
An algorithm is a sequence of unambiguous instructions for solving a problem, i.e., for obtaining a required output for any legitimate input in a finite amount of time.
onlinedeeneislam.blogspot.com 4
What is an Algorithm?
Problem
algorithm
“computer”input output
onlinedeeneislam.blogspot.com 5
Important Problem Types
• Sorting• Searching• String Processing• Graph Problems• Combinatorial Problems• Geometric Problems• Numerical Problems
onlinedeeneislam.blogspot.com 6
Important Problem TypesSorting
• The sorting problem asks us to rearrange the items of a given list in ascending order.
• Why would we want a sorted list?• It makes many questions about the list easier to answer.• It is used as an auxiliary step in several important
algorithms in other areas, e.g., greedy algorithms, geometric algorithms.
• There is no sorting algorithm that would be the best solution in all situations.
onlinedeeneislam.blogspot.com 7
Important Problem TypesSorting
• Two special properties of sorting algorithms– Stable– In place
• A sorting algorithm is called stable it it preserves the relative order of any two equal elements in its input.
• An algorithm is said to be in place if it dos not require extra memory, except possibly, for a few memory units.
onlinedeeneislam.blogspot.com 8
Important Problem TypesSearching
• The Searching Problem deals with finding a given value, called a search key, in a given set.
• There is no single algorithm that fits all situations best.
onlinedeeneislam.blogspot.com 9
Important Problem TypesString Processing
• A string is a sequence of characters from an alphabet.
• Strings of particular interest are – Text strings– Bit strings– Gene sequences
• String Matching I.e. searching of a given word in a text get a special attention from researchers.
onlinedeeneislam.blogspot.com 10
Important Problem TypesGraph Problems
• A graph is a collection of points called vertices, some of which are connected by line segments called edges.
• Graphs can be used for modeling a wide variety of real-life applications, like– Transportation and communication networks– Project Scheduling – Games
onlinedeeneislam.blogspot.com 11
Important Problem TypesGraph Problems
• Basic graph algorithms include– Graph traversal algorithms– Shortest path algorithms– Topological sorting for graphs with directed edges
• Some graph problems are computationally very hard like– Traveling salesperson problem– Graph coloring problem
onlinedeeneislam.blogspot.com 12
Important Problem TypesCombinatorial Problems
• These are problems that ask (explicitly or implicitly) to find a combinatorial object-such as– A permutation– A combination– Or a subset
• That satisfies certain constraints and has some desired property.
• E.g.– Traveling Salesperson problem– Graph Coloring problem
onlinedeeneislam.blogspot.com 13
Important Problem TypesCombinatorial Problems
• Most difficult problems in computing both theoretically and the practically. Because
1. The number of combinatorial objects typically grows extremely fast with a problem’s size.
2. There are no known algorithms for solving most such problems exactly in an acceptable amount of time.
• Some exceptional combinatorial problems can be solved by efficient algorithms like shortest-path problem
onlinedeeneislam.blogspot.com 14
Important Problem TypesGeometric Problems
• Geometric algorithms deal with geometric objects.
• Geometric algorithms are helpful in the applications like– Computer graphics– Robotics– Tomography
onlinedeeneislam.blogspot.com 15
Important Problem TypesNumerical Problems
• Numerical Problems are problems that involve mathematical objects of continuous nature:– Solving equations and systems of equations– Computing definite integrals– Evaluating functions and so on:
• The majority of such problems can be solved approximately
onlinedeeneislam.blogspot.com 16
Fundamental Data StructuresReview
• Data Structure can be defined as a particular scheme of organizing related data items.
• Linear Data Structures1. Arrays2. Linked List
onlinedeeneislam.blogspot.com 17
Fundamental Data StructuresReview (Linear Data Structures)
1. Arrays– Sequence of n items of same data type– Stored contiguously in computer memory– Each item is made accessible by specifying the
value of the array’s index.• Each and every array element can be
accessed in the same constant amount of time.
onlinedeeneislam.blogspot.com 18
Fundamental Data Structures Review (Linear Data Structures)
2. Linked List– Sequence of zero or more elements called nodes.– Each node contains
• Some data and• One or more links called pointers to other nodes of the linked
list.
• Singly Linked List– a node has a pointer only to its successor node
• Doubly Linked List– a node has a pointer to both its successor and its
predecessor.
onlinedeeneislam.blogspot.com 19
Fundamental Data Structures Review (Linear Data Structures)
• List– A finite sequence of data items– Implement by using• Arrays or• Linked lists
• Special kinds of lists– Stack &– Queue
onlinedeeneislam.blogspot.com 20
Fundamental Data Structures Review (Linear Data Structures)
• Stack– Only one end is used both for insertion and
deletion– Operates in LIFO fashion
• Queue– One end is used for insertion and other end is
used for deletion– Operates in FIFO fashion
onlinedeeneislam.blogspot.com 21
Algorithms Analysis FrameworkIntroduction
• How to analyze an algorithm?• Predicting the resources that the algorithm requires.
– Memory
– Communications Bandwidth
– Logic gates etc
– Computational time
onlinedeeneislam.blogspot.com 22
Algorithms Analysis FrameworkIntroduction
• Two parameters of measuring algorithm’s efficiency
1. Time Efficiency How fast an algorithm in question runs
2. Space Efficiency It deals with the extra space the algorithm
requires
onlinedeeneislam.blogspot.com 23
Algorithms Analysis FrameworkIntroduction
• Important thing before analysis
– Model of the machine upon which the algorithms is executed.
– Random Access Machine (RAM) (Sequential)
onlinedeeneislam.blogspot.com 24
Algorithms Analysis FrameworkTime Complexity Analysis
• We do not Determine the actual number of CPU cycles Want to count every instruction executed
• We want a measure that is independent of the Computer Programming language Programmer and The Compiler used in generating the machine code
onlinedeeneislam.blogspot.com 25
Algorithms Analysis FrameworkTime Complexity Analysis
• We do not Determine the actual number of CPU cycles Want to count every instruction executed
• We want a measure that is independent of the Computer Programming language Programmer and The Compiler used in generating the machine code
onlinedeeneislam.blogspot.com 26
Algorithms Analysis FrameworkTime Complexity Analysis
• For time complexity analysis– Identify the basic operation and– Compute the number of times the basic operation is executed
• Running Time:No. of primitive operations or “steps executed”.
• The running time of an algorithm increases with the size of the input.
• We can express running time T(n) as the function of the input size.
• T(n) is defined as the number of times the algorithm does the basic operation for an instance of size n.
onlinedeeneislam.blogspot.com 27
Algorithms Analysis FrameworkTime Complexity Analysis
• Let cop be the time of execution of an algorithm’s basic operation on a particular computer,
• Let C(n) be the number of times this operation needs to be executed for this algorithm,
• The running time T(n) can be estimated asT(n) cop C(n)