Data Structure Short Notes
Data Structure Short Notes
A data structure is a storage that is used to store and organize data. It is a way
of arranging data on a computer so that it can be accessed and updated
efficiently.
A data structure is not only used for organizing the data. It is also used for
processing, retrieving, and storing data. There are different basic and advanced
types of data structures that are used in almost every program or software
system that has been developed. So we must have good knowledge of data
structures.
Data structures are an integral part of computers used for the arrangement of
data in memory. They are essential and responsible for organizing, processing,
accessing, and storing data efficiently.
It can hold value but not data. It can hold multiple types of data within a
Therefore, it is dataless. single object.
Data type examples are int, float, Data structure examples are stack, queue,
double, etc. tree, etc.
Arrays:
An array is a linear data structure and it is a collection of items stored at
contiguous memory locations. The idea is to store multiple items of the same
type together in one place. It allows the processing of a large amount of data in
a relatively short period. The first element of the array is indexed by a subscript
of 0. There are different operations possible in an array, like Searching, Sorting,
Inserting, Traversing, Reversing, and Deleting.
Array
Characteristics of an Array:
An array has various characteristics which are as follows:
Arrays use an index-based data structure which helps to identify each of the
elements in an array easily using the index.
If a user wants to store multiple values of the same data type, then the array
can be utilized efficiently.
An array can also handle complex data structures by storing data in a two-
dimensional array.
An array is also used to implement other data structures like Stacks,
Queues, Heaps, Hash tables, etc.
The search process in an array can be done very easily.
Applications of Array:
Different applications of an array are as follows:
An array is used in solving matrix problems.
Database records are also implemented by an array.
It helps in implementing a sorting algorithm.
It is also used to implement other data structures like Stacks, Queues,
Heaps, Hash tables, etc.
An array can be used for CPU scheduling.
Can be applied as a lookup table in computers.
Arrays can be used in speech processing where every speech signal is an
array.
The screen of the computer is also displayed by an array. Here we use a
multidimensional array.
The array is used in many management systems like a library, students,
parliament, etc.
The array is used in the online ticket booking system. Contacts on a cell
phone are displayed by this array.
In games like online chess, where the player can store his past moves as
well as current moves. It indicates a hint of position.
To save images in a specific dimension in the android Like 360*1200
Linked list:
A linked list is a linear data structure in which elements are not stored at
contiguous memory locations. The elements in a linked list are linked using
pointers as shown in the below image:
Types of linked lists:
Singly-linked list
Doubly linked list
Circular linked list
Doubly circular linked list
Linked List
Stack:
Stack is a linear data structure that follows a particular order in which the
operations are performed. The order is LIFO(Last in first out). Entering and
retrieving data is possible from only one end. The entering and retrieving of
data is also called push and pop operation in a stack. There are different
operations possible in a stack like reversing a stack using recursion, Sorting,
Deleting the middle element of a stack, etc.
Characteristics of a Stack:
Stack has various different characteristics which are as follows:
Stack is used in many different algorithms like Tower of Hanoi, tree
traversal, recursion, etc.
Stack is implemented through an array or linked list.
It follows the Last In First Out operation i.e., an element that is inserted first
will pop in last and vice versa.
The insertion and deletion are performed at one end i.e. from the top of the
stack.
In stack, if the allocated space for the stack is full, and still anyone attempts
to add more elements, it will lead to stack overflow.
Applications of Stack:
Different applications of Stack are as follows:
The stack data structure is used in the evaluation and conversion of
arithmetic expressions.
Stack is used in Recursion.
It is used for parenthesis checking.
While reversing a string, the stack is used as well.
Stack is used in memory management.
It is also used for processing function calls.
The stack is used to convert expressions from infix to postfix.
The stack is used to perform undo as well as redo operations in word
processors.
The stack is used in virtual machines like JVM.
The stack is used in the media players. Useful to play the next and previous
song.
The stack is used in recursion operations.
Queue:
Queue is a linear data structure that follows a particular order in which the
operations are performed. The order is First In First Out(FIFO) i.e. the data item
stored first will be accessed first. In this, entering and retrieving data is not done
from only one end. An consumer that came first is served first. Different
operations are performed on a Queue like Reversing a Queue (with or without
using recursion), Reversing the first K elements of a Queue, etc. A few basic
operations performed In Queue are enqueue, dequeue, front, rear, etc.
Characteristics of a Queue:
The queue has various different characteristics which are as follows:
The queue is a FIFO (First In First Out) structure.
To remove the last element of the Queue, all the elements inserted before
the new element in the queue must be removed.
A queue is an ordered list of elements of similar data types.
Applications of Queue:
Tree:
A tree is a non-linear and hierarchical data structure where the elements are
arranged in a tree-like structure. In a tree, the topmost node is called the root
node. Each node contains some data, and data can be of any type. It consists
of a central node, structural nodes, and sub-nodes which are connected via
edges. Different tree data structures allow quicker and easier access to the data
as it is a non-linear data structure. A tree has various terminologies like Node,
Root, Edge, Height of a tree, Degree of a tree, etc.
There are different types of Tree-like .
Tree
Characteristics of a Tree:
The tree has various different characteristics which are as follows:
A tree is also known as a Recursive data structure.
In a tree, the Height of the root can be defined as the longest path from the
root node to the leaf node.
In a tree, one can also calculate the depth from the top to any node. The root
node has a depth of 0.
Applications of Tree:
Different applications of Tree are as follows:
Heap is a tree data structure that is implemented using arrays and used to
implement priority queues.
B-Tree and B+ Tree are used to implement indexing in databases.
Syntax Tree helps in scanning, parsing, generation of code, and evaluation
of arithmetic expressions in Compiler design.
K-D Tree is a space partitioning tree used to organize points in K-
dimensional space.
Spanning trees are used in routers in computer networks.
Operation performed on tree:
A tree is a non-linear data structure that consists of nodes connected by edges.
Here are some common operations performed on trees:
Insertion: New nodes can be added to the tree to create a new branch or to
increase the height of the tree.
Deletion: Nodes can be removed from the tree by updating the references of
the parent node to remove the reference to the current node.
Search: Elements can be searched for in a tree by starting from the root
node and traversing the tree based on the value of the current node until the
desired node is found.
Traversal: The elements in a tree can be traversed in several different ways,
including in-order, pre-order, and post-order traversal.
Height: The height of the tree can be determined by counting the number of
edges from the root node to the furthest leaf node.
Depth: The depth of a node can be determined by counting the number of
edges from the root node to the current node.
Balancing: The tree can be balanced to ensure that the height of the tree is
minimized and the distribution of nodes is as even as possible.
These are some of the most common operations performed on trees. The
specific operations and algorithms used may vary based on the requirements of
the problem and the programming language used. Trees are commonly used in
applications such as searching, sorting, and storing hierarchical data.
Graph
Characteristics of Graph:
The graph has various different characteristics which are as follows:
The maximum distance from a vertex to all the other vertices is considered
the Eccentricity of that vertex.
The vertex having minimum Eccentricity is considered the central point of the
graph.
The minimum value of Eccentricity from all vertices is considered the radius
of a connected graph.
Applications of Graph:
Different applications of Graphs are as follows:
The graph is used to represent the flow of computation.
It is used in modeling graphs.
The operating system uses Resource Allocation Graph.
Also used in the World Wide Web where the web pages represent the
nodes.
Operation performed on Graph:
A graph is a non-linear data structure consisting of nodes and edges. Here are
some common operations performed on graphs:
Add Vertex: New vertices can be added to the graph to represent a new
node.
Add Edge: Edges can be added between vertices to represent a
relationship between nodes.
Remove Vertex: Vertices can be removed from the graph by updating the
references of adjacent vertices to remove the reference to the current vertex.
Remove Edge: Edges can be removed by updating the references of the
adjacent vertices to remove the reference to the current edge.
Depth-First Search (DFS): A graph can be traversed using a depth-first
search by visiting the vertices in a depth-first manner.
Breadth-First Search (BFS): A graph can be traversed using a breadth-first
search by visiting the vertices in a breadth-first manner.
Shortest Path: The shortest path between two vertices can be determined
using algorithms such as Dijkstra’s algorithm or A* algorithm.
Connected Components: The connected components of a graph can be
determined by finding sets of vertices that are connected to each other but
not to any other vertices in the graph.
Cycle Detection: Cycles in a graph can be detected by checking for back
edges during a depth-first search.
These are some of the most common operations performed on graphs. The
specific operations and algorithms used may vary based on the requirements of
the problem and the programming language used. Graphs are commonly used
in applications such as computer networks, social networks, and routing
problems.
Real-Life Applications of Graph:
One of the most common real-world examples of a graph is Google Maps
where cities are located as vertices and paths connecting those vertices are
located as edges of the graph.
A social network is also one real-world example of a graph where every
person on the network is a node, and all of their friendships on the network
are the edges of the graph.
A graph is also used to study molecules in physics and chemistry.