UNIT – I
Introduction to Data Structures: Introduction to the Theory of Data Structures, Data
Representation, Abstract Data Types, Data Types, Primitive Data Types, Data Structure and
Structured Type, Atomic Type, Difference between Abstract Data Types, Data Types, and
Data Structures, Refinement Stages.
1. Introduction to Data Structures:
A data structure is a meaningful way of arranging and storing data in a computer so as to
use it efficiently.
Data is the collection of different numbers, symbols, and alphabets to represent information.
Type of data structure :
Linear Data Structure
Non-Linear Data Structure.
Linear Data Structure:
Elements are arranged in one dimension, also known as linear dimension.
Example: linked lists, stack, queue, etc.
Non-Linear Data Structure
Elements are arranged in one-many, many-one and many-many dimensions.
Example: tree, graph, table, etc.
Applications of Data Structures
Data structures are used in various fields such as:
Operating system
Graphics
Computer Design
Blockchain
Genetics
Image Processing
Simulation etc.
Need of Data Structures or Advantages of Data Structures
It helps to understand the relationship one data element with other and
organize within the memory.
It helps you to analyze the data, store it and organize it in a logical or
mathematical manner.
Data structure provides a way of organizing, managing, and storing data
efficiently.
With the help of data structure, the data items can be traversed easily.
Data structure provides efficiency, reusability and abstraction.
2. Data representation:
Bites and Bytes
All of the data stored and transmitted by digital devices is encoded as bits i.e. 0’s and 1’s.
The word bit, an abbreviation for binary digit, can be further abbreviated as a lowercase b.
A group of eight bits is called a byte and is usually abbreviated as an uppercase B.
Character representation
A standard code ASCII (American Standard for Computer Information Interchange)
defines what character is represented by each sequence. Characters must somehow be
represented in the computer using the 1's and 0's that the hardware works with.
American Standard Code for Information Interchange(ASCII) is an 8-bit code that
specifies character values from 0 to 127.
Representation of Alphabets
Lower case letters: ‘a’-‘z’: 97-122
Upper case letter: ‘A’-‘Z’: 65-90
Digit characters: ‘9’-‘10’: 48-57
Integer representation
An integer is a basic data type which stores negative and non- negative integers.
Example:
Representation schemes for integers:
1. Unsigned Integers: can represent zero and positive integers.
2. Signed Integers: can represent zero, positive and negative integers. Three
representation schemes had been proposed for signed integers:
a. Sign-Magnitude representation
b. 1's Complement representation
c. 2's Complement representation
For example, to find the byte size (8-bits), two's complement representation of -9.
9 (8 + 1) = 00001001
Interchange 0’s and 1’s 11110110 1’s complement
Add +1 +1
11110111 2’s complement
Real number representation
The floating number representation of a number has two part: the first part represents a
signed fixed point number called mantissa. The second part of designates the position of the
decimal (or binary) point and is called the exponent. The fixed point mantissa may be fraction
or an integer. Floating -point is always interpreted to represent a number in the following
form: M x re.
Example −Suppose number is using 32-bit format: the 1 bit sign bit, 8 bits for signed
exponent, and 23 bits for the fractional part. The leading bit 1 is not stored (as it is always 1
for a normalized number) and is referred to as a “hidden bit”.
Then −53.5 is normalized as -53.5=(-110101.1)2=(-1.101011)x25 , which is represented as
following below,
Where 00000101 is the 8-bit binary value of exponent value +5.
3. Abstract Data Type
An Abstract Data Type(ADT) is a mathematical model of a data structure that specifies the
type of data stored, the operations supported on them, and the types of parameters of
the operations. An ADT specifies what each operation does, but not how it does
it. Typically, an ADT can be implemented using one of many different data structures. A
useful first step in deciding what data structure to use in a program is to specify an ADT for
the program.
In general, the steps of building ADT to data structures are:
1. Understand and clarify the nature of the target information unit.
2. Identify and determine which data objects and operations to include in the models.
3. Express this property somewhat formally so that it can be understood and
communicate well.
4. Translate this formal specification into proper language. In C++, this becomes a .h
file. In Java, this is called "user interface".
5. Upon finalized specification, write necessary implementation. This includes storage
scheme and operational detail. Operational detail is expressed as separate functions
(methods).
Example:
Stack ADT
In Stack ADT Implementation instead of data being stored in each node, the pointer
to data is stored.
The program allocates memory for the data and address is passed to the stack ADT.
The head node and the data nodes are encapsulated in the ADT. The calling function
can only see the pointer to the stack.
The stack head structure also contains a pointer to top and count of number of
entries currently in stack.
push() – Insert an element at one end of the stack called top.
pop() – Remove and return the element at the top of the stack, if it is not empty.
peek() – Return the element at the top of the stack without removing it, if the stack
is not empty.
size() – Return the number of elements in the stack.
isEmpty() – Return true if the stack is empty, otherwise return false.
isFull() – Return true if the stack is full, otherwise return false.
4. Data type
Each programming has its own set of data types.
A data type is an internal representation of data in memory.
Data type is an attribute associated with a piece of data that tells a computer system
how to interpret its value. Understanding data types ensures that data is collected in the
preferred format and the value of each property is as expected.
5. Primitive data types or Basic data types
Primitive data types are basic data types of any language that form the basic unit for the
data structure defined by the user. A primitive data type defines how the data will be
internally represented in, stored and retrieved from the memory.
Few primitive data types which are commonly available with most programming
languages are:
Integer
Character
Real/ Floating point numbers
Integer
An integer data type is a primitive data type that may represent a range of numbers
from -2(n-1) to +2(n-1) -1 , where n is the number of bits used to represent the number.
Type Storage size Value range
int 2 or 4 bytes -32,768 to 32,767 or -
2,147,483,648 to 2,147,483,647
unsigned int 2 or 4 bytes 0 to 65,535 or 0 to
4,294,967,295
short 2 bytes -32,768 to 32,767
unsigned short 2 bytes 0 to 65,535
long 8 bytes or (4bytes for 32 bit OS) -9223372036854775808 to
9223372036854775807
unsigned long 8 bytes 0 to 18446744073709551615
Character
Any symbol from set of 0-9, A-Z, a-z and other special symbols is a character. Most of the
computers use 8 bits to represent a character.
Type Storage size Value range
Char 1 byte -128 to 127 or 0 to 255
unsigned char 1 byte 0 to 255
signed char 1 byte -128 to 127
Real/Float numbers
The floating number representation of a number has two part: the first part represents a
signed fixed point number called mantissa. The second part of designates the position of the
decimal (or binary) point and is called the exponent. The fixed point mantissa may be fraction
or an integer. Floating -point is always interpreted to represent a number in the following
form: M x re.
Type Storage Value range Precision
size
float 4 byte 1.2E-38 to 6 decimal places
3.4E+38
double 8 byte 2.3E-308 to 15 decimal places
1.7E+308
long 10 byte 3.4E-4932 to 19 ecimal places
double 1.1E+4932
6. Data Structure and Structured Type
A data structure can be defined as the structural relationship present between the data set.
The data set should be viewed as 2-tuple (N,R).
N- finite set of nodes representing the data structure.
R- is the set of relationship among the nodes.
Fig:A tree data structure
A structured type refers to a data structure which is made up of one or more elements
known as components. These elements are simple data structures that exist in the
language. The components of structured data type grouped together according to the set of
rules, for example the representation of polynomials requires at least two components:
Coefficient
Exponent
Consider a polynomial P(x) = 7x2 + 15x3 - 2 x2 + 9. Here 7, 15, -2, and 9 are the coefficients, and 4,3,2,0 are
the exponents of the terms in the polynomial. On representing this polynomial using a linked list, we have
In C programming language the structure type is implemented using struct keyword.
struct node {
int data;
int key;
struct node *next;
};
7. Atomic data types
Atomic data types have values that cannot be divided or broken down further. Atomic data
types can be either primitive or derived.
Generally, a data structure is represented by a memory block, which has two parts:
Data storage
Address Storage
An atomic type data is a data structure that contains only the data and not the pointers.
8. Difference between Abstract Data Types, Data Types, and Data
Structures
An abstract data type is the specification of the data type which specifies the logical and
mathematical model of the data type.
A data type is the implementation of an abstract data type.
Data structure refers to the collection of computer variables that are connected in some
specific manner.
9. Refinement stages
The best approach to solve a complex problem is to divide it into smaller parts such as each
part become independent module which is easy to mange. This helps in understanding the
problem, analyzing solutions and handling the problems efficiently.
The principle underlying writing the large programs is the top-down refinement. While
writing the main program, we decide exactly how the work will be divided into various
functions and then it is further decided the what will be the task of each function.
In general, there are four levels of refinement processes:
Conceptual level
Algorithmic level or data structure level
Programming or implementation level
Application level
Conceptual level
At this level we decide how the data is related to each other and what operations are
needed.
Algorithmic level or data structure level
At this level we decide the operations on the data as needed by our problem.
Programming or implementation level
At this level, we decide the details of how the data structures will be represented in the
computer memory.
Application level
This levels settles all details required for the particular application such as names for
variables or special requirements for the operations imposed by application.