Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 40

Data Structures and Algorithms

Chapter 1
Introduction

1
Reference book
Lipshutz, “Data Structures”, Schaum
Outline Series, 1999.
Horowitz Sahni, “Fundammentals of Data
Structures in C++”, 1999.
Weiss, “Data Structures and algorithm
analysis in C++”.
A.M Tennbaum, “Data Structures using C
and C++”, 2001.
2
3
Data Representation
A computer is a machine that manipulates
data.
 The prime aim of data structure includes to
study:
 how data is organized in a computer,
how it is manipulated,
how it is retrieved,
and how it can be utilized, resulting in more
efficient programs.
4
What is Data Structure?
Data Structure is a systematic way to organize
data in order to use it efficiently.
A data structure is a particular way of storing and
organizing data in a computer so that it can be
used efficiently.
Data may be organized in many different ways,
the logical or mathematical model of a particular
organization of data in memory or on disk is
called Data Structure.
Algorithms are used for manipulation of data
5
6
7
8
Overall Picture
Data Structure and Implementation
Algorithm Design Goals Goals

Correctness Robustness
Adaptability
Efficiency

Reusability

9 September 10, 2001


10
History
Name: Persian mathematician Mohammed al-
Khowarizmi, in Latin became Algorismus
First algorithm: Euclidean Algorithm, greatest
common divisor, 400-300 B.C.
19th century – Charles Babbage, Ada Lovelace.
20th century – Alan Turing, Alonzo Church, John von
Neumann

11 September 10, 2001


On the basis of Sequence (types)

12
On the basis of Size (classifications)

13
14
15
16
17
18
19
Pseudo Code and Flow Charts
There are two commonly used tools to help to
document program logic (the algorithm).
These are
Flowcharts
Pseudocode.
Generally, flowcharts work well for small problems
but Pseudocode is used for larger problems.

20
Pseudo-Code
Pseudo-Code is simply a numbered list of instructions to
perform some task.

21
Writing Pseudo Code
Number each instruction
 This is to enforce the notion of an ordered
sequence of operations
 Furthermore we introduce a dot notation
(e.g. 3.1 come after 3 but before 4) to
number subordinate operations for
conditional and iterative operations
Each instruction should be unambiguous and effective.
Completeness. Nothing is left out.

22
Pseudo-code
Statements are written in simple English without regard to the
final programming language.
Each instruction is written on a separate line.
The pseudo-code is the program-like statements written for
human readers, not for computers. Thus, the pseudo-code
should be readable by anyone who has done a little
programming.
Implementation is to translate the pseudo-code into
programs/software, such as “C++” language programs.

23
Basic Elements of Pseudo-code
A Variable
 Having name and value
 There are two operations performed on a variable
 Assignment Operation is the one in which we
associate a value to a variable.
 The other operation is the one in which at any
given time we intend to retrieve the value
previously assigned to that variable (Read
Operation)

24
Basic Elements of Pseudo-code
Assignment Operation
This operation associates a value to a
variable.
While writing Pseudo-code you may follow
your own syntax.
 Some of the possible syntaxes are:
Assign 3 to x
Set x equal to 3
x=3

25
Basic Operations of Pseudo-code
Read Operation
In this operation we intend to retrieve the
value previously assigned to that variable.
For example Set Value of x equal to y
Read the input from user
This operation causes the algorithm to get
the value of a variable from the user.
Get x Get a, b, c

26
Flow Chart
Some of the common
symbols used in
flowcharts are shown.
…

27

With flowcharting, essential steps of an algorithm are
shown using the shapes above.
 The flow of data between steps is indicated by arrows,
or flowlines. For example, a flowchart (and equivalent
Pseudocode) to compute the interest on a loan is
shown below:

28
29
30
31
Asymptotic Analysis

32
33
34 g(n) = O f(n)
35 g(n) = O f(n)
36 g(n) = O f(n)
37
38
39
40

You might also like