0% found this document useful (0 votes)
13 views

Common Data Structures

1) Common data structures include arrays, linked lists, stacks, queues, trees, and graphs. Arrays store elements contiguously while linked lists link elements using pointers. 2) Stacks follow LIFO while queues follow FIFO. Trees have hierarchical relationships and store data non-linearly. Graphs model pairwise relationships through nodes connected by edges. 3) These structures are widely used in applications like compilers, resource allocation, mapping systems, and finding shortest paths. Each has its own strengths like direct access for arrays or dynamic sizing for linked lists.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Common Data Structures

1) Common data structures include arrays, linked lists, stacks, queues, trees, and graphs. Arrays store elements contiguously while linked lists link elements using pointers. 2) Stacks follow LIFO while queues follow FIFO. Trees have hierarchical relationships and store data non-linearly. Graphs model pairwise relationships through nodes connected by edges. 3) These structures are widely used in applications like compilers, resource allocation, mapping systems, and finding shortest paths. Each has its own strengths like direct access for arrays or dynamic sizing for linked lists.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 29

1

COMMON DATA
STRUCTURES

Prepared by: Maria Lorena SP. Villena, MSCpE, PCpE


2

COMMON DATA STRUCTURES


• In ¼ sheet of paper.
• What Is Pseudocode?
• What are the Common Data Structures?
3

PSUEDOCODE

What is pseudo-code?
➢ Pseudo-code is a shorthand way of describing a computer
program
➢ Rather than using the specific syntax of a computer
language, more general wording is used
➢ It is a mixture of NL and PL expressions, in a systematic way
➢ Using pseudo-code, it is easier for a non-programmer to
understand the general workings of the program
4

Array

• The array is defined as a collection of similar data types


stored in contiguous memory space.
• The array is designed to store similar data altogether. Each
element has an index value for locating the element.
• Generally, the first element of the array is denoted by the
name of the array.
5

Array

• The array is useful in accessing elements faster.


• They have better cache locality
• Multiple elements can be represented using a single name.
• Once the array is declared, its size can’t be changed, so
this can create an issue in run time.
6

Linked List
• Linked lists are also linear data structures but they do not
store data elements in a contiguous memory location.
• All the elements in the linked list are linked using pointers.
• Linked lists are of the following types:
1. Singly Linked List
2. Doubly Linked list
3. Circular Linked list
4. Doubly Circular Linked List

7

Linked List
• Singly Linked List: Singly linked list is the simplest type of
linked list in this each node has some data and a pointer to
the next element. The next pointer holds the address of the
next data element.
8

Linked List
• Doubly Linked list: A doubly linked list also known as a two-way linked
list is the most complex type of linked list as each node points to its next
as well as previous node, so each node has to maintain two pointers
one pointing toward the previous node and pointer pointing to next
node. This enables traversing in the forward as well as backward
direction.
9

Linked List
• Circular Linked list: A circular linked list is similar to a singly linked list,
with the only difference being that its last node points to the first node.
While traversing a circular linked list the operation can be begun with
any node and traversing can be done in either direction, i.e. forward or
backward.
10

Linked List
• Doubly Circular Linked List : It is the most complex linked list as it is a kind
of combination of a doubly linked list and a circular linked list. The first and
last node of the doubly circular linked list does not contain NULL values.

• Linked lists are dynamic in size.


• Insertion and deletion operations are comparatively easy in the linked list.
• It does not allow random access; the entire list has to be traversed sequentially to find a single element.
• Extra space is required for pointers pointing to the previous and next nodes.
11

STACK
• A stack is a linear data structure that works upon the LIFO (Last
in First out) or FILO(First) approach, this means the element
which is inserted at last in the stack will be the first one to be
removed from the stack.
• Stack mainly has two operations:
• Push: It is used to insert any element in the stack.
• Pop: It is used to delete any element from the stack.
12

STACK
13

STACK
➢ It is used in Infix to Postfix or Infix to Prefix conversion.
➢ It is used in Balancing symbols.
➢ Forward and Backward feature of the Web browser.
➢ Undo-Redo feature.
➢ Used in algorithms like Tower of Hanoi.
➢ Used in Backtracking
14

QUEUE
• The queue is a data structure similar to a stack, the only
difference is queue is open from both ends. Unlike stack, Queue
works on the principle of First in First out or Last in Last out.
• The queue has mainly two operations:
➢ Enqueue: The enqueue operation is used to insert any element
into the queue.
➢ Dequeue: Dequeue operation is used to delete any element
from the queue.
15

QUEUE

• The queue is used in CPU scheduling.


• While transferring data asynchronously between two processes. Like in
I/O buffers, pipes, and File IO.
• While implementing semaphores.
• For spooling in printers
• For interruption Handling
16

TREE
• A tree is a non-linear,
hierarchical data structure,
it stores data linearly not
sequentially. It is a collection
of nodes, central node (root
node), Structural
node(parent node), sub-
node(child node, leaf
node).
17

TREE
• Two nodes originating from the same parent node and at the same
height are known as siblings.
1. Traversing is done using the breadth-first search or depth-first search.
2. The tree does not have any loop/ self-loop, or any circuit.
18

TREE
Types of tree Data Structure
• General tree: It does not have any restriction on the number of
child nodes, a parent node can have any number of child
nodes.
• Binary tree: In a binary tree, a parent node can have a
maximum of two child nodes, not more than two. It can have
no child, one child, or at most two child nodes.
19

TREE
Types of tree Data Structure
• Binary Search tree: A binary search tree is similar to a binary
tree with a few more restrictions like the left node of the tree
should be smaller than the root node and the right node of the
tree should be greater than the root node. It includes: AVL tree,
Red Black tree, B-Tree
• Balanced tree: In a Balanced binary search tree if the height of
the left sub-tree and right sub-tree differs at most by 1 then the
resulting tree is known as a balanced tree. Some of the self-
balanced binary search trees are the AVL tree and the Red-
Black tree.
20

TREE
Types of tree Data Structure
• Binary Search tree: A binary search tree is similar to a binary tree with
a few more restrictions like the left node of the tree should be smaller
than the root node and the right node of the tree should be greater
than the root node. It includes: AVL tree, Red Balck tree, B-Tree
• Balanced tree: In a Balanced binary search tree if the height of the
left sub-tree and right sub-tree differs at most by 1 then the resulting
tree is known as a balanced tree. Some of the self-balanced binary
search trees are the AVL tree and the Red-Black tree.
21

TREE
Applications
1. The tree data structure can be used in storing hierarchical
data.
2. It can be used in parse tree formation in compilers
3. Spanning trees are used in finding the minimum paths and used
in air routes.
22

GRAPH
• The graph is a finite set of vertices and edges, vertices known as
nodes and the link between nodes connecting both vertices is
known as an edge. It is denoted as (a,b) means there is n edge
from node a to node b.
• The graph has two representations:
• Adjacency list: To represent the graph in an adjacency list, an array
of linked lists is used. The number of vertices is equal to the size of
the array.
• Adjacency matrix: It is a two-dimensional array of size V*V, where V
is the number of vertices in the graph.
23

GRAPH
Graph Traversal
• The graph can be traversed in two ways:
• Breadth-first search
• Depth-first search
• The graph is mainly used to depict the flow of computation
• In OS, the resource allocation graph used to prevent deadlock
• The graph can be used in mapping systems like Google map
• To find the smallest path between two vertices or two points.
24

COMMON ALGORITHMS
Algorithms along with data structure are basically defined with
the following paradigms:

• Divide and Conquer


• Greedy Algorithm
• Dynamic Programming
25

COMMON ALGORITHMS
Divide and Conquer
• Some standard algorithm follows the divide and conquer
approach for problem-solving like QuickSort, Binary Search,
Merge Sort, etc.
• It works over a simple three-step principle
• Divide the problem into individual sub-problem.
• Conquer or solve each sub-problem.
• Combine the solution to get a solution for the original problem.
26

COMMON ALGORITHMS
Greedy Algorithm
• The greedy algorithm as the name suggests always makes greedy choices
mean always choosing the solution which is taking minimum cost and time,
and recursively making greedy choices until the problem is resolved and
results in an optimal solution to the problem.
• A greedy algorithm is used in optimization problems, some algorithms using
the greedy approach are:
• Kruskal’s algorithm
• Prim’s Algorithm
• Dijkstra’s Shortest path algorithm
• Huffman Coding
27

COMMON ALGORITHMS
Dynamic Programming
• Dynamic programming is an algorithmic approach to solving
the problem, it breaks the problem into subproblems and stores
the result of subproblems to avoid computing the same
subproblem again, it has the following properties:
• Overlapping Subproblems: Storing the solution of a
subproblem and storing it in a table so that the same
expression must not be computed again, saves time and
resources a lot.
28

COMMON ALGORITHMS
Dynamic Programming
• Optimal Substructure: If the optimal solution to the problem is
obtained using optimal substructure properties then the
problem is known as optimal substructure. The properties are:
• Memorization (Top-down approach)
• Tabulation (Bottom-up approach)
• Algorithms using the Dynamic Programming approach are as
follows:
• Floyd Warshall Algorithm
• Bellman Ford Algorithm
• Longest common subsequence
29

Thank you

You might also like