Department of ComputerScience And Engineering, Poornima
University, Jaipur, India
3
Data Structure
• Data is a collection of information.
• The data is a programming word, it is values or set of values.
• Data Structure is a way to store and organize data so that it
can be used efficiently.
• Data structure is not any programming language like C, C++,
java etc.
• It is a set of algorithms that we can use in any programming
language to structure the data in the memory.
4.
Department of ComputerScience And Engineering, Poornima
University, Jaipur, India
4
Cont…
Where data structures are used?
Compiler Design
Operating System
DBMS
Artificial Intelligence
Simulation
Numerical Analysis etc…
5.
Department of ComputerScience And Engineering, Poornima
University, Jaipur, India
5
Types of Data Structure
6.
Department of ComputerScience And Engineering, Poornima
University, Jaipur, India
6
Primitive Data Structure
Primitive data structures are the basic building blocks of data manipulation. These
include:
• Int: Represents integer values.
• Char: Used to store single characters.
• Bool: Holds Boolean values, true or false.
• Float: Used for floating-point numbers, which are numbers with a decimal point.
7.
Department of ComputerScience And Engineering, Poornima
University, Jaipur, India
7
Non-Primitive Data Structure
• Moving beyond the basics, non-primitive data structures offer more
sophisticated ways to organize and store data.
• These are generally divided into two categories: Linear and Non-
linear.
• The arrangement of data in a sequential manner is known as a linear
data structure.
• Array, Stack, Queue, Linked-List are the example of linear data
structure.
• Non-linear structures allow data to be stored in a non-sequential
manner, facilitating quick retrieval and linkage based on relationships;
like Tree and Graph.
8.
Department of ComputerScience And Engineering, Poornima
University, Jaipur, India
8
Array
• An array is a collection of items of the same variable type that
are stored at contiguous memory locations.
• Each element in an array is accessed through its index.
9.
Department of ComputerScience And Engineering, Poornima
University, Jaipur, India
9
Stack
• Stack is a linear data structure in which elements can be inserted
as well as deleted from one end.
• LIFO policy is used in Stack data structure.
10.
Department of ComputerScience And Engineering, Poornima
University, Jaipur, India
10
Queue
• Queue is linear data structure in which elements can be inserted
from one end as well deleted from another end
• FIFO policy is used in queue data structure.
11.
Department of ComputerScience And Engineering, Poornima
University, Jaipur, India
11
Linked List
• Linked List is a linear data structure in which each elements
contains two nodes: data, link
12.
Department of ComputerScience And Engineering, Poornima
University, Jaipur, India
12
Tree
• A hierarchical structure consisting of nodes, with each node
containing data and references to child nodes.
• The tree is a non-linear data structure that is comprised of various
nodes.
13.
Department of ComputerScience And Engineering, Poornima
University, Jaipur, India
13
Graph
• A graph is a non-linear data structure with a finite number of
vertices and edges, and these edges are used to connect the
vertices.
• It’s used to represent relationships between different entities.
14.
Department of ComputerScience And Engineering, Poornima
University, Jaipur, India
14
Memory Allocation
15.
Department of ComputerScience And Engineering, Poornima
University, Jaipur, India
15
#include <stdio.h>
int main() {
// Static memory allocation of an array
int arr[5] = {1, 2, 3, 4, 5};
// Printing the array elements
for (int i = 0; i < 5; i++) {
printf("arr[%d] = %dn", i, arr[i]);
}
return 0;
}
Static Memory Allocation