You are on page 1of 26

DESIGN AND ANALYSIS OF

ALGORITHMS
Lecture 1
Murtaza Mehdi
TOPICS
 Algorithms
 The Importance of Developing Efficient Algorithms

 Sequential Search Vs Binary Search

 The Fibonacci Sequence


ALGORITHMS
 An algorithm is a step-by-step procedure for performing
a task or solving a problem in a finite amount of time.

 A clearly specified finite set of instructions a computer


follows to solve a problem.

 In a computer program the steps of an algorithm are


specified in a specific computer language.
AN ALGORITHM FOR REPLYING TO
FRIEND’S LETTER
1. Read friend’s letter
2. Decide what to write
3. Write letter in reply
ALGORITHM TO ACCEPT / REJECT
HOLIDAY
Repeat
Read holiday leaflet
if it is in July
and costs less than Rs 8000
and is at a place not visited before
then Accept the holiday
else Reject the holiday
Until a holiday is accepted
WHERE ARE ALGORITHMS USED IN
COMPUTER SCIENCE?
 In computer science, an algorithm gives the computer a
specific set of instructions, which allows the computer to
do everything, be it running a calculator or running a
rocket.

 Computer algorithms play a big role in how social media


works: which posts show up, which ads are seen, and so
on. These decisions are all made by algorithms.

 Google’s programmers use algorithms to optimize


searches, predict what users are going to type, and more.
WHY ARE ALGORITHMS IMPORTANT TO
UNDERSTAND?
 We use algorithms and algorithmic thinking all the time.

 Algorithmic thinking allow us to break down problems


and conceptualize solutions in terms of discrete steps.

 Being able to understand and implement an algorithm


requires students to practice structured thinking and
reasoning abilities.
REAL LIFE EXAMPLES
REAL LIFE EXAMPLES
REAL LIFE EXAMPLES
TYPES OF ALGORITHMS
 Divide and conquer algorithms

divide the problem into smaller sub problems of the


same type; solve those smaller problems, and combine
those solutions to solve the original problem.
TYPES OF ALGORITHMS
 Greedy algorithms

find an optimal solution at the local level with the intent


of finding an optimal solution for the whole problem
TYPES OF ALGORITHMS
 Brute force algorithms

try all possible solutions until a satisfactory solution is


found.
SEQUENTIAL SEARCH
 Linear search is a very simple search algorithm. In this
type of search, a sequential search is made over all items
one by one.

 Every item is checked and if a match is found then that


particular item is returned, otherwise the search
continues till the end of the data collection.
SEQUENTIAL SEARCH
SEQUENTIAL SEARCH
MATRIX MULTIPLICATION
BINARY SEARCH
 Binary search is a fast search algorithm.

 This search algorithm works on the principle of divide


and conquer.

 For this algorithm to work properly, the data collection


should be in the sorted form.
BINARY SEARCH
BINARY SEARCH
BINARY SEARCH
BINARY SEARCH
BINARY SEARCH
THE FIBONACCI SEQUENCE
THE FIBONACCI SEQUENCE
THE FIBONACCI SEQUENCE

You might also like