You are on page 1of 37

ALGORITHMS

INDUCTION
PROGRAM
LESSON OBJECTIVE
Algorithms play an imperative role in
computer science.
They are at the heart of what our
devices actually do. And this isn’t a new
concept. Since the development of
mathematics itself, algorithms have
been needed to help us complete tasks
more efficiently
This lesson will help you master some
of the basic terminology and
understand a bit more about what,
why, how, and when of algorithms.
LET’S BEGIN
WHAT IS AN ALGORITHM?
• A sequence of instructions.
• A procedure or formula for solving a
problem.
• Often used for calculation, data
processing and programming
• Algorithms can be expressed in any
language.
WHAT IS AN ALGORITHM?
• An algorithm is a step-by-step
process designed to achieve some
outcome.
• Computers are the greatest
machines ever developed for doing
step-by-step processes.
• Algorithms are important to
computer science, but they aren't
exclusively part of computer
science.
WHAT IS AN ALGORITHM?
• Well-defined computational
procedure that takes some value, or
set of values, as input and produces
some value, or set of values as
output.”
• Road maps for accomplishing a
given, well-defined task.
• Example, a simple function for
adding two numbers is an
algorithm.
FIRST COMPUTER
ALGORITHM
• You may not have heard of Ada
Lovelace but she had a huge bearing
on everything that you do.
• She wrote algorithm for the
Analytical Engine to compute
Bernoulli numbers.
• This is widely regarded as the first
published algorithm written for a
computer, and it's for this reason that
Ada Lovelace is often cited as our first
ever computer programmer.
IMPORTANCE OF
ALGORITHMS
• Algorithms are very important in
computer Science.
• The best chosen algorithm makes
sure computer will do the given task
at best possible manner.
• In cases where efficiency matter a
proper algorithm is really vital to be
used.
• An algorithm is important in
optimizing a computer program
according to the available resources.
GOOD ALGORITHM
A good algorithm is –
• Precise – It knows the exact and
correct steps to execute.
• Unique – The input for the current
instructions comes only from the
preceding instruction.
• Finite – The algorithm ends giving
the result after the execution of a
finite number of instructions.
• Generality – The algorithm holds
good to set of inputs and not strictly
one input.
Could You Think Of An Example Of An Algorithm From
Your Life??
CLASS ACTIVITY

MAKING A PEANUT
BUTTER AND JELLY
SANDWICH
ACTIVITY OBJECTIVE
• This activity will introduce
students to several computer
science concepts.
• Students will learn the necessity
for thoroughness while
programming and will be
introduced to the often strange
results of literalism.
• Students are introduced to the
concept of debugging through
iterative attempts to program a
computer to make a peanut butter
and jelly sandwich.
ACTIVITY OBJECTIVE
• The overarching theme being
introduced is that computers do
what they are told and nothing
more.
• The ability to read between the
lines and determine what was
meant rather than what was said
is a skill computers lack.
INGREDIENTS
• 2 Loaves of Bread (sliced)
• Several knives
• 1 Jar Peanut Butter
• 1 Jar Jelly
• Lined Paper
• Pencils

• Time limit - 5 minutes


EXAMPLE
For example:
1. Take a slice of bread
2. Put peanut butter on the slice
3. Take a second slice of bread
4. Put jelly on that slice
5. Press the slices of bread together
SAMPLE ANSWER
1. Take a slice of bread.
2. Open the jar of peanut butter by twisting
the lid counter clockwise.
3. Pick up a knife by the handle.
4. Insert the knife into the jar of peanut
butter.
5. Withdraw the knife from the jar of
peanut butter and run it across the slice of
bread.
6. Take a second slice of bread.
7. Repeat steps 2-5 with the second slice of
bread and the jar of jelly.
8. Press the two slices of bread together
such that the peanut butter and jelly meet.
ACTIVITY CONCLUSION
• An algorithm could be simply
described as “any well-defined
computational procedure that takes
some value, or set of values, as
input, and produces some value, or
set of values, as output”.
• In other words, algorithms are
general steps to solve a specific
problem with well-defined input data
(e.g. ingredients) and output data
(e.g. a sandwich).
FINDING BEST
ALGORITHM
• Sometimes, there are more than one
way to solve a problem.
• We need to learn how to compare
the performance different algorithms
and choose the best one to solve a
particular problem.
• While analysing an algorithm, we
mostly consider time complexity and
space complexity. 
COMPLEXITY
• The complexity of an algorithm is a
function f(n) which measures the
time and space used by an algorithm
in terms of input size n.
•  The complexity of an algorithm is a
way to classify how efficient an
algorithm is, compared to alternative
ones.
• The focus is on how execution time
increases with the data set to be
processed.
TIME COMPLEXITY
• The time complexity of an algorithm
is the amount of time taken by the
algorithm to complete its process as a
function of its input length, n. 
TIME COMPLEXITY
EXAMPLE
Imagine a classroom of 100 students in
which you gave your pen to one person.
Now, you want that pen.
Here are some ways to find the pen and
what the O order is.

1. O(n2): You go and ask the first person


of the class, if he has the pen. Also,
you ask this person about other 99
people in the classroom if they have
that pen and so on,
This is what we call O(n2).
TIME COMPLEXITY
2. O(n): Going and asking each student
individually is O(N).

3. O(log n): Now I divide the class into


two groups, then ask: “Is it on the
left side, or the right side of the
classroom?”
Then I take that group and divide it
into two and ask again, and so on.
Repeat the process till you are left
with one student who has your pen.
This is what you mean by O(log n).
TIME COMPLEXITY
• I might need to do the O(n2) search if
only one student knows on which
student the pen is hidden.
• I’d use the O(n) if one student had the
pen and only they knew it.
• I’d use the O(log n) search if all the
students knew, but would only tell me
if I guessed the right side.
• We are interested in rate of growth of
time with respect to the inputs taken
during the program execution 
SPACE COMPLEXITY
• Whenever a solution to a problem
is written some memory is required
to complete. For any algorithm
memory may be used for the
following:
• Variables (This include the
constant values, temporary
values)
• Program Instruction
• Execution
SPACE COMPLEXITY
• Auxiliary Space is the extra space or
the temporary space used by the
algorithm during it's execution.
Space Complexity = Auxiliary Space +
Input space
• While executing, algorithm uses
memory space for three reasons:
• Instruction Space
• Environmental Stack
• Data Space
SPACE COMPLEXITY
• The space complexity of an algorithm
is the amount of space (or memory)
taken by the algorithm to run as a
function of its input length, n.
• Space complexity includes
both auxiliary space and space used
by the input.
• Auxiliary space is the temporary or
extra space used by the algorithm
while it is being executed. Space
complexity of an algorithm is
commonly expressed using Big
O (O(n))(O(n)) notation.
TYPES OF ALGORITHMS
There are many types of Algorithms such as
• Routing algorithms (Computer Networks)
• CPU Scheduling Algorithms (Operating System)
• Health Care Algorithms (Medical Science)
• Machine Learning algorithms (Artificial Intelligence)
• Encryption or Cryptographic Algorithms (Network Security)
• Graph searching algorithms such as backtracking (Data Structures)
• Speech Recognition Algorithms (Natural Language Processing)
• Pattern Matching Algorithms (Programming)
• Euclidean algorithm (Number Theory)
• And many more
WHAT ALGORITHMS
AM I GOING TO STUDY?
• Linear Search
• Binary Search
• Bubble Sort
• Merge Sort
• Quick Sort
• Dynamic Programming
• Backtracking
• Divide-n-Conquer
• Recursive Algorithms
• Fibonacci Sequence
GOOGLE SEARCH
ALGORITHM
GOOGLE SEARCH
ALGORITHM HISTORY
HOW GOOGLE SEARCH WORKS

• Every time you search, there are thousands, sometimes millions, of


webpages with helpful information.
• How Google figures out which results to show starts long before you
even type, and is guided by a commitment to you to provide the best
information.
ORGANIZING THE 
CONTENT OF THE WEB
• Even before you search, Google
organizes information about
webpages in our Search index.
• The index is like a library, except
it contains more info than in all
the world’s libraries put
together.
INSTANTLY MATCHING YOUR SEARCH

• In a fraction of a second, Google’s


Search algorithms sort through
hundreds of billions of webpages
in our Search index to find the
most relevant, useful results for
what you’re looking for.
GOOGLE PAGE RANK
ALGORITHM
• The PageRank system, a patented
automated process
• It determines where each search
result appears on Google's search
engine return page.
• Most users tend to concentrate on
the first few search results, so
getting a spot at the top of the list
usually means more user traffic. 
REFERENCES :
1. Why is the Google algorithm so important?
https://computer.howstuffworks.com/google-algorithm.htm

2. How Search algorithms work?


https://www.google.com/search/howsearchworks/algorithms/

3. Algorithms, https://brilliant.org/wiki/algorithm/

4. Algorithm Fundamentals,
https://brilliant.org/courses/computer-science-algorithms/

5. Types of Algorithms, https://www.educba.com/types-of-algorithms/

You might also like