The document provides an introduction to data structures and their fundamentals. It defines data structures as a way of collecting and organizing data to allow for effective operations. It then covers basic terminology related to data organization, classification of data structures, common operations on data structures like traversing, searching, inserting and deleting. It also discusses primitive data structures like integers, floats, characters and non-primitive/composite structures like arrays, stacks and linked lists. For each structure, it provides examples and applications.
1. FUNDAMENTALS OF
DATASTRUCTURE
By
Sri. C. RANJITHKUMAR, M.Sc.(IT & M)., M.Phil.,
Assistant Professor,
Department of Computer Science,
VIVEKANANDA COLLEGE,
TIIRUVEDAKAM WEST MADURAI
Fundamentals of Datastructures by Sri.C.Ranjithkumar, Asst. Professor of CS, VC
1
2. PROLOGUE
Introduction
Basic terminology
Datastructures and its Classification
Datastructure operations
Applications of Datastructures
Fundamentals of Datastructures by Sri.C.Ranjithkumar, Asst. Professor of CS, Vivekananda College 2
3. INTRODUCTION
Data Structure is a way of collecting and organizing data, in such a way that user can perform
operations on these data in an effective way.
Data Structures is about rendering data elements in terms of some relationship, for better
organization and storage.
For example
Consider we have data of player's name "Virat" and age 26. Here "Virat" is of String data type
and 26 is of Integer data type.
User can organize this data as a record like Player record. Now we can collect and store
player's records in a file or database as a data structure.
For example:
“Dhoni" 30, "Gambhir" 31, "Sehwag" 33.
In simple language, Data Structures are structures programmed to store ordered data, so that
various operations can be performed on it easily.
Fundamentals of Datastructures by Sri.C.Ranjithkumar, Asst. Professor of CS, Vivekananda College 3
4. BASIC TERMINOLOGY OF DATA ORGANIZATION
DATA : The term ‘DATA’ simply refers to a value or a set of values.
(EXAMPLE) roll no of a student, marks, name of an employee, address of person etc.
DATA ITEM : A data item refers to a single unit of value.
Data items that can be divided into sub items are called group items
(Eg. Address, Date, Name)
Data items can not be divided in to sub items are called elementary items
(Eg. Roll no, Marks, City, Pin-code etc.)
ENTITY – Data items with similar attributes is called an Entity set
( Eg. all employees of an organization)
INFORMATION - Processed data, Data with given attribute
Fundamentals of Datastructures by Sri.C.Ranjithkumar, Asst. Professor of CS, VC 4
5. BASIC TERMINOLOGY OF DATA ORGANIZATION
FIELD – It is a single elementary unit of information represented as an attribute of an entity
RECORD – It is a collection of field values of a given entity
FILE – It is a collection of records of the entities in a given entity set
(Eg.)
Name Age Sex Roll Number Branch
A 17 M 109cs0132 CSE
B 18 M 109ee1234 EE
Fundamentals of Datastructures by Sri.C.Ranjithkumar, Asst. Professor of CS, VC
5
7. BASIC OPERATIONS
TRAVERSING:
Accessing each record exactly once so that certain items in the record may be processed.
SEARCHING:
Finding the location of a particular record with a given key value, or finding the location of all
records which satisfy one or more conditions.
INSERTING:
Adding a new record to the structure.
DELETING:
Removing the record from the structure.
SORTING:
Managing the data or record in some logical order (Ascending or descending order).
MERGING:
Combining the record in two different sorted files into a single sorted file.
Fundamentals of Datastructures by Sri.C.Ranjithkumar, Asst. Professor of CS, VC 7
8. PRIMITIVE DATASTRUCTURES
PRIMITIVE DATASTRUCTURES:
Primitive data structure is a fundamental type of data structure that stores the data of only one
type
(Eg.) Integer, float, character
Integer variable can hold integer type of value
Float variable can hold floating type of value
Character variable can hold character type of value
Fundamentals of Datastructures by Sri.C.Ranjithkumar, Asst. Professor of CS, VC
8
9. NON-PRIMITIVE DATASTRUCTURES
NON-PRIMITIVE DATA STRUCTURES are user-defined that stores the data of different types in a
single entity.
It is categorized into two types:
1. LINEAR DATA STRUCTURE
2. NON-LINEAR DATA STRUCTURE
LINEAR DATA STRUCTURES are sequential type of data structure, that is all the elements in the
memory are stored in a sequential manner
For example, element stored after the second element would be the third element, the element
stored after the third element would be the fourth element and so on.
Linear data structures holding the sequential values such as Array, Stack, Linked List and Queue
NON-LINEAR DATA STRUCTURES is a kind of random type of data structure. The non-linear data
structures are Tree and Graph.
Fundamentals of Datastructures by Sri.C.Ranjithkumar, Asst. Professor of CS, VC 9
10. DIFFERENCE
PRIMITIVE DATASTRUCTURES NON-PRIMITIVE DATASTRUCTURES
Primitive data structures stores the data of only
one type.
Non-primitive data structures that can store data that
are more than one type.
(Eg) integer, character, float. (Eg) Array, Stack, Linked list, stack.
These contains some value and cannot be
NULL.(empty)
These can store NULL value.(empty)
Size depends on the type of the data structure Size is not fixed.
It can hold a single value in a specific location
It can hold multiple values either in a contiguous
location or random locations
Fundamentals of Datastructures by Sri.C.Ranjithkumar, Asst. Professor of CS, VC 10
11. Characteristics of Primitive Datastructures
INTEGER:
The integer data type contains the numeric values. It contains the whole numbers that can be
either negative or positive. When the range of integer data type is not large enough then in that
case, we can use long.
FLOAT:
The float is a data type that can hold decimal values. When the precision of decimal value
increases then the Double data type is used.
BOOLEAN:
It is a data type that can hold either a True or a False value. It is mainly used for checking the
condition.
CHARACTER:
It is a data type that can hold a single character value both uppercase and lowercase such as 'A'
or 'a'.
Fundamentals of Datastructures by Sri.C.Ranjithkumar, Asst. Professor of CS, VC 11
12. Characteristics of Non-Primitive Datastructures
ARRAY:
Each element in an array is of the same data type and carries the same size that is 4 bytes.
Elements in the array are stored at contiguous memory locations from which the first element is
stored at the smallest memory location.
Elements of the array can be randomly accessed since we can calculate the address of each
element of the array with the given base address and the size of the data element.
User can perform operations such insertion, deletion, traversing, searching and update.
For example:
Fundamentals of Datastructures by Sri.C.Ranjithkumar, Asst. Professor of CS, VC 12
13. Applications of Arrays
To store the possible moves in a chess game.
Password storage and generation
Marks storage and generation
Fundamentals of Datastructures by Sri.C.Ranjithkumar, Asst. Professor of CS, VC 13
14. STACK
A Stack is a linear data structure that follows the LIFO (Last-In-First-Out) principle.
Stack is one ended
It contains top pointer which points to the topmost element of the stack.
Any element added into the stack, it is added only at the top of the stack.
A stack can be defined as a container in which insertion and deletion can be done from the one
end known as the top of the stack.
Fundamentals of Datastructures by Sri.C.Ranjithkumar, Asst. Professor of CS, VC 14
15. Stack Operations
push():
To insert an element in a stack then the operation is known as a push. If the stack is full then
the overflow condition occurs.
pop():
To delete an element from the stack, the operation is known as a pop. If the stack is empty
means that no element exists in the stack, this state is known as an underflow state.
isEmpty():
To determine whether the stack is empty or not.
isFull():
To determine whether the stack is full or not.'
peek():
To returns the element at the given position.
Fundamentals of Datastructures by Sri.C.Ranjithkumar, Asst. Professor of CS, VC 15
16. Stack Operations
count():
It returns the total number of elements available in a stack.
change():
It changes the element at the given position.
display():
It prints all the elements available in the stack.
Fundamentals of Datastructures by Sri.C.Ranjithkumar, Asst. Professor of CS, VC
16
17. PUSH operation in Stack
The steps involved in the PUSH operation is given below:
To insert an element into a stack, user has to check whether the stack is full.
If the user inserts an element into a stack when the stack is full, then it is a overflow condition.
To initialize a stack, user has to set the value of top as -1 to check whether the stack is empty are not.
To insert new element, it is pushed into a stack, first, the value of the top gets incremented, i.e., top=top+1,
and the element will be placed at the new position of the top.
Elements can be inserted until we reach the max size of the stack.
Fundamentals of Datastructures by Sri.C.Ranjithkumar, Asst. Professor of CS, VC 17
18. POP Operation
To delete an element from the stack, user has to check whether the stack is empty.
To delete an element from an empty stack, then it is an underflow condition.
If the stack is not empty, first access is done on the element which is pointed by the top
Pop operation is performed, the top is decremented by 1, i.e., top=top-1.
Fundamentals of Datastructures by Sri.C.Ranjithkumar, Asst. Professor of CS, VC 18
19. Application for Stack
Balancing of symbols: Stack is used for balancing a symbol.
String reversal
Undo/Redo
Fundamentals of Datastructures by Sri.C.Ranjithkumar, Asst. Professor of CS, VC 19
20. LINKED LIST
Linked list is a linear data structure that includes a series of connected nodes.
Linked list can be defined as the nodes that are randomly stored in the memory.
A node in the linked list contains two parts,
the Data part
the Address part.
The last node of the list contains a pointer to the null.
After array, linked list is the second most used data structure.
In a linked list, every link contains a connection to another link.
Fundamentals of Datastructures by Sri.C.Ranjithkumar, Asst. Professor of CS, VC 20
21. Types of Linked List
SINGLY LINKED LIST
DOUBLY LINKED LIST
CIRCULAR LINKED LIST
Fundamentals of Datastructures by Sri.C.Ranjithkumar, Asst. Professor of CS, VC 21
22. Operations in Linked List
INSERTION:
This operation adds an element into the list.
DELETION:
It is performed to delete an operation from the list.
DISPLAY:
It is performed to display the elements of the list.
SEARCH:
It is performed to search an element from the list using the given key.
Fundamentals of Datastructures by Sri.C.Ranjithkumar, Asst. Professor of CS, VC 22
23. Applications of Linked List
Image viewer
Previous and next images are linked, hence can be accessed by next and previous button.
Previous and next page in web browser
User can access previous and next url searched in web browser by pressing back and next button
since, they are linked as linked list.
Music Player
Songs in music player are linked to previous and next song. User can play songs either from starting
or ending of the list.
Fundamentals of Datastructures by Sri.C.Ranjithkumar, Asst. Professor of CS, VC 23