3rd Semester
DATA STRUCTURES AND APPLICATIONS(BCS304)
Module-01
Part-01
1
Data structure
✓A data structure is a particular way of organizing data in a computer
so that it can be used effectively.
✓Data may be organized in many different ways. The logical or
mathematical model of a particular organization of data is called a
data structure.
2
3
4
Need Of Data Structure:
✓The structure of the data and the synthesis of the algorithm are
relative to each other.
✓Data presentation must be easy to understand so the developer, as
well as the user, can make an efficient implementation of the
operation.
✓Data structures provide an easy way of organizing, retrieving,
managing, and storing data.
• Data structure modification is easy.
• It requires less time.
• Save storage memory space.
• Data representation is easy.
• Easy access to the large database.
5
Classifications
6
Primitive vs non-primitive data structure
Data structure means organizing the data in the memory. The data can
be organized in two ways either linear or non-linear way.
There are two types of data structure available for the programming
purpose:
✓Primitive data structure
✓Non-primitive data structure
7
Primitive data structure
✓Primitive data structure is a fundamental type of data structure that
stores the data of only one type whereas the non-primitive data
structure is a type of data structure which is a user-defined that
stores the data of different types in a single entity.
8
Cont..
✓In the case of primitive data structure, it contains fundamental data types
such as integer, float, character, pointer, and these fundamental data
types can hold a single type of value.
✓For example, integer variable can hold integer type of value, float variable
can hold floating type of value, character variable can hold character type
of value whereas the pointer variable can hold pointer type of value.
9
Non-primitive data structure
In the case of non-primitive data structure, it is categorized into two
parts such as
✓linear data structure
✓non-linear data structure.
10
Linear Data Structure:
✓Data structure where data elements are arranged sequentially or linearly
where each and every element is attached to its previous and next
adjacent is called a linear data structure.
✓In linear data structure, single level is involved. Therefore, we can traverse
all the elements in single run only.
✓Linear data structures are easy to implement because computer memory is
arranged in a linear way.
✓Its examples are array, stack, queue, linked list, etc.
11
Non-linear Data Structure:
✓Data structures where data elements are not arranged sequentially or
linearly are called non-linear data structures.
✓In a non-linear data structure, single level is not involved. Therefore, we
can’t traverse all the elements in single run only.
✓Non-linear data structures are not easy to implement in comparison to
linear data structure.
✓It utilizes computer memory efficiently in comparison to a linear data
structure. Its examples are trees and graphs.
12
Data structure Operations
There are different types of operations that can be performed for the
manipulation of data in every data structure.
✓Traversing
✓Searching
✓Insertion
✓Deletion
13
Cont..
Traversing:
✓Traversing a Data Structure means to visit the element stored in it.
✓Accessing each data exactly once in the data structure so that each
data item in traversed or visited.
✓It visits data in a systematic manner.
✓This can be done with any type of DS.
Searching:
✓Searching means to find a particular element in the given data-
structure.
✓It is considered as successful when the required element is found.
✓Searching is the operation which we can performed on data-structures
like array, linked-list, tree, graph, etc.
14
Cont..
Insertion:
✓It is the operation which we apply on all the data-structures.
✓ Insertion means to add an element in the given data structure.
✓The operation of insertion is successful when the required element is
added to the required data-structure.
✓It is unsuccessful in some cases when the size of the data structure is
full and when there is no space in the data-structure to add any
additional element.
✓The insertion has the same name as an insertion in the data-
structure as an array, linked-list, graph, tree. In stack, this operation
is called Push. In the queue, this operation is called Enqueue.
15
Cont..
Deletion:
✓It is the operation which we apply on all the data-structures.
✓Deletion means to delete an element in the given data structure.
✓The operation of deletion is successful when the required element is
deleted from the data structure.
✓The deletion has the same name as a deletion in the data-structure
as an array, linked-list, graph, tree, etc.
✓In stack, this operation is called Pop. In Queue this operation is
called Dequeue.
16
Cont..
Other Operations:
Sorting: Arranging the data in some logical order, for example,
is numerical increasing order or alphabetically.
Merging: Combining the data of two different sorted files into
a single sorted file.
17
Pointers
✓The pointer in C language is a variable which stores the address of
another variable.
✓This variable can be of type int, char, array, function, or any other
pointer. The size of the pointer depends on the architecture. However, in
32-bit architecture the size of a pointer is 2 byte.
Declaring a pointer
The pointer in c language can be declared using * (asterisk symbol). It is
also known as indirection pointer used to dereference a pointer.
18
19
20
Dynamic Memory Allocation in C
✓The concept of dynamic memory allocation in c language enables the
C programmer to allocate memory at runtime.
✓Dynamic memory allocation in c language is possible by 4 functions
of stdlib.h header file.
✓malloc()
✓calloc()
✓realloc()
✓free()
21
22
Static Vs Dynamic
static memory allocation dynamic memory allocation
▪ Memory is allocated at compile ▪ Memory is allocated at run time.
time.
▪ Memory can't be increased ▪ Memory can be increased while
while executing program. executing program.
▪ Used in array. ▪ Used in linked list.
23
Methods used for dynamic memory allocation.
malloc() - allocates single block of requested memory.
calloc() - allocates multiple block of requested memory.
realloc() - reallocates the memory occupied by malloc() or calloc()
functions.
free() - frees the dynamically allocated memory.
24
Arrays
25
26
27
28
29
Arrays
30
31
32
33
34
35
36
37
Thank you
38