Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
10 views

Lecture 1a - Algorithm

Uploaded by

doreenprince00
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Lecture 1a - Algorithm

Uploaded by

doreenprince00
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 25

DISCRETE

STRUCTURES
INF 191
SAMUEL N. N.
NORTEY

....Linking Learners Everywhere © 2013 All Rights Reserved


OUTLINE OF LECTURE 1a
• Introduction to course
• Textbooks
• Modelling
• Psedocode
• Exercise
• Summary
....Linking Learners Everywhere © 2013 All Rights Reserved
QUOTES FOR MOTIVATION
• It’s not the load that breaks you
down, it’s the way you carry it - by
Lou Holtz,

• Nothing in the world is ever


completely wrong. Even a stopped
clo==ck is right twice a day – by
Paulo Coelho, Brida
....Linking Learners Everywhere © 2013 All Rights Reserved
TEXT BOOKS
• DISCRETE MATHEMATICS FOR COMPUTING
by Rod Haggarty,
• DISCRETE MATHEMATICS WITH
APPLICATIONS by Kenneth Rosen 5, 6 or 7
Edition
• DISCRETE MATHEMATICS FOR COMPUTER
SCIENTISTS, J. Truss, Addison-Wesley 1999,
ISBN: 0201360616
....Linking Learners Everywhere © 2013 All Rights Reserved
WHAT IS DISCRETE STRUCTURES ?
• Discrete mathematics is the branch of
mathematics dealing with objects that can assume
only distinct, separated values. The term "discrete
mathematics" is therefore used in contrast with
"continuous mathematics," which is the branch of
mathematics dealing with objects that can vary
smoothly (and which includes, for example,
calculus). Whereas discrete objects can often be
characterized by integers, continuous objects
require real numbers. (Wolfram MathWorld)
....Linking Learners Everywhere © 2013 All Rights Reserved
WHAT IS DISCRETE STRUCTURES ?

• Discrete mathematics is the part of


mathematics devoted to the study
of discrete objects. (Here discrete
means consisting of distinct or
unconnected elements.) (Kenneth
Rosen 7th Edition)

....Linking Learners Everywhere © 2013 All Rights Reserved


EXAMPLE OF DISCRETE
COMPONENTS
• What is this?

(google.com) ....Linking Learners Everywhere © 2013 All Rights Reserved


REASON FOR
MODELLING
• AIM:
- To understand how a
machine works
- We achieve this by
modelling it as a discrete
system.
- To acquire the tools &
techniques of how to
....Linking Learners Everywhere © 2013 All Rights Reserved
DIAGRAMATICAL REPRESENTATION

PROBLEM SOLUTION

ABSTRACT TRANSFORMED
MODEL MODEL

....Linking Learners Everywhere © 2013 All Rights Reserved


PROBLEM 1
• The distance (in km) between 6 Ghanaian
towns: Accra, Aflao, Akosombo, Bolga, Cape
Coast and Kumasi. Find a road network of
minimal total length connecting all six
towns? ACCRA AFLAO AKOSOMBO BOLGA CAPE KUMASI
COAST
ACCRA --- 190 104 810 114 270
AFLO 190 --- 128 566 293 317
AKOSOMBO 104 128 --- 508 196 189
BOLGA 810 566 508 --- 633 464
CAPE COAST 114 293 196 633 --- 181
KUMASI 270 317 189 464 181 ---

....Linking Learners Everywhere © 2013 All Rights Reserved


PROPOSED SOLUTION
• We construct a graph whose
vertices denote the towns,
and edges representing the
connecting roads consisting
of all 6 towns.
• Connect all 6 towns which
has minimal total weight by
....Linking Learners Everywhere © 2013 All Rights Reserved
ALGORITHM
• Definition:
- An algorithm is a finite
sequence of precise instructions
for performing a computation or
for solving a problem. (Kenneth
Rosen 7th Edition)
....Linking Learners Everywhere © 2013 All Rights Reserved
ALGORITHM
• PSEUDOCODE
- An intermediate step
between an English language
description of an algorithm and
an implementation of this
algorithm in a programming
language
- Does not follow the syntax of
....Linking Learners Everywhere © 2013 All Rights Reserved
PRIM’S ALGORITHM
• STEP 1 Select any vertex and
connect it to a nearest
neighbour.
• STEP 2 Find an unconnected
vertex that is closest to
previously connected
vertices, and connect it.
• STEP 3 Repeat Step 2 until all
....Linking Learners Everywhere © 2013 All Rights Reserved
BUILDING BLOCKS OF ALGORITHM

• ASSIGNMENT STATEMENT:
- Causes a value to be
assigned to a variable
- Has a general form:

variable name : =
expression
....Linking Learners Everywhere © 2013 All Rights Reserved
PROBLEM 2
• Algorithm to add two numbers,
named First and Second, and
assign the result to Sum.
• SOLUTION:
begin
Input First and Second;
Sum := First + Second:
end ....Linking Learners Everywhere © 2013 All Rights Reserved
BUILDING BLOCKS OF ALGORITHM

• CONTROL STATEMENT:
- It determines the order in
which statements in algorithm
are to be implemented.
- They are of 3 main types:
* Compound Statements
* Conditional Statements
* Iterative Statements
....Linking Learners Everywhere © 2013 All Rights Reserved
BUILDING BLOCKS OF ALGORITHM
• A COMPOUND STATEMENT:
- Is a list of statements to be
executed as a single unit.
- Takes the form:
begin
statement 1;
statement 2:
:
:
statement n;
end ....Linking Learners Everywhere © 2013 All Rights Reserved
PROBLEM 3
• An algorithm to interchange the
values assigned to two variables
One and Two.
• Solution:
begin
Input One and Two:
Store := One:
One := Two;
Two := Store;
end ....Linking Learners Everywhere © 2013 All Rights Reserved
BUILDING BLOCKS
• CONDITIONAL STATEMENT:
- Allows a choice between 2
alternatives
- It is of the form if – then or
if – then – else.

begin
if condition then statement

end
and
begin
if condition then statement
....Linking Learners Everywhere © 2013 All Rights Reserved
PROBLEM 4
• Algorithm to compute the
absolute value of n and store the
result in abs.

• SOLUTION
begin
Input n;
if n < 0 then abs : = -
n
else abs : = n;
output abs;
....Linking Learners Everywhere © 2013 All Rights Reserved
BUILDING BLOCKS
• ITERATIVE STATEMENT OR LOOPS:
- Can be one of the following forms

for variable := initial value to final value


do statement ----------------- (1)
while expression do statement ---
(2)
repeat
statement 1;
statement 2:
:
statement n;
until condition ------------------- (3)
....Linking Learners Everywhere © 2013 All Rights Reserved
PROBLEM 5
• Algorithm to compute the sum of the
squares of the first n positive integers.

• SOLUTION
begin
sum := 0;
for i := 1 to n do
begin
j := i * i;
sum : = sum +j;
end
output sum;
end
....Linking Learners Everywhere © 2013 All Rights Reserved
SUMMARY LECTURE 1
• DISCRETE MATHEMATICS
• MATHEMATICAL MODELLING
• A GRAPH
• ALGORITHM
• PRIM’S ALGORITHM
• PSEUDOCODE
• ASSIGNMENT STATEMENT
• CONTROL STATEMENTS
• A COMPOUND STATEMENT
• A CONDITIONAL STATEMENT
• ITERATIVE STATEMENT
....Linking Learners Everywhere © 2013 All Rights Reserved
Contact

Phone:
Email:
snortey@gtuc.edu.gh ssamnot@
hotmail.com
Skype: snorteygtuc
Website: gtuc.edu.gh

....Linking Learners Everywhere © 2013 All Rights Reserved

You might also like