You are on page 1of 17

Dr.

Muhammad Umair

07/02/2013

Lecture # 02

DATA STRUCTURE AND ALGORITHM


1

Dr. Muhammad Umair

07/02/2013

BASIC DATA TYPES

Numeric
Integer

Numbers
etc.

0,10,15,4563

Fractional
10.5,

Number

78.67, 20.0

Character
A,

X, U, o, r etc.

Dr. Muhammad Umair

07/02/2013

MEMORY REPRESENTATION (NUMERIC)

Integer Numbers

Binary Number System


positive integers only Maximum decimal Value

2n1 0 2n

Minimum decimal Value

No of values

Dr. Muhammad Umair

07/02/2013

MEMORY REPRESENTATION (NUMERIC)

Integer Numbers

Ones Compliment
negative numbers Minimum Value

-2 n-1 + 1 2 n-1 -1 2n - 1

Maximum Value

No. of Values

Dr. Muhammad Umair

07/02/2013

MEMORY REPRESENTATION (NUMERIC)

Integer Numbers

Twos Compliment
negative number Minimum Value

-2 n-1 2 n-1 -1 2n

Maximum Value

No. of Values

Binary Coded Decimal

Dr. Muhammad Umair

07/02/2013

MEMORY REPRESENTATION(NUMERIC)

Fractional Number

Mantissa Base Exponent

57.78
5778 x 10-2 Mantissa

5778

Base
10

Exponent
-2

Dr. Muhammad Umair

07/02/2013

MEMORY REPRESENTATION (CHARACTER)

Character

byte size

Minimum no. of bits required to represent a character value

Byte

No. of bits used to represent one character in the system

Hardware & Software Implementation

Dr. Muhammad Umair

07/02/2013

INTRODUCTION TO ADT

Data Type

is the collection of objects and the set of operations that act on those objects.
is a data type that is organized in such a way that the specification of the objects and the specification of the operations on the objects is separated from the representation of the objects and the implementation of the operations.

Abstract Data Type

Dr. Muhammad Umair

07/02/2013

CONCEPT OF DATA STRUCTURE

Storage Representation of User Data


Understandable

for computer
for user

Retrieval of Stored Data


Understandable

Transformation of User Data


Operations

to transform data from one to another

Dr. Muhammad Umair

07/02/2013

CONCEPT OF DATA STRUCTURE (CONTINUED)

Domain (D)
Range

of values

Function (F)
Set

of operations of rules

Axioms (A)
Set

10

Dr. Muhammad Umair

07/02/2013

DATA STRUCTURE

Logical or mathematical model of a particular organization of data


Arrays String Link List Tree Graph Stacks & Queues

11

Dr. Muhammad Umair

07/02/2013

OPERATION ON DATA STRUCTURE


Traversing

Searching
Inserting Deleting

Sorting
Merging

12

Dr. Muhammad Umair

07/02/2013

CLASSIFICATION OF DATA STRUCTURE (IMPLEMENTATION)


Data Structure

Physical

Logical

Arrays, Linked List

Strings, Stack, Queues, Tree, Graphs


13

Dr. Muhammad Umair

07/02/2013

CLASSIFICATION OF DATA STRUCTURE (STRUCTURE)


Data Structure

Linear

Non-Linear

Arrays, Linked List, Strings, Stack, Queues

Tree, Graphs, Sets


14

Dr. Muhammad Umair

07/02/2013

ARRAY & ITS MEMORY REPRESENTATION


Identifier keeps the base address Length = UB - LB - 1 Address of particular element

Base

= B, Size of element = W, Lower Bound = LB, Index = I Loc (A[ I ]) = B + W * ( I - LB)


15

Dr. Muhammad Umair

07/02/2013

TWO DIMENSIONAL ARRAY (MEMORY REPRESENTATION


No. of Rows = M, No. of Columns= N Row Major

Loc

(A[I][J]) = B + W * [N (I-RLB) + (J-CLB)] (A[I][J]) = B + W * [M (J-CLB) + (I-RLB)]

Column Major
Loc

16

Dr. Muhammad Umair

07/02/2013

THREE DIMENSIONS

Row Major
A[I][J][K]

= BA + W * [ ( I 1LB) * M * N + ( J - 2LB ) * N + ( K - 3LB)]


= BA + W * [ ( K 3LB) * L * M + ( J - 2LB ) * M + ( I - 1LB)]

Column Major
A[I][J][K]

17

You might also like