CSC 211 Data Structures: Dr. Iftikhar Azim Niaz
CSC 211 Data Structures: Dr. Iftikhar Azim Niaz
Data Structures
Lecture 1
Dr. Iftikhar Azim Niaz
[email protected]
Quaid-i-Azam University
Deck Officer
Quaid-i-Azam University
Head of Department
Lecturer
Why?
Why are you
studying Data
Structure and
Computer
Science ?
Encarta Dictionary
Course Details
Course Code:
CSC 211
Course Title:
Data Structures
Credit Hours:
3+1
Course Prerequisites CSC141
Course Objectives:
The course is designed to teach students
structures and schemes, which allow them
to write programs to efficiently manipulate,
store, and retrieve data.
Course Description
Course Objectives
Course Goals
Course Goals
Course Outline - I
Course Outline - II
Recommended Books
Textbooks:
Reference Books:
15
16
Assignments .
15%
Quizzes
10%
Sessionals
25%
Final
....
....
. 50%
17
A Nice Quote
Want to get something in life
Always think positive
You will definitely get the thing you want
18
A nice saying
I keep 6 honest serving men.
They taught me all I knew.
Their names are:
WHAT and WHY and WHEN and HOW and WHERE
and WHO.
(R. Kipling)
19
Work Hard
Try More
exercises and
more practice
20
Five Tips
21
22
23
Your Question:
24
So your answer:
Great thinkers
will always be needed.
25
Study:
26
27
Programming is Problem
Solving
Programming is a process of problem solving
Computer Programming
Nicklaus Wirth
Introduction to Problem
Solving
Programming is a problem solving activity.
31
32
1. Requirement Specification
Yummy Cupcake
Problem: You are required to calculate the amount to be
paid by a customer buying cupcakes.
34
Problem Analysis
35
Yummy Cupcake
Input?
Quantity of the cupcake purchased (integer)
Price per cupcake (RM, float)
Output?
Total amount to be paid by the customer (RM, float)
Constraint/condition?
Quantity purchased must be more than zero
Price per cupcake must be more than zero (it is not free)
We assume that the price given is the standard price to all
cupcakes
Formula/equation?
36
Designing algorithm
37
Yummy Cupcake
Major Task:
1.
Read the quantity of cupcake purchased
2.
Read the price per cupcake
3.
Calculate total amount to pay
4.
Display the total amount to pay
However, looking at the above algorithm, we can still further refine
step 3, by introducing the formula to calculate the amount to pay.
After refinement:
5.
Read the quantity of cupcake purchased
6.
Read the price per cupcake
7.
Total amount to pay = quantity of cupcake x price per cupcake
8.
Display the total amount to pay
39
2.
3.
Control Structure
41
Control Structure
What is an Algorithm?
There are two parts to a computer
program.
There is the process or sequence of
steps which are necessary to
complete the given task and
the translation of this process into a
language which the computer can
understand.
43
Algorithm (Definition)
45
From Algorithms to
Programs
Problem
Algorithm: A sequence
of instructions describing
how to do a task
Computer Program
46
Algorithm Representation
Pseudocode
Algorithm
Flow Chart
47
What is Pseudocode?
Pseudocodes
Example of Pseudocode
1. Open freezer door
2. Take out Meal
3. Close freezer door
4. Open microwave door
5. Put Meal on carousel
6. Shut microwave door
7. Set microwave on high for 5 minutes
8. Start microwave
9. Wait 5 minutes
10. Open microwave door
11. Remove Meal
12. Close microwave door
50
Example of Algorithm
procedure Do_Thursday
{
Wake_up ;
Take_A_Shower ;
Eat_Breakfast ;
Drive_To_university ;
Attend_ALGO_Lecture ;
...etc...etc...etc...
Drive_From_university ;
...etc...etc...etc...
}
procedure Do_Week
{
Do_Monday ;
Do_Tuesday ;
Do_Thursday ;
...etc...etc...etc...
}
51
Pseudocode
52
Pseudocode Rules
Pseudocode
Pseudocode
55
1.
2.
3.
4.
5.
Flowcharts
It is an alternative to pseudocoding;
whereas a pseudocode description is
verbal, a flowchart is graphical in nature.
58
Flowchart Symbols
Terminal symbol - indicates the beginning and
end points of an algorithm.
Process symbol - shows an instruction other than
input, output or selection.
Input-output symbol - shows an input or an
output operation.
Disk storage I/O symbol - indicates input
from or output to disk storage.
Printer output symbol - shows hardcopy printer
output.
59
60
statement n.
end
begi
n
statement 1
statement 2
statement n
end
61
begi
n
62
No
elsestatement(s)
Condition?
Yes
thenstatement(s)
63
Begin
Read age
YES
NO
print Pencen
End
64
Example 1
Example 2
65
Exercise
Draw the flowchart diagram for
Example 1 and Example 2
66
Condition?
yes
Loop
Statement(s)
no
67
68
Counter initialisation
Begin
number of users giving his age = 1
while (number of users giving his age <= 10)
read the age from the user.
Loop condition
print the user age.
number of user giving his age + 1
Updating counter
end_while
End
Begin
users = 1
while (users <= 10)
read age
print age.
users = users + 1
end_while
End
69
Begin
users = 1
NO
End
print age
users =users + 1
70
Subsequently..
You can start the
counter with ZERO
Begin
number of users giving his age = 0
while (number of users giving his age < 10)
read the age from the user.
print the user age.
The loop condition
must less than the
number of user giving his age + 1
value it requires to
end_while
stop
End
Begin
users = 0
while (users < 10)
read age
print age.
users = users + 1
end_while
End
Be
consiste
nt
71
Little extra
72
Begin
Example 3
users = 1
while (users <= 10)
begin
Read birth year
age = current year birth year
Note that in this
print age
example, we are
if age > 55
using all the
print Pencen
three control
else
structures:
print Kerja lagi
sequence,
end_if
selection and
users = users + 1
repetition
end
end_while
End
73
Exercise
Draw the flowchart diagram for
Example 3
74
Implementation
75
76
Documentation
Documentation cont
Exercise time!!!
79
Volume calculation
Write a pseudocode and a flowchart for a
C program that reads the value of height,
width and length of a box from the user
and prints its volume.
80
Sum of 1 to 10
Write a pseudocode or flowchart for a
program that would compute and print the
sum of all integers between 1 and 10.
82
Summary