0% found this document useful (0 votes)
16 views

Introduction To Algorithms

The document provides an introduction to algorithms, discussing what algorithms are, examples of algorithms, and the components and structure of algorithms. It describes the problem-solving process and how algorithms are translated into computer programs. Key aspects covered include variables, values, instructions, sequences, procedures, selection, repetition, and documentation in algorithms.

Uploaded by

NALE SVPMEngg
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Introduction To Algorithms

The document provides an introduction to algorithms, discussing what algorithms are, examples of algorithms, and the components and structure of algorithms. It describes the problem-solving process and how algorithms are translated into computer programs. Key aspects covered include variables, values, instructions, sequences, procedures, selection, repetition, and documentation in algorithms.

Uploaded by

NALE SVPMEngg
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 24

Introduction To Algorithms

Data Structures & Algorithms

Represented By

Nale Rajesh K.
(Lecturer COE Malegaon (Bk))

Sunday, April 14, 202 1


4
How do we solve problems?
 We "just do"
 Guesswork-and-luck
 Trial-and-error
 Experience (possibly someone else's)
 "Scientifically"

Sunday, April 14, 2024 2


The Problem-solving
Process
"Doctor, my head hurts"

Analysis Patient has elevated


pressure in anterior
Problem parietal lobe
specification
1. Sterilize cranial saw
Design
2. Anaesthetize patient
3. Remove top of skull
Algorithm 4. Get the big spoon...
5. etc., etc.
Implementation sterilize(saw,alcohol);
raise_hammer();
Program lower hammer(fast);
start(saw);
/* etc. etc. */
Compilation 0100111010110010101010101
0010101010101001100101010
Executable 1010100101101001110101010
(solution) 1010010010111010011110101
Sunday, April 14, 2024 3
010111110101010001101…
The Problem-solving Process
"Doctor, my head hurts"

Patient has elevated


Analysis pressure in anterior
Problem parietal lobe.
specification
1. Sterilize cranial saw
Design
2. Anaesthetize patient
3. Remove top of skull
Algorithm 4. Get the big spoon...
5. etc., etc.
Implementation sterilize(saw,alcohol);
raise_hammer();
lower hammer(fast);
Program start(saw);
/* etc. etc. */
Compilation 01001110101100101010101010010
10101010100110010101010101001
01101001110101010101001001011
Executable 10100111101010101111101010100
Sunday, April 14, 2024
(solution) 0110100001101...
4
The Problem-solving Process

Analysis
Problem
specification
Design

Algorithm

Implementation

Program

Compilation
Executable
Sunday, April 14, 2024 5
(solution)
Algorithm
 A sequence of instructions specifying
the steps required to accomplish
some task
 Named after:
Muhammad ibn Musa al-Khwarizmi
of Khowarezm (now Khiva in Uzbekistan)

Sunday, April 14, 2024 6


Algorithm – Working Definition
 A sequence of instructions describing
how to do a task

[As opposed to actually executing


the instructions]

Sunday, April 14, 2024 7


Algorithm -- Examples
 A cooking recipe
 Assembly instructions for a model
 The rules of how to play a game
 VCR instructions
 Description of a martial arts
technique
 Directions for driving from A to B
 A knitting pattern
 A car repair manual
Sunday, April 14, 2024 8
Algorithm – Examples (cont)
 Recipe for Almond and honey slice
 Recipe for Arroz con pollo

Sunday, April 14, 2024 9


Almond and Honey Slice
1/2 quantity Shotcrust Pastry Bake blind for 20 minutes, then
185 g unsalted butter remove weights and foil
100 g castor sugar Turn oven up to 220° C.
5 tablespoons honey Bring remaining ingredients to a boil,
50 ml cream stirring.
50 ml brandy or any other Spread evenly over pastry.
liqueur or spirit
Bake until topping is bubbling and
300 g flaked almonds has caramelised evenly, about
Preheat oven for 200° C 15 minutes.
Line a 30 cm  20 cm baking Cool before cutting into fingers or
tray with baking paper, and
then with pastry squares.

From: Stephanie Alexander, The


Cook’s Companion, Viking/Penguin,
Ringwood, Victoria, 1996, p. 349.
Sunday, April 14, 2024 10
Almond and Honey Slice
1/2 quantity Shotcrust Pastry
Bake blind for 20 minutes, then
185 g unsalted butter
remove weights and foil
100 g castor sugar
Turn oven up to 220° C.
Instructions
5 tablespoons honey are given
50 ml cream Bring remaining ingredients to a
in the order in which boil, stirring.
50 ml brandy or any other
theyor
liqueur are performed
spirit Spread evenly over pastry.
(“executed”)
300 g flaked almonds Bake until topping is bubbling and
Preheat oven for 200° C has caramelised evenly, about
Line a 30 cm  20 cm baking 15 minutes.
tray with baking paper, Cool before cutting into fingers or
and then with pastry squares.

Sunday, April 14, 2024 11


Correct Algorithm?

Cut chicken into pieces and Arrange chicken on rice, cover


brown the pieces on all casserole and bake in a
sides in a casserole dish in moderate oven (350°F) for
hot olive oil. 20 minutes or until the rice
Remove the chicken and to the is tender.
juices in the casserole add Add beans and artichokes
garlic, onions and green during last 10 minutes of
peppers, and sauté until cooking.
onion is golden.
Add bay leaf, whole tomatoes,
and chicken broth.
When the broth boils add salt,
saffron and rice.

Sunday, April 14, 2024 12


Correct Algorithm?

Cut chicken into pieces and


brown the pieces on all Arrange chicken on rice, cover
sides in a casserole dish in casserole and bake in a
hot olive oil. moderate oven (350°F) for
Remove the chicken and to the 10 minutes.
juices in the casserole add Add beans and artichokes.
garlic, onions and green Cover, and bake for another 10
peppers, and sauté until minutes or until rice is
onion is golden. tender.
Add bay leaf, whole tomatoes,
and chicken broth.
When the broth boils add salt,
saffron and rice.

Sunday, April 14, 2024 13


From Algorithms to Programs

Problem Algorithm:
Algorithm A sequence
of instructions describing
how to do a task (or
process)

Sunday, April 14, 2024


C Program 14
Components of an Algorithm
 Variables and values
 Instructions
 Sequences
 Procedures
 Selections
 Repetitions
 Documentation

Sunday, April 14, 2024 15


Values

 Represent quantities, amounts or


measurements
 May be numerical or alphabetical (or
other things)
 Often have a unit related to their
purpose
 Example:
 Recipe ingredients
Sunday, April 14, 2024 16
Variables

 Are containers for values places to store values

Variable Values

10 cookies
This jar
50 grams of sugar
can contain
3 slices of cake
etc.
Sunday, April 14, 2024 17
Restrictions on Variables
 Variables may be restricted to
contain a specific type of value

Sunday, April 14, 2024 18


Components of an Algorithm
 Values and Variables
 Instruction (a.k.a. primitive)
 Sequence (of instructions)
 Procedure (involving instructions)
 Selection (between instructions)
 Repetition (of instructions)
 Documentation (beside instructions)

Sunday, April 14, 2024 19


Instructions (Primitives)
 Some action that is simple...
 ...and unambiguous...
 ...that the system knows about...
 ...and should be able to actually do

Sunday, April 14, 2024 20


Instructions – Examples
 Take off your shoes
Directions to perform
 Count to 10 specific actions on values
 Cut along dotted lineand variables.
 Knit 1
 Purl 2
 Pull rip-cord firmly
 Sift 10 grams of arsenic

Sunday, April 14, 2024 21


Instructions -- Application
 Some instructions can only be applied
to a specific type of values or
variables
 Examples:

Sunday, April 14, 2024 22


Instructions (Primitives) --
Recommendations
 When writing an algorithm, make
each instruction simple and
unambiguous
 Example:

Cut chicken into pieces Cut chicken into pieces.


and brown the Heat olive oil in a
pieces on all sides in casserole dish.
a casserole dish in Brown the chicken
hot olive oil. pieces in the
Sunday, April 14, 2024 23
casserole dish.
Instruction (Primitives)
 When writing an algorithm,
A “sequence” of make
thesimple
instructions simple and
instructions
unambiguous.
 Example:

Cut chicken into pieces Cut chicken into pieces.


and brown the pieces Heat olive oil in a
on all sides in a
casserole dish in hot
casserole dish.
olive oil. Brown the chicken
Sunday, April 14, 2024 pieces in the 24

casserole dish.

You might also like