Chapter 1: Basic Concepts: Design and Analysis of Algorithm (CS 302)

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 16

Chapter 1: Basic Concepts

Design and Analysis of Algorithm


(CS 302)
ALGORITHM DEFINITION
Algorithm Definition
• Definition 1: A computer Algorithm is a
detailed step-by-step method for solving a
problem by using a computer.
• Definition 2: An algorithm is a sequence of
unambiguous instructions for solving a
problem in a finite amount of time.
Algorithm Definition (cont.)
• Definition 3: An algorithm is a well defined
computational procedure that takes some
value, or set of values, as input and produces
some value or set of values as output.
• Definition 4: 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.
One problem many algorithms
• One might need to sort a sequence of
numbers into non-decreasing order.
• There are various algorithms to perform this
task e.g. merge sort, quick sort, heap sort etc.
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.
Important Designing Techniques
• Brute Force
– Straight forward, enumerate all possible candidates for the
solution, most exhaustive.
• Divide and Conquer
– Divide into smaller sub-problems.
• Decrease and Conquer
– Decrease instance size
• Dynamic Programming
– Decompose into sub-problems like divide and conquer. Sub-
problems are dependent. Record result of smaller sub—
problems and re-use it for further occurrences.
Important Designing Techniques (cont.)

• Greedy Approach
– Locally optimal decisions, cannot change once
made. Efficient, easy to implement, the solution is
expected to be optimal. Every problem may not
have greedy solution.
Problem Solving Process
• Problem
• Algorithm
– Input
– Output
– Steps
• Analysis
– Correctness
– Time and space complexity
– Optimality
• Implementation
• Verification
Models of Computation Assumptions
• Model of computation is in fact a set of assumptions where we
define under which assumptions we will design and analyze our
algorithms.
• Designing Assumptions
– Level of abstraction which meets our requirement.
– It should be neither more nor less, for example [0, 1] infinite continuous
interval.
• Analysis Assumptions
– Analysis Independent of the variations in:
• Machines
• Operating systems
• Programming languages
• Compilers etc.
Models of Computation Assumptions (cont.)

• Our model will be an abstraction of a standard


generic single processor machine called a
random-access machine (RAM).
Models of Computation Assumptions (cont.)

• RAM is assumed to be an idealized machine


– Infinitely large random-access memory
– Instruction 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.
• Examples of basic operations include:
– Assigning a value to a variable
– Arithmetic operation (+, -, *, /) on integers
– Performing any comparison, for example, A < B.
– Boolean operations
– Accessing an element of an array
Discussion on Model of Computation

• We took some assumptions for our model.


Having this weakness our model is not 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.
Asymptotic Notations
• In theoretical analysis computational
complexity estimated in asymptotic sense i.e.
estimating for large inputs.
• Big O, Ω, Θ are used to compute the
complexity.
• Asymptotic notations are used because
different implementations of algorithm may
differ in efficiency.
ALGORITHM ANALYSIS
Algorithm Analysis and Design
• Design an algorithm
– Loop invariant
– Recursive function
– Formal (mathematical) proof

• Analyze the algorithm


– Algorithm analysis means predicting the resources such as:
• Time
– Worse case, best case, average case.
– For some algorithms, worst case occurs often, average case is often roughly as bad
as the worst case. So generally, worse case running time.
• Space

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy