You are on page 1of 7

PARVATHY’S ARTS AND

SCIENCE COLLEGE, DINDIGUL

DEPARTMENT OF COMPUTER
SCIENCE

STAFF NAME: MS.F.CELINE INIGO


SUBJECT NAME: DATA STRUCTURES AND COMPUTER
ALGORITHMS
CLASS: II B.SC IT
Unit I: Introduction to Data Structures: The Need For Data Structures – Definitions –
Types – Data Type – Data Structures – Types Of Data Structures – Choice Of Data Structures
– Definitions Related To Data Structures.

The Need for Data structures

• Any computer system are based on three activities – storing, accessing, and
manipulating data in one form or the other

• Divided into major categories like Operating System, databases, Compilers, Artificial
Intelligence, etc.

• These fields will address the tasks of storing, accessing, and manipulating data

• Most of the programmers are trained on programming languages and coding


applications using them

• Gain experience to write programs

• Should they also need a course on Data Structures? Yes they need it.

Definitions

Types

It refers to a ‘domain’ of values

Type Domain of values

Characters Set of characters

Integers …,-4,-3,-2,-1,0,1,2,3,4,…

Real Set of real number

Complex Numbers Real number x Real number

Small fraction { x | x is between 0.0 and 1.0

Boolean {true, false}

Days {Sunday, Monday, Tuesday, Wednesday,


Thursday, Friday, Saturday}

Months { January- December}


Primary colors RGB

Data Type

The domain of values (type) and the operations that can be performed on these values

Data Type Set of operations

Integer Addition, Subtraction, Multiplication, Division,


Modulus

Character Convert a character to lowercase / uppercase, to


find whether the character is alphabetic / digit,
etc

Real Number Arithmetic ( +, -, *, /), fnding absolute, floor, ceil


values

Complex Number Create complex number, find conjugate of the


number, arithmetic operations ( +, -,*,/)

Boolean AND, OR, NOT

There are two types of definitions. They are structural definitions and behavioral definitions

Structural definition – the structure of the values is defined for examples, a fraction can be
defined as the one that has:

1. An optional sign ( +/-)

2. A numerator ( a nonnegative integer)

3. A denominator ( a positive integer)

Behavioral definitions - do not impose any constraint on the structure. Use functions to
define the behaviors of the data type for examples, we can assume, that we have a function
create_fraction(N,D) that creates a fraction, given two integers N and D.

Implementation of a fraction (in c)

A fraction can be coded in any one of the following two ways:


Implementation 1:

Struct Fraction {

Int nr,dr;

} f;

Implementation 2:

#define Nr 0

#define Dr 1

Typedef int fraction[2];

In the main program, you can have statements like the following for defining the fractions
and accessing their numerators and denominators:

Fraction f;

f[Nr] = 4;

f[Dr] = 5;

ADT(Abstract Data Types)

• An abstract data type(ADT) is a data type in which the members of the data type are
unknown to users of the type.

• Abstraction refers to defining new types, hiding the details of implementation

• Both the user and the implementor have to agree on type of the interface

• ADT stack can be defined as a list of elements in which the elements can be inserted
or deleted from one end of the collection. It refers to the ‘Last in First out’ list.

• ADT we define fractions with a set of core functions as:

Create_fraction(N,D),get_Numerator(),get_Denominator()

Using these we can define functions like add, multiply, for specific operations.

Applications Specifications Implementation

Uses ADT Define ADT Implements ADT


Advantages of ADT

• Isolates the application from the implementation

• Supports modular programming

1. program can be split into smaller modules

2. modules can be complied separately

3. Different modules can share the same ADT

• Supports encapsulation

1. Modules are kept independent

2. Can substitute different classes that implement same interface

3. No need to change the modules that use the ADT, when the implementation
change

Pre-and Post-conditions

Pre-conditions refers to the properties of the inputs assumed by the operation defined. This
defines the state of the program the client guarantees that will be true before calling a
function.

For example, in a Stack ( a last in first out list) an ‘insert operation’ assumes that there is
enough space to store the element and similarly the ’delete operation’ assumes that there is
atleast an element in the stack for deletion

Post-conditions specifies the effects of an operation.

Data Structures

It is a physical representation of an ADT. We indicate the data type and also suggest how
these could be stored on the computer system memory.

For example, an integer as a data structure can be defined as a integer data type stored on
consecutive memory bytes.

• Data structure is a STRING, it consists of a sequence of characters

• Stored in consecutive locations- two types of implementations

1. fixed length

2. variable length

Fixed Length - implementation, all strings will have the same amount of memory location
allocated
Variable Length – a terminating character such as NULL is used to terminate a String, this
eliminates the problem of memory wastage

• Another on example is an array stack/ linked stack

• A stack can be implemented either using an array or a linked list

Type Topology Description Examples

Set Collection of unrelated Visitors at an exhibition


items hall, students of a class

Linear One-to-One relationshipQueue at a ticket


counter, jobs in a printer
queue, computers in a
LAN with ring topology

Hierarchical(tree) One-to-many A family tree,


relationship organization chart,
expression tree, folders
and files in a file system

Network(graph) Many-to-many Road map,


relationship Communication network

Types of Data Structures

• Primitive and Compound data structures

• Primitive data structures – basic structure like integer, character

• Compound data structures – an array is an example

• Also classified according to the ordering of the elements in them – Linear and
Nonlinear

• Linear data structures – elements have linear order in between them(1,2 3…)

• Nonlinear structure- ordering is not present

Choice of the Data Structures

• Depends on the application


Example ATM Bank account

Definitions related to data Structures

• File Structures

• Recursive data Structure

You might also like