SlideShare a Scribd company logo
Department of
Computer Science and Engineering
DATA STRUCTURES
School of Computing
Vel Tech Rangarajan Dr. Sagunthala R&D Institute of
Science and Technology
Year : 2019-23
Course Code : 1151CS102
Course Category : Program Core
Unit No : I
Topic : Linear data Structures
Faculty Name : Mrs.A.SANGEETHA
Department of Computer Science and Engineering
COURSE DETAILS
02-02-2023 2
and Project
Management
(SEPM)
Preamble:
This course provides an introduction to the basic concepts and techniques of
Linear and nonlinear data Structures and Analyze the various algorithm.
1150CS201 Problem Solving using C
•Prerequisite Courses:
Sl. No Course Code Course Name
1 1151CS105 System Software
2 1151CS106 Design and Analysis of Algorithm
3 1151CS107 Database Management System
4 1151CS108 Operating Systems
5 1151CS111 Computer Networks
•Related Courses:
Department of Computer Science and Engineering
COURSE OUTCOMES
02-02-2023 3
 Identify and explain user defined data types, linear data structures for
solving real world problems.
 Design modular programs on non linear data structures and
algorithms for solving engineering problems efficiently.
 Illustrate special trees and Hashing Techniques.
 Apply searching techniques in graph traversal
 Apply sorting techniques for real world problems.
Department of Computer Science and Engineering
CORRELATION OF CO WITH PO
02-02-2023 4
COs PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12 PSO1 PSO2 PSO3
CO1 H M L M M M M M M M L
CO2 M M M M L M M M M L
CO3 M M M L L M L M M M
CO4 M M L M M M H
CO5 M M M L L M M M M M H
H- High; M-Medium; L-Low
Department of Computer Science and Engineering
RESOURCES
02-02-2023 5
i. Text Books:
1. M. A. Weiss, “Data Structures and Algorithm Analysis in C”, Second Edition,
Pearson Education, 2007.
ii. Reference:
1. A. V. Aho, J. E. Hopcroft, and J. D. Ullman, “Data Structures and Algorithms”,
Pearson Education, First Edition Reprint 2003.
2. R. F. Gilberg, B. A. Forouzan, “Data Structures”, Second Edition, Thomson
India Edition, 2005.
3. Ellis Horowitz, SartajSahni, Dinesh Mehta, “Fundamentals of Data Structure”,
Computer Science Press, 1995.
Department of Computer Science and Engineering
RESOURCES
02-02-2023 6
iii. Online resources
1. http://simplenotions.wordpress.com/2009/05/13/java-standard-data-structures-
big-o-notation/
2. http://mathworld.wolfram.com/DataStructure.html
Department of Computer Science and Engineering
WHY TO STUDY ?
02-02-2023 7
 Computer science is all about storing and computing from a given data. So
studying data structures helps you deal with different ways of arranging,
processing and storing data.
 All codes are made for real time purpose so data structure allow user to
provide/use/handle data in different ways.
 To deal with BIG DATA
 Computers are basically tool to solve problems which has data to process
on to make some decisions. In real life this data would be very large. So we
need to organize data for better accessing
Department of Computer Science and Engineering
LINEAR DATA STRUCTRES - AGENDA
02-02-2023 8
and Project
Management
(SEPM)
 Introduction
 Time and space complexity analysis
 Abstract Data Type (ADT)
 The List ADT
 Array Implementation
 Linked List Implementation
 Stack ADT
 The Queue ADT
 Applications of Stack, Queue and List.
Department of Computer Science and Engineering
DATA
02-02-2023 9
and Project
Management
(SEPM)
Data is a set of values of qualitative or quantitative variables about
one or more persons or objects
Department of Computer Science and Engineering
DATA
02-02-2023 10
and Project
Management
(SEPM)
Department of Computer Science and Engineering
DATA STRUCTURES
02-02-2023 11
and Project
Management
(SEPM)
• Data structure is a representation of data and the operations
allowed on that data.
• Data-Collection of raw facts.
• Data structure is a way to store and organize data in order to
facilitate the access and modifications.
• Program= Algorithm + Data Structure
Department of Computer Science and Engineering
DATA STRUCTURES
02-02-2023 12
and Project
Management
(SEPM)
Department of Computer Science and Engineering
DATA STRUCTURES
02-02-2023 13
and Project
Management
(SEPM)
Department of Computer Science and Engineering
STORING DATA
02-02-2023 14
and Project
Management
(SEPM)
Department of Computer Science and Engineering
STORING DATA
02-02-2023 15
and Project
Management
(SEPM)
Department of Computer Science and Engineering
STORING DATA
02-02-2023 16
and Project
Management
(SEPM)
Department of Computer Science and Engineering
NEED FOR DATA STRUCTURES
02-02-2023 17
and Project
Management
(SEPM)
• Processing speed: To handle very large data, high-
speed processing is required
• Data Search: Getting a particular record
from database should be quick and with optimum use of
resources.
• Multiple requests: To handle simultaneous requests from
multiple users
Department of Computer Science and Engineering
TIME AND SPACE COMPLEXITY
02-02-2023 18
and Project
Management
(SEPM)
•Time complexity : Amount of time required by the algorithm to
execute to completion.
•Best case - Minimum number of steps on input data of n
elements.
•Worst case - Maximum number of steps on input data of size n.
•Average case - Average number of steps on input data of n
elements.
• Space complexity : Amount of memory space needed the algorithm
in its life cycle.
Department of Computer Science and Engineering
ASYMPTOTIC NOTATION
02-02-2023 19
and Project
Management
(SEPM)
• Mathematical notations used to describe the running time of an algorithm
• Theta Notation (Θ-notation)
 Represents the upper and the lower bound of the running time of an
algorithm
 Used for analyzing the average case complexity of an algorithm.
• Big-O Notation (O-notation)
 Represents the upper bound of the running time of an algorithm.
 Gives the worst case complexity of an algorithm.
• Omega Notation (Ω-notation)
 Represents the lower bound of the running time of an algorithm.
 Provides best case complexity of an algorithm.
Department of Computer Science and Engineering
EXAMPLE
02-02-2023 20
and Project
Management
(SEPM)
#include <stdio.h>
int main()
{
printf("Hello World");
}
#include <stdio.h>
void main()
{
int i, n ;
scanf(“%d”,&n);
for (i = 1; i <= n; i++) {
printf("Hello Word !!!");
}
}
O(1)
O(N)
Department of Computer Science and Engineering
EXAMPLE
02-02-2023 21
O(N^2)
Department of Computer Science and Engineering
TIME COMPLEXITY
02-02-2023 22
and Project
Management
(SEPM)
O(n2) - quadratic time
The number of operations is proportional to the size of the task
squared.
Examples:
A. Some more simplistic sorting algorithms, for instance a selection
sort of n elements
B. Comparing two two-dimensional arrays of size n by n
C. Finding duplicates in an unsorted list of n elements (implemented
with two nested loops). I
O(log n) - logarithmic time
Examples:
A. Binary search in a sorted list of n elements
B. Insert and Find operations for a binary search tree with n nodes
C. Insert and Remove operations for a heap with n nodes.
Department of Computer Science and Engineering
TIME COMPLEXITY
02-02-2023 23
and Project
Management
(SEPM)
O(n log n) - "n log n " time
Examples:
A. More advanced sorting algorithms - quicksort, mergesort
O(a^n) (a > 1) - exponential time
Examples:
A. Recursive Fibonacci implementation
B. Towers of Hanoi
C. Generating all permutations of n symbols
Department of Computer Science and Engineering
TIME COMPLEXITY
02-02-2023 24
and Project
Management
(SEPM)
BETTER
WORSE
• O(1) constant time
• O(log n) log time
• O(n) linear time
• O(n log n) log linear time
• O(n2) quadratic time
• O(n3) cubic time
• O(2n) exponential time
Department of Computer Science and Engineering
TYPES
02-02-2023 25
and Project
Management
(SEPM)
Department of Computer Science and Engineering
PRMITIVE DATA STRUCTURE
02-02-2023 26
and Project
Management
(SEPM)
•Primitive Data Structures are the basic data structures that directly operate upon
the machine instructions.
Department of Computer Science and Engineering
NON PRMITIVE DATA STRUCTURE
02-02-2023 27
and Project
Management
(SEPM)
•The items which are collection of other data structures are called
non-primitive items.
– If more than one values are combined in the single name is
called non-primitive data structures
– Example
Arrays, Stack, Queues etc.
• Types of non-Primitive Data Structures
– Linear
– Non-Linear
Department of Computer Science and Engineering
LINEAR DATA STRUCTURES
02-02-2023 28
and Project
Management
(SEPM)
• Data elements arranged in sequential manner and each member element
is connected to its previous and next element.
• This connection helps to traverse a linear data structure in a single level
and in single run.
•Types
•Arrays
•Queues
•Stacks
•Linked lists
Department of Computer Science and Engineering
ARRAY
02-02-2023 29
and Project
Management
(SEPM)
•Group of similar data items
•Types
•One Dimensional Array
•Two Dimensional Array
•Multi Dimensional Array
•Syntax:
Datatype var_name[size];
Ex:
int a[100];
Department of Computer Science and Engineering
ONE D ARRAY
02-02-2023 30
and Project
Management
(SEPM)
A type of array in which all elements are arranged in the
form of a list is known as 1-D array or single dimensional
array or linear list.
Declaring 1-D Array:
data_type identifier[length]; e.g: int marks[5];
o Data _type: Data type of values to be stored in the array.
o Identifier: Name of the array.
o Length: Number of elements.
0 1 2 3 4
Department of Computer Science and Engineering
ONE D ARRAY
02-02-2023 31
and Project
Management
(SEPM)
A type of array in which all elements are arranged in the
form of a list is known as 1-D array or single dimensional
array or linear list.
Declaring 1-D Array:
data_type identifier[length]; e.g: int marks[5];
o Data _type: Data type of values to be stored in the array.
o Identifier: Name of the array.
o Length: Number of elements.
0 1 2 3 4
Department of Computer Science and Engineering
ONE D ARRAY
02-02-2023 32
One-D array Intialization
The process of assigning values to array elements at the time of
array declaration is called array initialization.
Syntax:
data_type identifier[length]={ List of values };
e.g: int marks[5]={70,54,82,96,49};
o Data _type: Data type of values to be stored in the array.
o Identifier: Name of the array.
o Length: Number of elements
o List of values: Values to initialize the array. Initializing values
must be constant
70 54 82 96 49
Department of Computer Science and Engineering
2 D ARRAY
02-02-2023 33
The two-D array can also be initialized at the time of declaration.
Initialization is performed by assigning the initial values in braces
seperated by commas.
o The elements of each row are enclosed within braces and seperated
by comma.
o All rows are enclosed within braces.
o For number arrays, if all elements are not specified , the un specified
elements are initialized by zero.
Department of Computer Science and Engineering
2 D ARRAY
02-02-2023 34
Syntax:
int arr[4][3]={ {12,5,22},
{95,3,41},
{77,6,53},
{84,59,62} }
12 5 22
95 3 41
77 6 53
84 59 62
Column
indexes
Row
indexes
0
2
1
3
1
0 2
Department of Computer Science and Engineering
MULTI DIMENSIONALARRAY
02-02-2023 35
A variable which represent the list of items using more than
two index (subscript) is called multi-dimensional array.
The general form of multi dimensional array is :
type array-name[s1][s2][s3]…….[sn];
Department of Computer Science and Engineering
MULTI DIMENSIONALARRAY
02-02-2023 36
Where S is the size. Some examples are :
int survey[3][5][6];
float table[5][4][5][3];
Here survey is a three-dimensional array And table is a
four-dimensional array.
Department of Computer Science and Engineering 37
LINKED LIST
• A linked list is a linear data structure.
• Nodes make up linked lists.
• Nodes are structures made up of data and a pointer
to another node.
• Pointer is called next.
02-02-2023
Department of Computer Science and Engineering 38
Stack ADT
Example:
02-02-2023
Department of Computer Science and Engineering 39
QUEUE ADT
10 20 30 40 50
Deletion
(DEQUEUE)
Insertion
(ENQUEUE)
A[0] A[1] A[2] A[3] A[4]
02-02-2023
Department of Computer Science and Engineering 40
TREE
• Tree is a hierarchical data structure which stores the
information naturally in the form of hierarchy style
• Collection of nodes (starting at a root node) together with a list
of references to nodes (the "children")
02-02-2023
Department of Computer Science and Engineering 41
WHY?
EmployeesTable
02-02-2023
Department of Computer Science and Engineering 42
WHY?
EmployeesTable
02-02-2023
Department of Computer Science and Engineering 43
TERMINOLOGIES
02-02-2023
Department of Computer Science and Engineering 44
EXAMPLE
02-02-2023
Department of Computer Science and Engineering
GRAPH
02-02-2023 45
and Project
Management
(SEPM)
• A graph G = (V,E) consists of a finite set of vertices, V,and a finite set of
edges E.
Department of Computer Science and Engineering 46
REPRESENTATION - EXAMPLE
02-02-2023
Department of Computer Science and Engineering
IMPLEMENTATION OF LIST ADT
02-02-2023 47
and Project
Management
(SEPM)
1. Array Implementation
2. Linked List Implementation
3. Cursor Implementation.
Department of Computer Science and Engineering
ABSTRACT DATA TYPE
02-02-2023 48
and Project
Management
(SEPM)
• Stores data and allow various operations on the data to
access and change it.
• A mathematical model, together with various operations
defined on the model
• An ADT is a collection of data and associated operations for
manipulating that data
Department of Computer Science and Engineering
ARRAY IMPLEMENTATION OF LIST
ADT
02-02-2023 49
and Project
Management
(SEPM)
Array is a collection of specific number of data stored in a
consecutive memory locations.
* Insertion and Deletion operation are expensive as it
requires more data movement
* Find and Printlist operations takes constant time.
* Even if the array is dynamically allocated, an
estimate of the maximum size of the list is required which
considerably wastes the memory space.
Department of Computer Science and Engineering
ARRAY ADT-INSERTION
02-02-2023 50
and Project
Management
(SEPM)
Insert()
declare array A
read n
for (i=0;i<n;i++)
read A[i]
set i=0,j=n
get position k
n=n+1
while( j >= k)
A[j+1] = A[j]
j = j - 1
A[k] =item
print array A
Department of Computer Science and Engineering
ARRAY ADT-INSERTION
02-02-2023 51
and Project
Management
(SEPM)
main()
{
int A[] = {1,3,5,7};
int item = 8, k = 3, n = 5;
int i = 0, j = n;
printf("The original array elements are :n");
for(i = 0; i<n; i++)
{
printf("A[%d] = %d n", i, A[i]);
} n = n + 1;
while( j >= k)
{
A[j+1] = A[j];
j = j - 1;
}
Department of Computer Science and Engineering
ARRAY ADT-INSERTION
02-02-2023 52
and Project
Management
(SEPM)
A[k] = item;
printf("The array elements after insertion :n");
for(i = 0; i<n; i++)
{
printf("A[%d] = %d n", i, A[i]);
}
}
Before Insertion
After Insertion
1 3 5 7
1 3 5 7 8
Department of Computer Science and Engineering
ARRAY ADT-DELETION
02-02-2023 53
and Project
Management
(SEPM)
delete()
declare array A
read n
for (i=0;i<n;i++)
read A[i]
get position k
j=k
while( j < n)
A[j-1] = A[j]
j = j + 1
n=n-1
print array A
Department of Computer Science and Engineering
ARRAY ADT-DELETION
02-02-2023 54
and Project
Management
(SEPM)
main()
{
int A[] = {1,3,5,7,8};
int k = 3, n = 5;
int i, j;
printf("The original array elements are :n");
for(i = 0; i<n; i++)
{
printf("A[%d] = %d n", i, A[i]);
}
j = k;
while( j < n)
{
A[j-1] = A[j];
j = j + 1;
}
Department of Computer Science and Engineering
ARRAY ADT-DELETION
02-02-2023 55
and Project
Management
(SEPM)
n = n -1;
printf("The array elements after deletion :n");
for(i = 0; i<n; i++)
{
printf("A[%d] = %d n", i, A[i]);
} }
Before Deletion
After Deletion 1 3 7 8
1 3 5 7 8
Department of Computer Science and Engineering
ARRAY ADT- SEARCH
02-02-2023 56
and Project
Management
(SEPM)
search()
declare array A
read n
for (i=0;i<n;i++)
read A[i]
read k(element to be searched)
set f=0
for(i=0;i<n;i++)
if(A[i]==k)
f=1
print i
break
if(f==0)
print “Element not found”
Department of Computer Science and Engineering
ARRAY ADT- SEARCH
02-02-2023 57
and Project
Management
(SEPM)
main()
{
int list[20],size,i,sElement;
printf("Enter size of the list: ");
scanf("%d",&size);
printf("Enter any %d integer values: ",size);
for(i = 0; i < size; i++)
scanf("%d",&list[i]);
printf("Enter the element to be Search: ");
scanf("%d",&sElement);
Department of Computer Science and Engineering
ARRAY ADT- SEARCH
02-02-2023 58
and Project
Management
(SEPM)
for(i = 0; i < size; i++)
{
if(sElement == list[i])
{
printf("Element is found at %d index", i);
break;
}
}
if(i == size)
printf("Given element is not found in the list!!!");
}
Department of Computer Science and Engineering
ARRAY ADT- SEARCH
02-02-2023 59
and Project
Management
(SEPM)
Department of Computer Science and Engineering 60
LINKED LIST
• A linked list is a linear data structure.
• Nodes make up linked lists.
• Nodes are structures made up of data and a pointer
to another node.
• Pointer is called next.
02-02-2023
Department of Computer Science and Engineering 61
DRAWBACKS OF ARRAY
•Fixed size: Resizing is expensive
•Insertions and Deletions are inefficient:
Elements are usually shifted
•No memory waste if the array is full or almost full; otherwise
may result in much memory waste.
02-02-2023
Department of Computer Science and Engineering 62
WHY LINKED LIST?
•Dynamic size
•Insertions and Deletions are efficient: No Shifting
•Linked List can grow and shrink during run time.
•Since memory is allocated dynamically there is no waste of
memory.
•Faster Access time,can be expanded in constant time without
memory overhead
02-02-2023
Department of Computer Science and Engineering 63
REPRESENTATION OF LINKED LIST
•Static or sequential or array representation.
•The linked list will be maintained or represented by two
parallel arrays of same sizes.
•Dynamic or pointers or linked representation.
•The size of the linked list may increase or decrease according
to the requirement
02-02-2023
Department of Computer Science and Engineering 64
TYPES
• Singly Linked List
• Doubly Linked List
• Circular Linked List
 Singly Circular Linked List
 Doubly Circular Linked List
02-02-2023
Department of Computer Science and Engineering 65
SINGLY LINKED LIST
• Two field
 Data
 Next pointer
02-02-2023
Department of Computer Science and Engineering 66
SINGLY LINKED LIST
• Link part of the last node contains NULL value
which signifies the end of the node
02-02-2023
Department of Computer Science and Engineering 67
DECLARATION
Struct node ;
typedef struct Node *List ;
typedef struct Node *Position ;
int IsLast (List L) ;
int IsEmpty (List L) ;
position Find(int X, List L) ;
void Delete(int X, List L) ;
position FindPrevious(int X, List L) ;
position FindNext(int X, List L) ;
void Insert(int X, List L, Position P) ;
void DeleteList(List L) ;
02-02-2023
Department of Computer Science and Engineering 68
STORING DATA IN A NODE
Node declaration:
struct node
{
int data;
node *next;
}
Storing data:
node *nptr;
nptr= new(node);
nptr->data= 50;
nptr->next = NULL;
nptr
50
02-02-2023
Department of Computer Science and Engineering 69
Insertion of node into a linked list requires a free node
in which the information can be inserted and then the node
can be inserted into the linked list.
At beginning.
At the end of list.
At the specified position.
INSERTING A NEW NODE
02-02-2023
Department of Computer Science and Engineering 70
INSERTION AT BEGINNING
void insert(item)
{
struct node *newNode;
newNode = malloc(sizeof(struct node));
newNode->data = item;
newNode->next = head;
head = newNode;
}
02-02-2023
Department of Computer Science and Engineering 71
INSERTION AT BEGINNING
48 17 142
HEAD //
HEAD 93
Step 1 Step 2
Step
3
02-02-2023
Department of Computer Science and Engineering 72
INSERTION AT BEGINNING
02-02-2023
Department of Computer Science and Engineering 73
INSERTION AT END
void insert(item)
{
struct node *newNode;
newNode = malloc(sizeof(struct node));
newNode->data = item;
newNode->next = NULL;
struct node *temp = head;
while(temp->next != NULL)
{
temp = temp->next;
}
temp->next = newNode;
}
02-02-2023
Department of Computer Science and Engineering 74
INSERTION AT END
48 17 142
HEAD //
93
Step 1 Step 2
Step 3
48 17 142
HEAD //
02-02-2023
Department of Computer Science and Engineering 75
INSERTION AT END
02-02-2023
Department of Computer Science and Engineering 76
INSERTION AT END
void Insert (int X, List L, Position P)
{
position Newnode;
Newnode = malloc (size of (Struct Node));
If (Newnode! = NULL)
{
Newnode ->Element = X;
Newnode ->Next = P-> Next;
P-> Next = Newnode;
}
}
02-02-2023
Department of Computer Science and Engineering 77
INSERTION AT SPECIFIED POSITION
48 17 142
HEAD //
Step 1 Step 2
48 17 142
HEAD //
02-02-2023
Department of Computer Science and Engineering 78
INSERTION AT SPECIFIED POSITION
02-02-2023
Department of Computer Science and Engineering 79
INSERTION AT SPECIFIED POSITION
02-02-2023
Department of Computer Science and Engineering 80
DELETION
void Delete(int X, List L)
{
position P, Temp;
P = Findprevious (X,L);
If (!IsLast(P,L))
{
Temp = P→Next;
P →Next = Temp→Next;
Free (Temp);
}
}
02-02-2023
Department of Computer Science and Engineering 81
Step 1
48 17 142
HEAD //
Step 2
48 17 142
HEAD
DELETION
02-02-2023
Department of Computer Science and Engineering 82
DELETION
02-02-2023
Department of Computer Science and Engineering 83
DELETION
02-02-2023
Department of Computer Science and Engineering 84
void DeleteList (List L)
{
position P, Temp;
P = L →Next;
L→Next = NULL;
while (P! = NULL)
{
Temp = P→Next
free (P);
P = Temp;
}
}
DELETE THE LIST
02-02-2023
Department of Computer Science and Engineering 85
position Find (int X, List L)
{
position P;
P = L-> Next;
while (P! = NULL && P -> Element ! = X)
P = P->Next;
return P;
}
FIND
02-02-2023
Department of Computer Science and Engineering 86
position FindPrevious (int X, List L)
{
position P;
P = L;
while (P -> Next ! = Null && P ->Next -> Element ! = X)
P = P ->Next;
return P;
}
FIND PREVIOUS
02-02-2023
Department of Computer Science and Engineering 87
position FindNext (int X, List L)
{
P = L ->Next;
while (P -> Next! = NULL && P-> Element ! = X)
P = P→Next;
return P→Next;
}
FIND NEXT
02-02-2023
Department of Computer Science and Engineering 88
int IsLast (position P, List L)
{
if (P->Next = = NULL)
return;
}
IsLast()
02-02-2023
Department of Computer Science and Engineering 89
int IsEmpty (List L)
{
if (L -> Next = = NULL)
return (1);
}
IsEmpty()
L
02-02-2023
Department of Computer Science and Engineering 90
1) Insertions and Deletions can be done easily.
2) It space is not wasted as we can get space according to
our requirements.
3) Its size is not fixed.
4) Elements may or may not be stored in consecutive
memory available, even then we can store the data in
computer.
ADVANTAGES
02-02-2023
Department of Computer Science and Engineering 91
1) It requires more space as pointers are also stored with
information.
2) Different amount of time is required to access each
element.
3) If we have to go to a particular element then we have to
go through all those elements that come before that
element.
4) Can not traverse it from last & only from the beginning.
DISADVANTAGES
02-02-2023
Department of Computer Science and Engineering 92
DOUBLY LINKED LIST
 Node Contains
Info : The user’s data.
Prev/Blink: The address of previous node
Next/Flink: The address of next node
Data
Prev Next
02-02-2023
Department of Computer Science and Engineering 93
ADVANTAGES OVER SLL
• A DLL can be traversed in both forward and backward
direction.
• The delete operation in DLL is more efficient
• Easy to insert a new node before a given node.
• In singly linked list, to delete a node, pointer to the previous
node is needed.
• In DLL, we can get the previous node using previous pointer.
02-02-2023
Department of Computer Science and Engineering 94
struct Node {
int data;
struct Node* next; // Pointer to next node in DLL
struct Node* prev; // Pointer to previous node in DLL
};
CREATING A NEW NODE
•Create a head node and assign some data to its data field.
•Make sure that the previous and next address field of
the head node must point to NULL.
02-02-2023
Department of Computer Science and Engineering 95
void Insert (int X, list L, position P)
{
Struct Node * Newnode;
Newnode = malloc (size of (Struct Node));
If (Newnode ! = NULL)
{
Newnode →Element = X;
Newnode →Flink = P Flink;
P →Flink →Blink = Newnode;
P →Flink = Newnode ;
Newnode →Blink = P;
} }
INSERTION
02-02-2023
Department of Computer Science and Engineering 96
INSERTION
02-02-2023
Department of Computer Science and Engineering 97
DELETION
void Delete (int X, List L)
{
position P;
P = Find (X, L);
If ( IsLast (P, L))
{
Temp = P;
P →Blink →Flink = NULL;
free (Temp);
}
02-02-2023
Department of Computer Science and Engineering 98
DELETION
else
{
Temp = P;
P →Blink→ Flink = P→Flink;
P →Flink →Blink = P→Blink;
free (Temp);
}
}
02-02-2023
Department of Computer Science and Engineering 99
DELETION AT SPECIFIED POSITION
02-02-2023
Department of Computer Science and Engineering 100
PROS:
1) Deletion operation is easier.
2) Finding the predecessor & Successor of a node is easier.
CONS:
Every node of DLL Require extra space for an previous pointer.
PROS & CONS
02-02-2023
Department of Computer Science and Engineering 101
1) It is used by browsers to implement backward and forward
navigation of visited web pages i.e. back and forward button
APPLICATIONS
02-02-2023
Department of Computer Science and Engineering 102
CIRCULAR LINKED LIST
• Last node points to the first
• Both singly and doubly linked list can be made into a
circular linked list.
• Circular linked list can be used to help traverse the same list
again and again if needed.
02-02-2023
Department of Computer Science and Engineering 103
WHY?
• To represent arrays that are naturally circular, e.g. the corners of
a polygon, a pool of buffers.
• With a circular list, a pointer to the last node gives easy access
also to the first node, by following one link.
• Some problems are circular and a circular data structure would
be more natural when used to represent it.
02-02-2023
Department of Computer Science and Engineering 104
REPRESENTATION
02-02-2023
Department of Computer Science and Engineering 105
TYPES
1. Singly: The last node points to the first node and there is only
link between the nodes of linked list.
2. Doubly: The last node points to the first node and there are two
links between the nodes of linked list.
02-02-2023
Department of Computer Science and Engineering 106
Node declaration:
struct node
{
int data;
node *next;
};
Declare variable (pointer type) that point to the node:
node *nptr;
Allocate memory for new node:
nptr = new (node);
Enter value:
nptr→data = item;
nptr→next = NULL;
CREATING A NEW NODE- SINGLY
02-02-2023
Department of Computer Science and Engineering 107
BASIC OPERATIONS
1) Insert element at beginning in list.
2) Insert element at end in list.
3) Insert element at any place in list.
4) Delete element from the beginning of list.
5) Delete element from the end of list.
6) Delete element from any place from list.
7) Display
02-02-2023
Department of Computer Science and Engineering 108
Insertion of node into a linked list requires a free node
in which the information can be inserted and then the node
can be inserted into the linked list.
At beginning.
At the end of list.
At the specified position.
INSERTING A NEW NODE
02-02-2023
Department of Computer Science and Engineering 109
INSERTION AT BEGINNING ALGORITHM
• Declare struct node *t.
• Set t:=start.
• Create a new node n by malloc function and enter the
information in info part.
• Check if start=NULL set start=n
set start->next=start. else
• Set n->next=start.
• Repeat step(a)
while(t->next!=start)
▫ (a) set t:=t->next.
• Set t->next=n.
• Set start=n. [end if]
02-02-2023
Department of Computer Science and Engineering 110
INSERTION AT BEGINNING CODE
Void addfront()
{
struct node *t=start;
struct node *n=(struct node*)malloc(sizeof(struct node));
printf(“nenter the information”);
scanf(“%d”,&n->info);
if(start==NULL)
{
start=n;
start->next=start;
}
02-02-2023
Department of Computer Science and Engineering 111
INSERTION AT BEGINNING CODE
else
{
n->next=start;
while(t->next!=start)
t=t->next;
t->next=n;
start=n;
}
02-02-2023
Department of Computer Science and Engineering 112
INSERTION AT BEGINNING
02-02-2023
Department of Computer Science and Engineering 113
INSERTION AT END ALGORITHM
• Declare struct node *t.
• Set t:=start.
• Create a new node n by malloc function and enter the information
in info part.
• Check if start=NULL then,
set start:=n.
set start->next:=start. Otherwise
• Set n->next:=start.
• Repeat step(a)
while(t!=NULL)
▫ (a) set t:=t->next.
• [end of loop]
• Set t->next=n. [end if]
02-02-2023
Department of Computer Science and Engineering 114
INSERTION AT END
02-02-2023
Department of Computer Science and Engineering 115
INSERTION AT END
Void addlast()
{
struct node *t=start;
struct node *n=(struct node*)malloc(sizeof(struct node));
printf(“nenter the information”); scanf(“%d”,&n->info);
if(start==NULL)
{
start=n;
start->next=start;
}
else
{
n->next=start;
while(t!=NULL)
t=t->next;
t->next=n;
}
02-02-2023
Department of Computer Science and Engineering 116
INSERTION AT SPECIFIED POSITION
let
*head -pointer to first node
*p -pointer to the nodeafter whichwewant to insert anewnode.
1. Createanewnodeusingmallocfunction
NewNode=(NodeType*)malloc(sizeof(NodeType));
2. Assigndatato theinfofieldof newnode
NewNode->info=newItem;
3. Setnextof newnodeto nextof p
NewNode->next=p->next;
4. Setnextof p toNewNode
p->next =NewNode
5. End
02-02-2023
Department of Computer Science and Engineering 117
INSERTION AT SPECIFIED POSITION
void insertAfter(struct Node* prev_node, int new_data)
{
if (prev_node == NULL)
{
printf("the given previous node cannot be NULL");
return;
}
struct Node* new_node =(struct Node*) malloc(sizeof(struct Node));
new_node->data = new_data;
new_node->next = prev_node->next;
prev_node->next = new_node;
}
02-02-2023
Department of Computer Science and Engineering 118
INSERTION AT SPECIFIED POSITION
02-02-2023
Department of Computer Science and Engineering 119
DELETION OF A NODE
If the node be deleted, that element should be search all
over the list still the node find. Then it should be deleted.
Deletion at the beginning position of the linked list.
Deletion at the ending position of linked list.
Deletion at a specified position in linked list.
02-02-2023
Department of Computer Science and Engineering 120
DELETION AT BEGINNING
• Check if (start=NULL) then,
print “empty list”
• Check if
(start->next=start) then,
declare free (t)
set start:=NULL otherwise
• Repeat step(a) while(t->next!=start)
▫ (a) set t:=t->next
• [end of loop]
• set start:=start->next
• Declare free(t-next).
• Set t->next:=start.
• [end of if]
02-02-2023
Department of Computer Science and Engineering 121
DELETION AT BEGINNING
02-02-2023
Department of Computer Science and Engineering 122
DELETION AT BEGINNING
Void delfront()
{
struct node *t=start;
if (start==NULL)
printf (“nempty list”);
else if (start->next==start)
{
free (t); start=NULL;
}
else{
while(t->next!=start)
t=t->next;
start=start->next;
free(t->next);
t->next=start;
}}
02-02-2023
Department of Computer Science and Engineering 123
DELETION AT END
• Check if (start=NULL) then, print “empty list”
• Check if (start->next=start)
then,
declare free (t) set start:=NULL otherwise
• Repeat step(a)
while(t->next->next!=start)
▫ (a) set t:=t->next
• [end of loop]
• Declare free(t->next).
• Set t->next:=start.
• [end if]
02-02-2023
Department of Computer Science and Engineering 124
DELETION AT END
02-02-2023
Department of Computer Science and Engineering 125
Void dellast()
{
struct node *t=start;
if (start==NULL)
printf(“nempty list”);
else if (start->next==start)
{
free (t); start=NULL ;
}
else
{
while(t->next->next!=start)
t=t->next;
free(t->next);
t->next=start;
}
}
DELETION AT END
02-02-2023
Department of Computer Science and Engineering 126
DELETION AT SPECIFIED POSITION
02-02-2023
Department of Computer Science and Engineering 127
DELETION AT SPECIFIED POSITION
void deleteNode(struct Node **head, int key)
{
struct Node* temp = *head *prev;
if (temp != NULL && temp->data == key)
{
*head_ref = temp->next;
free(temp);
return;
}
while (temp != NULL && temp->data != key)
{
prev = temp;
temp = temp->next;
}
if (temp == NULL) return;
prev->next = temp->next;
free(temp);
}
02-02-2023
Department of Computer Science and Engineering 128
DELETION AT SPECIFIED POSITION
02-02-2023
Department of Computer Science and Engineering 129
Step 1: IF HEAD == NULL
WRITE "UNDERFLOW"
GOTO STEP 8
[END OF IF]
Step 2: Set PTR = HEAD
Step 3: Set i = 0
Step 4: Repeat step 5 to 7 while PTR != NULL
Step 5: IF PTR → data = item
return i
[END OF IF]
Step 6: i = i + 1
Step 7: PTR = PTR → next
Step 8: Exit
FINDING A N ELEMENT
02-02-2023
Department of Computer Science and Engineering 130
struct Node {
int data;
struct Node* next; // Pointer to next node in DLL
struct Node* prev; // Pointer to previous node in DLL
};
CREATING A NEW NODE – DOUB LY
•Create a head node and assign some data to its data field.
•Make sure that the previous and next address field of
the head node must point to NULL.
•Make the head node as last node.
02-02-2023
Department of Computer Science and Engineering 131
INSERTION
let
*head -pointer to first node
*p -pointer to the nodeafter whichwewant to insert anewnode.
1. Createanewnodeusingmallocfunction
2. Assigndatato theinfofieldof newnode
NewNode->info=newItem;
3. Setnextof newnodeto nextof p
NewNode->next=p->next;
4. Setnextof p toNewNode
p->next =NewNode
5. End
02-02-2023
Department of Computer Science and Engineering 132
INSERTION
02-02-2023
Department of Computer Science and Engineering 133
DELETION
02-02-2023
Department of Computer Science and Engineering 134
DELETION
02-02-2023
Department of Computer Science and Engineering
APPLICATIONS OF LIST
02-02-2023 135
and Project
Management
(SEPM)
1. Polynomial ADT
2. Radix Sort
3. Multilist
Department of Computer Science and Engineering
Stack ADT
02-02-2023 136
and Project
Management
(SEPM)
• Principle-LIFO
•Top pointer
•Operations
•Push()
•Pop()
•Conditions
•Underflow-Empty stack
•Overflow – Full stack
Department of Computer Science and Engineering 137
Stack ADT
Example:
02-02-2023
Department of Computer Science and Engineering
Why it is Used?
02-02-2023 138
and Project
Management
(SEPM)
•Used for
 Reversing elements
 MS paint and Editing apps.
 Expression evaluation
 Backtracking algorithms
To check the string is well formed parenthesis.
Department of Computer Science and Engineering
Stack Operation
02-02-2023 139
and Project
Management
(SEPM)
• Push-Insertion
To push x:
top++;
s[top]=x;
• Pop –Deletion
To pop(x)
s[top]=x
top--;
• Peek() – return the top element
• isEmpty()-to check whether stack is empty or not
• isFull()- to check whether stack is full or not
Department of Computer Science and Engineering
Stack Implementation
02-02-2023 140
and Project
Management
(SEPM)
Two types:
Array Implementation
Linked List Implementation
Department of Computer Science and Engineering
Array Implementation
02-02-2023 141
and Project
Management
(SEPM)
Array Implementation of Stack ADT:
•peek( )
•push( )
•pop( )
•isempty( )
•isfull( )
int peek()
{
return stack[top];
}
Department of Computer Science and Engineering
Array Implementation
02-02-2023 142
and Project
Management
(SEPM)
To check whether stack is empty:
bool isfull()
{
if(top == MAXSIZE-1)
return true;
else
return false;
}
To check whether stack is empty:
bool isempty()
{
if(top == -1)
return true;
else
return false;
}
Department of Computer Science and Engineering
Array Implementation
02-02-2023 143
and Project
Management
(SEPM)
push():
void push(int data)
{
if(!isfull())
{
top = top + 1;
stack[top] = data;
}
else
{
printf(“Stack is full.n");
}
}
Department of Computer Science and Engineering
Array Implementation
02-02-2023 144
and Project
Management
(SEPM)
Push(50)
Department of Computer Science and Engineering
Array Implementation
02-02-2023 145
and Project
Management
(SEPM)
pop():
int pop(int data)
{
if(!isempty())
{
data = stack[top];
top = top - 1;
return data;
}
else
{
printf("Stack is empty.n");
}
}
Department of Computer Science and Engineering
Array Implementation
02-02-2023 146
and Project
Management
(SEPM)
Pop()
Department of Computer Science and Engineering
Linked List Implementation
02-02-2023 147
and Project
Management
(SEPM)
Node Creation:
Step 1 - Define a 'Node' structure with two members data and next.
Step 2 - Define a Node pointer 'top' and set it to NULL.
DATA NEXT
Department of Computer Science and Engineering
CREATE AN EMPTY STACK
02-02-2023 148
and Project
Management
(SEPM)
Stack CreateStack ( )
{
Stack S;
S = malloc (Sizeof (Struct Node));
if (S = = NULL)
Error (" Outof Space");
MakeEmpty (s);
return S;
}
Department of Computer Science and Engineering
MAKE EMPTY
02-02-2023 149
and Project
Management
(SEPM)
void MakeEmpty (Stack S)
{
if (S = = NULL)
Error (" Create Stack First");
else
while (! IsEmpty (s))
pop (s);
}
Department of Computer Science and Engineering
LINKED LIST IMPLEMENTATION - PUSH
02-02-2023 150
and Project
Management
(SEPM)
void push (int X, Stack S)
{
Struct Node * Tempcell;
Tempcell = malloc (sizeof (Struct Node));
If (Tempcell = = NULL)
Error ("Out of Space");
else
{
Tempcell → Element = X;
Tempcell → Next = S → Next;
S→Next = Tempcell;
} }
Department of Computer Science and Engineering
LINKED LIST IMPLEMENTATION - PUSH
02-02-2023 151
and Project
Management
(SEPM)
Department of Computer Science and Engineering
LINKED LIST IMPLEMENTATION - POP
02-02-2023 152
and Project
Management
(SEPM)
void pop (Stack S)
{
Struct Node *Tempcell;
If (IsEmpty (S))
Error ("Empty Stack");
else
{
Tempcell = S→Next;
S→Next = S→Next→Next;
Free (Tempcell);
} }
Department of Computer Science and Engineering
LINKED LIST IMPLEMENTATION - POP
02-02-2023 153
and Project
Management
(SEPM)
Department of Computer Science and Engineering
RETURN TOP ELEMENT
02-02-2023 154
and Project
Management
(SEPM)
int Top (Stack S)
{
If (! IsEmpty (s))
return S→Next→Element;
Error ("Empty Stack");
return 0;
}
Department of Computer Science and Engineering
Applications
02-02-2023 155
and Project
Management
(SEPM)
 Function call
 Evaluation Arithmetic Expression
•Infix to postfix
•Evaluating postfix
 Balancing Parenthesis
Reversing a word
8 Queen problem
Towers of Hanoi
Department of Computer Science and Engineering 156
EVALUATING ARITHMETIC EXPRESSIONS
INFIX notation:
•Operator presents between operands: A+B
POSTFIX notation:
•Operator follows its two operands: AB+
PREFIX notation:
•Operator precedes its two operands: +AB
Operator Precedence
$, ^
*,/
+,-
02-02-2023
Department of Computer Science and Engineering 157
INFIX TO POSTFIX -ALGORITHM
1. Scan the infix expression
2. If the scanned character is an operand, output it.
3. Else,
3.1 If (precedence of scanned operator) >(precedence
of stack operator) - push it.
3.2 Else, Pop all the operators from the stack which are
greater than or equal to in precedence than that of the
scanned operator.
02-02-2023
Department of Computer Science and Engineering 158
4. If the scanned character is an ‘(‘, push it to the stack.
5. If the scanned character is an ‘)’, pop the stack and and output
it until a ‘(‘ is encountered, and discard both the parenthesis.
6. Repeat steps 2-6 until infix expression is scanned.
7. Print the output
8. Pop and output from the stack until it is not empty.
INFIX TO POSTFIX –ALGORITHM
02-02-2023
Department of Computer Science and Engineering 159
CONVERSION OF INFIX INTO POSTFIX
(2+(4-1)*3) into 241-3*+
CURRENT
SYMBOL
ACTION
PERFORMED
STACK STATUS POSTFIX
EXPRESSIO
N
( PUSH ( ( 2
2 2
+ PUSH + (+ 2
( PUSH ( (+( 24
4 24
- PUSH - (+(- 241
1 POP 241-
) (+ 241-
* PUSH * (+* 241-
3 241-3
POP * 241-3*
POP + 241-3*+
)
02-02-2023
Department of Computer Science and Engineering 160
1) Scan the expression from left to right.
2) If an operand is seen, push it onto stack.
3) If an operator is seen, pop of top two elements
(operands) [ x & y ] from stack and perform z = operand y
Push z onto stack.
4) Repeat steps (2) & (3) till scanning is over.
EVALUATING POSTFIX EXPRESSION
02-02-2023
Department of Computer Science and Engineering
EVALUATING POSTFIX EXPRESSION
02-02-2023 161
Department of Computer Science and Engineering 162
BALANCING PARENTHESIS
• Declare a character stack S.
• Now traverse the expression string exp.
 If the current character is a starting bracket (‘(‘ or ‘{‘ or ‘[‘)
then push it to stack.
 If the current character is a closing bracket (‘)’ or ‘}’ or ‘]’)
then pop from stack and if the popped character is the matching
starting bracket then fine else parenthesis are not balanced.
• After complete traversal, if there is some starting bracket left in
stack then “not balanced”
Balancing Parenthesis
02-02-2023
Department of Computer Science and Engineering 163
BALANCING PARENTHESIS
VALID INPUTS INVALID INPUTS
{ } { ( }
( { [ ] } ) ( [ ( ( ) ] )
{ [ ] ( ) } { } [ ] )
[ { ( { } [ ] ( { [ { ) } ( ] } ]
})}]
02-02-2023
Department of Computer Science and Engineering
TOWERS OF HANOI
02-02-2023 164
and Project
Management
(SEPM)
void hanoi (int n, char s, char d, char i)
{
if (n = = 1)
{
print (s, d);
return;
}
else
{
hanoi (n - 1, s, i, d);
print (s, d) ;
hanoi (n-1, i, d, s);
return;
}
}
Department of Computer Science and Engineering
TOWERS OF HANOI
02-02-2023 165
and Project
Management
(SEPM)
Department of Computer Science and Engineering
FUNCTION CALLS
02-02-2023 166
and Project
Management
(SEPM)
When a call is made to a new function all the variables local to the
calling routine need to be saved, otherwise the new function will overwrite
the calling routine variables.
RECURSIVE FUNCTION TO FIND FACTORIAL : -
int fact (int n)
{
int s;
if (n = = 1)
return (1);
else
s = n * fact (n - 1);
return (s);
}
Department of Computer Science and Engineering
Queue ADT
02-02-2023 167
and Project
Management
(SEPM)
• FIFO
•Front is a variable which refers to first position in queue
•Rear is a variable which refers to last position in queue.
•Element is component which has data.
•MaxQueue is variable that describes maximum number
of elements in a queue
Department of Computer Science and Engineering
Queue ADT
02-02-2023 168
and Project
Management
(SEPM)
•Two pointers
Front
Rear
•Basic Operations
enqueue() – Rear end
dequeue() – Front end
•Conditions
Underflow-Empty Queue
Overflow - Full Queue
Department of Computer Science and Engineering 169
QUEUE ADT
10 20 30 40 50
Deletion
(DEQUEUE)
Insertion
(ENQUEUE)
A[0] A[1] A[2] A[3] A[4]
02-02-2023
Department of Computer Science and Engineering 170
Front
Rear
ENQUEUE
• Placing an item in a queue is called “Insertion or
Enqueue”, which is done at the end of the queue called
“Rear”.
02-02-2023
Department of Computer Science and Engineering 171
Front
Rear
DEQUEUE
• Removing an item from a queue is called
“deletion or dequeue”, which is done at the other end
of the queue called “front”.
02-02-2023
Department of Computer Science and Engineering 172
TYPES OF QUEUE
• Linear Queue
• Circular Queue
• Priority Queue
• Deque – Double Ended Queue
 Input Restricted Deque
 Output Restricted Deque
02-02-2023
Department of Computer Science and Engineering 173
•A normal queue
•insertion - Rear
•deletion –Front
LINEAR QUEUE
02-02-2023
Department of Computer Science and Engineering
QUEUE IMPLEMENTATION
02-02-2023 174
and Project
Management
(SEPM)
Two types:
Array Implementation
Linked List Implementation
arr 0 1 7 8 9
2 3 4 5 6
A B C D E F G
front
back
Array Implementation
Department of Computer Science and Engineering 175
void enqueue(item)
{
if (rear = = maxsize-1 )
print (“queue overflow”);
else
rear = rear + 1;
Queue [rear] = item;
}
ENQUEUE
02-02-2023
Department of Computer Science and Engineering 176
ENQUEUE
02-02-2023
Department of Computer Science and Engineering 177
void dequeue()
{
if (front= = -1)
print “queue empty”;
else if(front == rear)
front=rear=-1;
else
{
front = front + 1 ;
item = queue [front];
return item;
}}
DEQUEUE
02-02-2023
Department of Computer Science and Engineering 178
DEQUEUE
02-02-2023
Department of Computer Science and Engineering 179
LIST IMPLEMENTATION QUEUE
using namespace std;
struct QNode {
int data;
QNode* next;
QNode(int d)
{
data = d;
next = NULL;
}
};
struct Queue {
QNode *front, *rear;
Queue()
{
front = rear = NULL;
}
02-02-2023
Department of Computer Science and Engineering 180
LIST IMPLEMENTATION QUEUE
void enQueue(int x)
{
QNode* temp = new QNode(x);
if (rear == NULL) {
front = rear = temp;
return;
}
rear->next = temp;
rear = temp;
}
02-02-2023
Department of Computer Science and Engineering 181
LIST IMPLEMENTATION QUEUE
rear
After inserting 4
02-02-2023
Department of Computer Science and Engineering 182
LIST IMPLEMENTATION QUEUE
void deQueue()
{
if (front == NULL)
return;
QNode* temp = front;
front = front->next;
if (front == NULL)
rear = NULL;
delete (temp);
}
};
02-02-2023
Department of Computer Science and Engineering 183
LIST IMPLEMENTATION QUEUE
front
02-02-2023
Department of Computer Science and Engineering 184
•The last element points to the first element.
•Ring Buffer
Use:
consumes less memory than linear queue
CIRCULAR QUEUE
02-02-2023
Department of Computer Science and Engineering 185
CIRCULAR QUEUE
02-02-2023
Department of Computer Science and Engineering 186
ENQUEUE -ALGORITHM
Insert-Circular-Q(CQueue, Rear, Front, N, Item)
Initailly Rear = 0 and Front = 0.
1. If Front = 0 and Rear = 0 then Set Front := 1 and go to step 4.
2. If Front =1 and Rear = N or Front = Rear + 1
then Print: “Circular Queue Overflow” and Return.
3. If Rear = N then Set Rear := 1 and go to step 5.
4. Set Rear := Rear + 1
5. Set CQueue [Rear] := Item.
6. Return
02-02-2023
Department of Computer Science and Engineering 187
void CEnqueue (int X)
{
if (Front = = (rear + 1) % Maxsize)
print ("Queue is overflow");
else
{
if (front = = -1)
front = rear = 0;
else
rear = (rear + 1)% Maxsize;
CQueue [rear] = X;
} }
ENQUEUE
02-02-2023
Department of Computer Science and Engineering 188
DEQUEUE - ALGORITHM
Delete-Circular-Q(CQueue, Front, Rear, Item)
Initially, Front = 1.
1. If Front = 0 then
Print: “Circular Queue Underflow” and
Return.
2. Set Item := CQueue [Front]
3. If Front = N then Set Front = 1 and Return.
4. If Front = Rear then Set Front = 0 and Rear = 0 and Return.
5. Set Front := Front + 1
6. Return.
02-02-2023
Department of Computer Science and Engineering 189
int CDequeue ( )
{
if (front = = -1)
print ("Queue is underflow");
else
{
X = CQueue [Front];
if (Front = = Rear)
Front = Rear = -1;
else
Front = (Front + 1)% maxsize;
}
return (X);
}
DEQUEUE
02-02-2023
Department of Computer Science and Engineering 190
EXAMPLE
02-02-2023
Department of Computer Science and Engineering 191
EXAMPLE
02-02-2023
Department of Computer Science and Engineering
APPLICATIONS OF QUEUE
02-02-2023 192
and Project
Management
(SEPM)
• Batch processing in an operating system
• To implement Priority Queues.
• Priority Queues can be used to sort the elements using Heap
Sort.
• Simulation.
• Mathematics user Queueing theory.
• Computer networks where the server takes the jobs of the
client as per the queue strategy.
Department of Computer Science and Engineering 193
RESEARCH APPLICATION
• Image processing
-Watershed transformation implementation by hierarchical queues
• The HQ is initialized by storing tokens corresponding to the pixels
labelled in image gin their respective queues.
• In the case of the watershed transform (WTS), this priority level of each
queue corresponds to the grey level of the token (pixel).
• pixels of lower grey level have the highest priority (queues are numbered
according to the grey levels, queue 0 has the highest priority).
02-02-2023
Department of Computer Science and Engineering 194
RESEARCH APPLICATION
02-02-2023
Department of Computer Science and Engineering 195
QUEUEING THEORY
02-02-2023
Thank You
Department of Computer Science and Engineering

More Related Content

Similar to unit 1.pptx

Data and File Structure Lecture Notes
Data and File Structure Lecture NotesData and File Structure Lecture Notes
Data and File Structure Lecture Notes
FellowBuddy.com
 
Introduction to DS.pptx
Introduction to DS.pptxIntroduction to DS.pptx
Introduction to DS.pptx
OnkarModhave
 
Privacy Preserving Multi-keyword Top-K Search based on Cosine Similarity Clus...
Privacy Preserving Multi-keyword Top-K Search based on Cosine Similarity Clus...Privacy Preserving Multi-keyword Top-K Search based on Cosine Similarity Clus...
Privacy Preserving Multi-keyword Top-K Search based on Cosine Similarity Clus...
IRJET Journal
 
Web based-distributed-sesnzer-using-service-oriented-architecture
Web based-distributed-sesnzer-using-service-oriented-architectureWeb based-distributed-sesnzer-using-service-oriented-architecture
Web based-distributed-sesnzer-using-service-oriented-architectureAidah Izzah Huriyah
 
Internship PPT Format-1.pptx
Internship PPT Format-1.pptxInternship PPT Format-1.pptx
Internship PPT Format-1.pptx
SmithaV19
 
It 2ndyear syllabus
It 2ndyear syllabusIt 2ndyear syllabus
It 2ndyear syllabus
Ashish Jain
 
Database Systems - Lecture Week 1
Database Systems - Lecture Week 1Database Systems - Lecture Week 1
Database Systems - Lecture Week 1
Dios Kurniawan
 
PROJECT FOR CSE BY TUSHAR DHOOT
PROJECT FOR CSE BY TUSHAR DHOOTPROJECT FOR CSE BY TUSHAR DHOOT
PROJECT FOR CSE BY TUSHAR DHOOT
Tushar Dhoot
 
Ug 3 1 r19 cse syllabus
Ug 3 1 r19 cse syllabusUg 3 1 r19 cse syllabus
Ug 3 1 r19 cse syllabus
SubbuBuddu
 
Syllabus mca 2 rdbms i
Syllabus mca 2 rdbms iSyllabus mca 2 rdbms i
Syllabus mca 2 rdbms iemailharmeet
 
dsa.ppt
dsa.pptdsa.ppt
dsa.ppt
ssuser1f953d
 
dsa.ppt
dsa.pptdsa.ppt
dsa.ppt
ssuser1f953d
 
dsa (1).ppt
dsa (1).pptdsa (1).ppt
dsa (1).ppt
ssuser1f953d
 
Data Science & Big Data - Theory.pdf
Data Science & Big Data - Theory.pdfData Science & Big Data - Theory.pdf
Data Science & Big Data - Theory.pdf
RAKESHG79
 
Programming Assignment Help
Programming Assignment HelpProgramming Assignment Help
Programming Assignment Help
#essaywriting
 
Spatial decision support and analytics on a campus scale: bringing GIS, CAD, ...
Spatial decision support and analytics on a campus scale: bringing GIS, CAD, ...Spatial decision support and analytics on a campus scale: bringing GIS, CAD, ...
Spatial decision support and analytics on a campus scale: bringing GIS, CAD, ...
Safe Software
 
Enhancing keyword search over relational databases using ontologies
Enhancing keyword search over relational databases using ontologiesEnhancing keyword search over relational databases using ontologies
Enhancing keyword search over relational databases using ontologies
csandit
 
ENHANCING KEYWORD SEARCH OVER RELATIONAL DATABASES USING ONTOLOGIES
ENHANCING KEYWORD SEARCH OVER RELATIONAL DATABASES USING ONTOLOGIES ENHANCING KEYWORD SEARCH OVER RELATIONAL DATABASES USING ONTOLOGIES
ENHANCING KEYWORD SEARCH OVER RELATIONAL DATABASES USING ONTOLOGIES
cscpconf
 
ENHANCING KEYWORD SEARCH OVER RELATIONAL DATABASES USING ONTOLOGIES
ENHANCING KEYWORD SEARCH OVER RELATIONAL DATABASES USING ONTOLOGIESENHANCING KEYWORD SEARCH OVER RELATIONAL DATABASES USING ONTOLOGIES
ENHANCING KEYWORD SEARCH OVER RELATIONAL DATABASES USING ONTOLOGIES
csandit
 

Similar to unit 1.pptx (20)

Data and File Structure Lecture Notes
Data and File Structure Lecture NotesData and File Structure Lecture Notes
Data and File Structure Lecture Notes
 
Introduction to DS.pptx
Introduction to DS.pptxIntroduction to DS.pptx
Introduction to DS.pptx
 
Privacy Preserving Multi-keyword Top-K Search based on Cosine Similarity Clus...
Privacy Preserving Multi-keyword Top-K Search based on Cosine Similarity Clus...Privacy Preserving Multi-keyword Top-K Search based on Cosine Similarity Clus...
Privacy Preserving Multi-keyword Top-K Search based on Cosine Similarity Clus...
 
Web based-distributed-sesnzer-using-service-oriented-architecture
Web based-distributed-sesnzer-using-service-oriented-architectureWeb based-distributed-sesnzer-using-service-oriented-architecture
Web based-distributed-sesnzer-using-service-oriented-architecture
 
Internship PPT Format-1.pptx
Internship PPT Format-1.pptxInternship PPT Format-1.pptx
Internship PPT Format-1.pptx
 
It 2ndyear syllabus
It 2ndyear syllabusIt 2ndyear syllabus
It 2ndyear syllabus
 
Database Systems - Lecture Week 1
Database Systems - Lecture Week 1Database Systems - Lecture Week 1
Database Systems - Lecture Week 1
 
PROJECT FOR CSE BY TUSHAR DHOOT
PROJECT FOR CSE BY TUSHAR DHOOTPROJECT FOR CSE BY TUSHAR DHOOT
PROJECT FOR CSE BY TUSHAR DHOOT
 
Ug 3 1 r19 cse syllabus
Ug 3 1 r19 cse syllabusUg 3 1 r19 cse syllabus
Ug 3 1 r19 cse syllabus
 
Computer engineering university
Computer engineering university Computer engineering university
Computer engineering university
 
Syllabus mca 2 rdbms i
Syllabus mca 2 rdbms iSyllabus mca 2 rdbms i
Syllabus mca 2 rdbms i
 
dsa.ppt
dsa.pptdsa.ppt
dsa.ppt
 
dsa.ppt
dsa.pptdsa.ppt
dsa.ppt
 
dsa (1).ppt
dsa (1).pptdsa (1).ppt
dsa (1).ppt
 
Data Science & Big Data - Theory.pdf
Data Science & Big Data - Theory.pdfData Science & Big Data - Theory.pdf
Data Science & Big Data - Theory.pdf
 
Programming Assignment Help
Programming Assignment HelpProgramming Assignment Help
Programming Assignment Help
 
Spatial decision support and analytics on a campus scale: bringing GIS, CAD, ...
Spatial decision support and analytics on a campus scale: bringing GIS, CAD, ...Spatial decision support and analytics on a campus scale: bringing GIS, CAD, ...
Spatial decision support and analytics on a campus scale: bringing GIS, CAD, ...
 
Enhancing keyword search over relational databases using ontologies
Enhancing keyword search over relational databases using ontologiesEnhancing keyword search over relational databases using ontologies
Enhancing keyword search over relational databases using ontologies
 
ENHANCING KEYWORD SEARCH OVER RELATIONAL DATABASES USING ONTOLOGIES
ENHANCING KEYWORD SEARCH OVER RELATIONAL DATABASES USING ONTOLOGIES ENHANCING KEYWORD SEARCH OVER RELATIONAL DATABASES USING ONTOLOGIES
ENHANCING KEYWORD SEARCH OVER RELATIONAL DATABASES USING ONTOLOGIES
 
ENHANCING KEYWORD SEARCH OVER RELATIONAL DATABASES USING ONTOLOGIES
ENHANCING KEYWORD SEARCH OVER RELATIONAL DATABASES USING ONTOLOGIESENHANCING KEYWORD SEARCH OVER RELATIONAL DATABASES USING ONTOLOGIES
ENHANCING KEYWORD SEARCH OVER RELATIONAL DATABASES USING ONTOLOGIES
 

Recently uploaded

Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 

Recently uploaded (20)

Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 

unit 1.pptx

  • 1. Department of Computer Science and Engineering DATA STRUCTURES School of Computing Vel Tech Rangarajan Dr. Sagunthala R&D Institute of Science and Technology Year : 2019-23 Course Code : 1151CS102 Course Category : Program Core Unit No : I Topic : Linear data Structures Faculty Name : Mrs.A.SANGEETHA
  • 2. Department of Computer Science and Engineering COURSE DETAILS 02-02-2023 2 and Project Management (SEPM) Preamble: This course provides an introduction to the basic concepts and techniques of Linear and nonlinear data Structures and Analyze the various algorithm. 1150CS201 Problem Solving using C •Prerequisite Courses: Sl. No Course Code Course Name 1 1151CS105 System Software 2 1151CS106 Design and Analysis of Algorithm 3 1151CS107 Database Management System 4 1151CS108 Operating Systems 5 1151CS111 Computer Networks •Related Courses:
  • 3. Department of Computer Science and Engineering COURSE OUTCOMES 02-02-2023 3  Identify and explain user defined data types, linear data structures for solving real world problems.  Design modular programs on non linear data structures and algorithms for solving engineering problems efficiently.  Illustrate special trees and Hashing Techniques.  Apply searching techniques in graph traversal  Apply sorting techniques for real world problems.
  • 4. Department of Computer Science and Engineering CORRELATION OF CO WITH PO 02-02-2023 4 COs PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12 PSO1 PSO2 PSO3 CO1 H M L M M M M M M M L CO2 M M M M L M M M M L CO3 M M M L L M L M M M CO4 M M L M M M H CO5 M M M L L M M M M M H H- High; M-Medium; L-Low
  • 5. Department of Computer Science and Engineering RESOURCES 02-02-2023 5 i. Text Books: 1. M. A. Weiss, “Data Structures and Algorithm Analysis in C”, Second Edition, Pearson Education, 2007. ii. Reference: 1. A. V. Aho, J. E. Hopcroft, and J. D. Ullman, “Data Structures and Algorithms”, Pearson Education, First Edition Reprint 2003. 2. R. F. Gilberg, B. A. Forouzan, “Data Structures”, Second Edition, Thomson India Edition, 2005. 3. Ellis Horowitz, SartajSahni, Dinesh Mehta, “Fundamentals of Data Structure”, Computer Science Press, 1995.
  • 6. Department of Computer Science and Engineering RESOURCES 02-02-2023 6 iii. Online resources 1. http://simplenotions.wordpress.com/2009/05/13/java-standard-data-structures- big-o-notation/ 2. http://mathworld.wolfram.com/DataStructure.html
  • 7. Department of Computer Science and Engineering WHY TO STUDY ? 02-02-2023 7  Computer science is all about storing and computing from a given data. So studying data structures helps you deal with different ways of arranging, processing and storing data.  All codes are made for real time purpose so data structure allow user to provide/use/handle data in different ways.  To deal with BIG DATA  Computers are basically tool to solve problems which has data to process on to make some decisions. In real life this data would be very large. So we need to organize data for better accessing
  • 8. Department of Computer Science and Engineering LINEAR DATA STRUCTRES - AGENDA 02-02-2023 8 and Project Management (SEPM)  Introduction  Time and space complexity analysis  Abstract Data Type (ADT)  The List ADT  Array Implementation  Linked List Implementation  Stack ADT  The Queue ADT  Applications of Stack, Queue and List.
  • 9. Department of Computer Science and Engineering DATA 02-02-2023 9 and Project Management (SEPM) Data is a set of values of qualitative or quantitative variables about one or more persons or objects
  • 10. Department of Computer Science and Engineering DATA 02-02-2023 10 and Project Management (SEPM)
  • 11. Department of Computer Science and Engineering DATA STRUCTURES 02-02-2023 11 and Project Management (SEPM) • Data structure is a representation of data and the operations allowed on that data. • Data-Collection of raw facts. • Data structure is a way to store and organize data in order to facilitate the access and modifications. • Program= Algorithm + Data Structure
  • 12. Department of Computer Science and Engineering DATA STRUCTURES 02-02-2023 12 and Project Management (SEPM)
  • 13. Department of Computer Science and Engineering DATA STRUCTURES 02-02-2023 13 and Project Management (SEPM)
  • 14. Department of Computer Science and Engineering STORING DATA 02-02-2023 14 and Project Management (SEPM)
  • 15. Department of Computer Science and Engineering STORING DATA 02-02-2023 15 and Project Management (SEPM)
  • 16. Department of Computer Science and Engineering STORING DATA 02-02-2023 16 and Project Management (SEPM)
  • 17. Department of Computer Science and Engineering NEED FOR DATA STRUCTURES 02-02-2023 17 and Project Management (SEPM) • Processing speed: To handle very large data, high- speed processing is required • Data Search: Getting a particular record from database should be quick and with optimum use of resources. • Multiple requests: To handle simultaneous requests from multiple users
  • 18. Department of Computer Science and Engineering TIME AND SPACE COMPLEXITY 02-02-2023 18 and Project Management (SEPM) •Time complexity : Amount of time required by the algorithm to execute to completion. •Best case - Minimum number of steps on input data of n elements. •Worst case - Maximum number of steps on input data of size n. •Average case - Average number of steps on input data of n elements. • Space complexity : Amount of memory space needed the algorithm in its life cycle.
  • 19. Department of Computer Science and Engineering ASYMPTOTIC NOTATION 02-02-2023 19 and Project Management (SEPM) • Mathematical notations used to describe the running time of an algorithm • Theta Notation (Θ-notation)  Represents the upper and the lower bound of the running time of an algorithm  Used for analyzing the average case complexity of an algorithm. • Big-O Notation (O-notation)  Represents the upper bound of the running time of an algorithm.  Gives the worst case complexity of an algorithm. • Omega Notation (Ω-notation)  Represents the lower bound of the running time of an algorithm.  Provides best case complexity of an algorithm.
  • 20. Department of Computer Science and Engineering EXAMPLE 02-02-2023 20 and Project Management (SEPM) #include <stdio.h> int main() { printf("Hello World"); } #include <stdio.h> void main() { int i, n ; scanf(“%d”,&n); for (i = 1; i <= n; i++) { printf("Hello Word !!!"); } } O(1) O(N)
  • 21. Department of Computer Science and Engineering EXAMPLE 02-02-2023 21 O(N^2)
  • 22. Department of Computer Science and Engineering TIME COMPLEXITY 02-02-2023 22 and Project Management (SEPM) O(n2) - quadratic time The number of operations is proportional to the size of the task squared. Examples: A. Some more simplistic sorting algorithms, for instance a selection sort of n elements B. Comparing two two-dimensional arrays of size n by n C. Finding duplicates in an unsorted list of n elements (implemented with two nested loops). I O(log n) - logarithmic time Examples: A. Binary search in a sorted list of n elements B. Insert and Find operations for a binary search tree with n nodes C. Insert and Remove operations for a heap with n nodes.
  • 23. Department of Computer Science and Engineering TIME COMPLEXITY 02-02-2023 23 and Project Management (SEPM) O(n log n) - "n log n " time Examples: A. More advanced sorting algorithms - quicksort, mergesort O(a^n) (a > 1) - exponential time Examples: A. Recursive Fibonacci implementation B. Towers of Hanoi C. Generating all permutations of n symbols
  • 24. Department of Computer Science and Engineering TIME COMPLEXITY 02-02-2023 24 and Project Management (SEPM) BETTER WORSE • O(1) constant time • O(log n) log time • O(n) linear time • O(n log n) log linear time • O(n2) quadratic time • O(n3) cubic time • O(2n) exponential time
  • 25. Department of Computer Science and Engineering TYPES 02-02-2023 25 and Project Management (SEPM)
  • 26. Department of Computer Science and Engineering PRMITIVE DATA STRUCTURE 02-02-2023 26 and Project Management (SEPM) •Primitive Data Structures are the basic data structures that directly operate upon the machine instructions.
  • 27. Department of Computer Science and Engineering NON PRMITIVE DATA STRUCTURE 02-02-2023 27 and Project Management (SEPM) •The items which are collection of other data structures are called non-primitive items. – If more than one values are combined in the single name is called non-primitive data structures – Example Arrays, Stack, Queues etc. • Types of non-Primitive Data Structures – Linear – Non-Linear
  • 28. Department of Computer Science and Engineering LINEAR DATA STRUCTURES 02-02-2023 28 and Project Management (SEPM) • Data elements arranged in sequential manner and each member element is connected to its previous and next element. • This connection helps to traverse a linear data structure in a single level and in single run. •Types •Arrays •Queues •Stacks •Linked lists
  • 29. Department of Computer Science and Engineering ARRAY 02-02-2023 29 and Project Management (SEPM) •Group of similar data items •Types •One Dimensional Array •Two Dimensional Array •Multi Dimensional Array •Syntax: Datatype var_name[size]; Ex: int a[100];
  • 30. Department of Computer Science and Engineering ONE D ARRAY 02-02-2023 30 and Project Management (SEPM) A type of array in which all elements are arranged in the form of a list is known as 1-D array or single dimensional array or linear list. Declaring 1-D Array: data_type identifier[length]; e.g: int marks[5]; o Data _type: Data type of values to be stored in the array. o Identifier: Name of the array. o Length: Number of elements. 0 1 2 3 4
  • 31. Department of Computer Science and Engineering ONE D ARRAY 02-02-2023 31 and Project Management (SEPM) A type of array in which all elements are arranged in the form of a list is known as 1-D array or single dimensional array or linear list. Declaring 1-D Array: data_type identifier[length]; e.g: int marks[5]; o Data _type: Data type of values to be stored in the array. o Identifier: Name of the array. o Length: Number of elements. 0 1 2 3 4
  • 32. Department of Computer Science and Engineering ONE D ARRAY 02-02-2023 32 One-D array Intialization The process of assigning values to array elements at the time of array declaration is called array initialization. Syntax: data_type identifier[length]={ List of values }; e.g: int marks[5]={70,54,82,96,49}; o Data _type: Data type of values to be stored in the array. o Identifier: Name of the array. o Length: Number of elements o List of values: Values to initialize the array. Initializing values must be constant 70 54 82 96 49
  • 33. Department of Computer Science and Engineering 2 D ARRAY 02-02-2023 33 The two-D array can also be initialized at the time of declaration. Initialization is performed by assigning the initial values in braces seperated by commas. o The elements of each row are enclosed within braces and seperated by comma. o All rows are enclosed within braces. o For number arrays, if all elements are not specified , the un specified elements are initialized by zero.
  • 34. Department of Computer Science and Engineering 2 D ARRAY 02-02-2023 34 Syntax: int arr[4][3]={ {12,5,22}, {95,3,41}, {77,6,53}, {84,59,62} } 12 5 22 95 3 41 77 6 53 84 59 62 Column indexes Row indexes 0 2 1 3 1 0 2
  • 35. Department of Computer Science and Engineering MULTI DIMENSIONALARRAY 02-02-2023 35 A variable which represent the list of items using more than two index (subscript) is called multi-dimensional array. The general form of multi dimensional array is : type array-name[s1][s2][s3]…….[sn];
  • 36. Department of Computer Science and Engineering MULTI DIMENSIONALARRAY 02-02-2023 36 Where S is the size. Some examples are : int survey[3][5][6]; float table[5][4][5][3]; Here survey is a three-dimensional array And table is a four-dimensional array.
  • 37. Department of Computer Science and Engineering 37 LINKED LIST • A linked list is a linear data structure. • Nodes make up linked lists. • Nodes are structures made up of data and a pointer to another node. • Pointer is called next. 02-02-2023
  • 38. Department of Computer Science and Engineering 38 Stack ADT Example: 02-02-2023
  • 39. Department of Computer Science and Engineering 39 QUEUE ADT 10 20 30 40 50 Deletion (DEQUEUE) Insertion (ENQUEUE) A[0] A[1] A[2] A[3] A[4] 02-02-2023
  • 40. Department of Computer Science and Engineering 40 TREE • Tree is a hierarchical data structure which stores the information naturally in the form of hierarchy style • Collection of nodes (starting at a root node) together with a list of references to nodes (the "children") 02-02-2023
  • 41. Department of Computer Science and Engineering 41 WHY? EmployeesTable 02-02-2023
  • 42. Department of Computer Science and Engineering 42 WHY? EmployeesTable 02-02-2023
  • 43. Department of Computer Science and Engineering 43 TERMINOLOGIES 02-02-2023
  • 44. Department of Computer Science and Engineering 44 EXAMPLE 02-02-2023
  • 45. Department of Computer Science and Engineering GRAPH 02-02-2023 45 and Project Management (SEPM) • A graph G = (V,E) consists of a finite set of vertices, V,and a finite set of edges E.
  • 46. Department of Computer Science and Engineering 46 REPRESENTATION - EXAMPLE 02-02-2023
  • 47. Department of Computer Science and Engineering IMPLEMENTATION OF LIST ADT 02-02-2023 47 and Project Management (SEPM) 1. Array Implementation 2. Linked List Implementation 3. Cursor Implementation.
  • 48. Department of Computer Science and Engineering ABSTRACT DATA TYPE 02-02-2023 48 and Project Management (SEPM) • Stores data and allow various operations on the data to access and change it. • A mathematical model, together with various operations defined on the model • An ADT is a collection of data and associated operations for manipulating that data
  • 49. Department of Computer Science and Engineering ARRAY IMPLEMENTATION OF LIST ADT 02-02-2023 49 and Project Management (SEPM) Array is a collection of specific number of data stored in a consecutive memory locations. * Insertion and Deletion operation are expensive as it requires more data movement * Find and Printlist operations takes constant time. * Even if the array is dynamically allocated, an estimate of the maximum size of the list is required which considerably wastes the memory space.
  • 50. Department of Computer Science and Engineering ARRAY ADT-INSERTION 02-02-2023 50 and Project Management (SEPM) Insert() declare array A read n for (i=0;i<n;i++) read A[i] set i=0,j=n get position k n=n+1 while( j >= k) A[j+1] = A[j] j = j - 1 A[k] =item print array A
  • 51. Department of Computer Science and Engineering ARRAY ADT-INSERTION 02-02-2023 51 and Project Management (SEPM) main() { int A[] = {1,3,5,7}; int item = 8, k = 3, n = 5; int i = 0, j = n; printf("The original array elements are :n"); for(i = 0; i<n; i++) { printf("A[%d] = %d n", i, A[i]); } n = n + 1; while( j >= k) { A[j+1] = A[j]; j = j - 1; }
  • 52. Department of Computer Science and Engineering ARRAY ADT-INSERTION 02-02-2023 52 and Project Management (SEPM) A[k] = item; printf("The array elements after insertion :n"); for(i = 0; i<n; i++) { printf("A[%d] = %d n", i, A[i]); } } Before Insertion After Insertion 1 3 5 7 1 3 5 7 8
  • 53. Department of Computer Science and Engineering ARRAY ADT-DELETION 02-02-2023 53 and Project Management (SEPM) delete() declare array A read n for (i=0;i<n;i++) read A[i] get position k j=k while( j < n) A[j-1] = A[j] j = j + 1 n=n-1 print array A
  • 54. Department of Computer Science and Engineering ARRAY ADT-DELETION 02-02-2023 54 and Project Management (SEPM) main() { int A[] = {1,3,5,7,8}; int k = 3, n = 5; int i, j; printf("The original array elements are :n"); for(i = 0; i<n; i++) { printf("A[%d] = %d n", i, A[i]); } j = k; while( j < n) { A[j-1] = A[j]; j = j + 1; }
  • 55. Department of Computer Science and Engineering ARRAY ADT-DELETION 02-02-2023 55 and Project Management (SEPM) n = n -1; printf("The array elements after deletion :n"); for(i = 0; i<n; i++) { printf("A[%d] = %d n", i, A[i]); } } Before Deletion After Deletion 1 3 7 8 1 3 5 7 8
  • 56. Department of Computer Science and Engineering ARRAY ADT- SEARCH 02-02-2023 56 and Project Management (SEPM) search() declare array A read n for (i=0;i<n;i++) read A[i] read k(element to be searched) set f=0 for(i=0;i<n;i++) if(A[i]==k) f=1 print i break if(f==0) print “Element not found”
  • 57. Department of Computer Science and Engineering ARRAY ADT- SEARCH 02-02-2023 57 and Project Management (SEPM) main() { int list[20],size,i,sElement; printf("Enter size of the list: "); scanf("%d",&size); printf("Enter any %d integer values: ",size); for(i = 0; i < size; i++) scanf("%d",&list[i]); printf("Enter the element to be Search: "); scanf("%d",&sElement);
  • 58. Department of Computer Science and Engineering ARRAY ADT- SEARCH 02-02-2023 58 and Project Management (SEPM) for(i = 0; i < size; i++) { if(sElement == list[i]) { printf("Element is found at %d index", i); break; } } if(i == size) printf("Given element is not found in the list!!!"); }
  • 59. Department of Computer Science and Engineering ARRAY ADT- SEARCH 02-02-2023 59 and Project Management (SEPM)
  • 60. Department of Computer Science and Engineering 60 LINKED LIST • A linked list is a linear data structure. • Nodes make up linked lists. • Nodes are structures made up of data and a pointer to another node. • Pointer is called next. 02-02-2023
  • 61. Department of Computer Science and Engineering 61 DRAWBACKS OF ARRAY •Fixed size: Resizing is expensive •Insertions and Deletions are inefficient: Elements are usually shifted •No memory waste if the array is full or almost full; otherwise may result in much memory waste. 02-02-2023
  • 62. Department of Computer Science and Engineering 62 WHY LINKED LIST? •Dynamic size •Insertions and Deletions are efficient: No Shifting •Linked List can grow and shrink during run time. •Since memory is allocated dynamically there is no waste of memory. •Faster Access time,can be expanded in constant time without memory overhead 02-02-2023
  • 63. Department of Computer Science and Engineering 63 REPRESENTATION OF LINKED LIST •Static or sequential or array representation. •The linked list will be maintained or represented by two parallel arrays of same sizes. •Dynamic or pointers or linked representation. •The size of the linked list may increase or decrease according to the requirement 02-02-2023
  • 64. Department of Computer Science and Engineering 64 TYPES • Singly Linked List • Doubly Linked List • Circular Linked List  Singly Circular Linked List  Doubly Circular Linked List 02-02-2023
  • 65. Department of Computer Science and Engineering 65 SINGLY LINKED LIST • Two field  Data  Next pointer 02-02-2023
  • 66. Department of Computer Science and Engineering 66 SINGLY LINKED LIST • Link part of the last node contains NULL value which signifies the end of the node 02-02-2023
  • 67. Department of Computer Science and Engineering 67 DECLARATION Struct node ; typedef struct Node *List ; typedef struct Node *Position ; int IsLast (List L) ; int IsEmpty (List L) ; position Find(int X, List L) ; void Delete(int X, List L) ; position FindPrevious(int X, List L) ; position FindNext(int X, List L) ; void Insert(int X, List L, Position P) ; void DeleteList(List L) ; 02-02-2023
  • 68. Department of Computer Science and Engineering 68 STORING DATA IN A NODE Node declaration: struct node { int data; node *next; } Storing data: node *nptr; nptr= new(node); nptr->data= 50; nptr->next = NULL; nptr 50 02-02-2023
  • 69. Department of Computer Science and Engineering 69 Insertion of node into a linked list requires a free node in which the information can be inserted and then the node can be inserted into the linked list. At beginning. At the end of list. At the specified position. INSERTING A NEW NODE 02-02-2023
  • 70. Department of Computer Science and Engineering 70 INSERTION AT BEGINNING void insert(item) { struct node *newNode; newNode = malloc(sizeof(struct node)); newNode->data = item; newNode->next = head; head = newNode; } 02-02-2023
  • 71. Department of Computer Science and Engineering 71 INSERTION AT BEGINNING 48 17 142 HEAD // HEAD 93 Step 1 Step 2 Step 3 02-02-2023
  • 72. Department of Computer Science and Engineering 72 INSERTION AT BEGINNING 02-02-2023
  • 73. Department of Computer Science and Engineering 73 INSERTION AT END void insert(item) { struct node *newNode; newNode = malloc(sizeof(struct node)); newNode->data = item; newNode->next = NULL; struct node *temp = head; while(temp->next != NULL) { temp = temp->next; } temp->next = newNode; } 02-02-2023
  • 74. Department of Computer Science and Engineering 74 INSERTION AT END 48 17 142 HEAD // 93 Step 1 Step 2 Step 3 48 17 142 HEAD // 02-02-2023
  • 75. Department of Computer Science and Engineering 75 INSERTION AT END 02-02-2023
  • 76. Department of Computer Science and Engineering 76 INSERTION AT END void Insert (int X, List L, Position P) { position Newnode; Newnode = malloc (size of (Struct Node)); If (Newnode! = NULL) { Newnode ->Element = X; Newnode ->Next = P-> Next; P-> Next = Newnode; } } 02-02-2023
  • 77. Department of Computer Science and Engineering 77 INSERTION AT SPECIFIED POSITION 48 17 142 HEAD // Step 1 Step 2 48 17 142 HEAD // 02-02-2023
  • 78. Department of Computer Science and Engineering 78 INSERTION AT SPECIFIED POSITION 02-02-2023
  • 79. Department of Computer Science and Engineering 79 INSERTION AT SPECIFIED POSITION 02-02-2023
  • 80. Department of Computer Science and Engineering 80 DELETION void Delete(int X, List L) { position P, Temp; P = Findprevious (X,L); If (!IsLast(P,L)) { Temp = P→Next; P →Next = Temp→Next; Free (Temp); } } 02-02-2023
  • 81. Department of Computer Science and Engineering 81 Step 1 48 17 142 HEAD // Step 2 48 17 142 HEAD DELETION 02-02-2023
  • 82. Department of Computer Science and Engineering 82 DELETION 02-02-2023
  • 83. Department of Computer Science and Engineering 83 DELETION 02-02-2023
  • 84. Department of Computer Science and Engineering 84 void DeleteList (List L) { position P, Temp; P = L →Next; L→Next = NULL; while (P! = NULL) { Temp = P→Next free (P); P = Temp; } } DELETE THE LIST 02-02-2023
  • 85. Department of Computer Science and Engineering 85 position Find (int X, List L) { position P; P = L-> Next; while (P! = NULL && P -> Element ! = X) P = P->Next; return P; } FIND 02-02-2023
  • 86. Department of Computer Science and Engineering 86 position FindPrevious (int X, List L) { position P; P = L; while (P -> Next ! = Null && P ->Next -> Element ! = X) P = P ->Next; return P; } FIND PREVIOUS 02-02-2023
  • 87. Department of Computer Science and Engineering 87 position FindNext (int X, List L) { P = L ->Next; while (P -> Next! = NULL && P-> Element ! = X) P = P→Next; return P→Next; } FIND NEXT 02-02-2023
  • 88. Department of Computer Science and Engineering 88 int IsLast (position P, List L) { if (P->Next = = NULL) return; } IsLast() 02-02-2023
  • 89. Department of Computer Science and Engineering 89 int IsEmpty (List L) { if (L -> Next = = NULL) return (1); } IsEmpty() L 02-02-2023
  • 90. Department of Computer Science and Engineering 90 1) Insertions and Deletions can be done easily. 2) It space is not wasted as we can get space according to our requirements. 3) Its size is not fixed. 4) Elements may or may not be stored in consecutive memory available, even then we can store the data in computer. ADVANTAGES 02-02-2023
  • 91. Department of Computer Science and Engineering 91 1) It requires more space as pointers are also stored with information. 2) Different amount of time is required to access each element. 3) If we have to go to a particular element then we have to go through all those elements that come before that element. 4) Can not traverse it from last & only from the beginning. DISADVANTAGES 02-02-2023
  • 92. Department of Computer Science and Engineering 92 DOUBLY LINKED LIST  Node Contains Info : The user’s data. Prev/Blink: The address of previous node Next/Flink: The address of next node Data Prev Next 02-02-2023
  • 93. Department of Computer Science and Engineering 93 ADVANTAGES OVER SLL • A DLL can be traversed in both forward and backward direction. • The delete operation in DLL is more efficient • Easy to insert a new node before a given node. • In singly linked list, to delete a node, pointer to the previous node is needed. • In DLL, we can get the previous node using previous pointer. 02-02-2023
  • 94. Department of Computer Science and Engineering 94 struct Node { int data; struct Node* next; // Pointer to next node in DLL struct Node* prev; // Pointer to previous node in DLL }; CREATING A NEW NODE •Create a head node and assign some data to its data field. •Make sure that the previous and next address field of the head node must point to NULL. 02-02-2023
  • 95. Department of Computer Science and Engineering 95 void Insert (int X, list L, position P) { Struct Node * Newnode; Newnode = malloc (size of (Struct Node)); If (Newnode ! = NULL) { Newnode →Element = X; Newnode →Flink = P Flink; P →Flink →Blink = Newnode; P →Flink = Newnode ; Newnode →Blink = P; } } INSERTION 02-02-2023
  • 96. Department of Computer Science and Engineering 96 INSERTION 02-02-2023
  • 97. Department of Computer Science and Engineering 97 DELETION void Delete (int X, List L) { position P; P = Find (X, L); If ( IsLast (P, L)) { Temp = P; P →Blink →Flink = NULL; free (Temp); } 02-02-2023
  • 98. Department of Computer Science and Engineering 98 DELETION else { Temp = P; P →Blink→ Flink = P→Flink; P →Flink →Blink = P→Blink; free (Temp); } } 02-02-2023
  • 99. Department of Computer Science and Engineering 99 DELETION AT SPECIFIED POSITION 02-02-2023
  • 100. Department of Computer Science and Engineering 100 PROS: 1) Deletion operation is easier. 2) Finding the predecessor & Successor of a node is easier. CONS: Every node of DLL Require extra space for an previous pointer. PROS & CONS 02-02-2023
  • 101. Department of Computer Science and Engineering 101 1) It is used by browsers to implement backward and forward navigation of visited web pages i.e. back and forward button APPLICATIONS 02-02-2023
  • 102. Department of Computer Science and Engineering 102 CIRCULAR LINKED LIST • Last node points to the first • Both singly and doubly linked list can be made into a circular linked list. • Circular linked list can be used to help traverse the same list again and again if needed. 02-02-2023
  • 103. Department of Computer Science and Engineering 103 WHY? • To represent arrays that are naturally circular, e.g. the corners of a polygon, a pool of buffers. • With a circular list, a pointer to the last node gives easy access also to the first node, by following one link. • Some problems are circular and a circular data structure would be more natural when used to represent it. 02-02-2023
  • 104. Department of Computer Science and Engineering 104 REPRESENTATION 02-02-2023
  • 105. Department of Computer Science and Engineering 105 TYPES 1. Singly: The last node points to the first node and there is only link between the nodes of linked list. 2. Doubly: The last node points to the first node and there are two links between the nodes of linked list. 02-02-2023
  • 106. Department of Computer Science and Engineering 106 Node declaration: struct node { int data; node *next; }; Declare variable (pointer type) that point to the node: node *nptr; Allocate memory for new node: nptr = new (node); Enter value: nptr→data = item; nptr→next = NULL; CREATING A NEW NODE- SINGLY 02-02-2023
  • 107. Department of Computer Science and Engineering 107 BASIC OPERATIONS 1) Insert element at beginning in list. 2) Insert element at end in list. 3) Insert element at any place in list. 4) Delete element from the beginning of list. 5) Delete element from the end of list. 6) Delete element from any place from list. 7) Display 02-02-2023
  • 108. Department of Computer Science and Engineering 108 Insertion of node into a linked list requires a free node in which the information can be inserted and then the node can be inserted into the linked list. At beginning. At the end of list. At the specified position. INSERTING A NEW NODE 02-02-2023
  • 109. Department of Computer Science and Engineering 109 INSERTION AT BEGINNING ALGORITHM • Declare struct node *t. • Set t:=start. • Create a new node n by malloc function and enter the information in info part. • Check if start=NULL set start=n set start->next=start. else • Set n->next=start. • Repeat step(a) while(t->next!=start) ▫ (a) set t:=t->next. • Set t->next=n. • Set start=n. [end if] 02-02-2023
  • 110. Department of Computer Science and Engineering 110 INSERTION AT BEGINNING CODE Void addfront() { struct node *t=start; struct node *n=(struct node*)malloc(sizeof(struct node)); printf(“nenter the information”); scanf(“%d”,&n->info); if(start==NULL) { start=n; start->next=start; } 02-02-2023
  • 111. Department of Computer Science and Engineering 111 INSERTION AT BEGINNING CODE else { n->next=start; while(t->next!=start) t=t->next; t->next=n; start=n; } 02-02-2023
  • 112. Department of Computer Science and Engineering 112 INSERTION AT BEGINNING 02-02-2023
  • 113. Department of Computer Science and Engineering 113 INSERTION AT END ALGORITHM • Declare struct node *t. • Set t:=start. • Create a new node n by malloc function and enter the information in info part. • Check if start=NULL then, set start:=n. set start->next:=start. Otherwise • Set n->next:=start. • Repeat step(a) while(t!=NULL) ▫ (a) set t:=t->next. • [end of loop] • Set t->next=n. [end if] 02-02-2023
  • 114. Department of Computer Science and Engineering 114 INSERTION AT END 02-02-2023
  • 115. Department of Computer Science and Engineering 115 INSERTION AT END Void addlast() { struct node *t=start; struct node *n=(struct node*)malloc(sizeof(struct node)); printf(“nenter the information”); scanf(“%d”,&n->info); if(start==NULL) { start=n; start->next=start; } else { n->next=start; while(t!=NULL) t=t->next; t->next=n; } 02-02-2023
  • 116. Department of Computer Science and Engineering 116 INSERTION AT SPECIFIED POSITION let *head -pointer to first node *p -pointer to the nodeafter whichwewant to insert anewnode. 1. Createanewnodeusingmallocfunction NewNode=(NodeType*)malloc(sizeof(NodeType)); 2. Assigndatato theinfofieldof newnode NewNode->info=newItem; 3. Setnextof newnodeto nextof p NewNode->next=p->next; 4. Setnextof p toNewNode p->next =NewNode 5. End 02-02-2023
  • 117. Department of Computer Science and Engineering 117 INSERTION AT SPECIFIED POSITION void insertAfter(struct Node* prev_node, int new_data) { if (prev_node == NULL) { printf("the given previous node cannot be NULL"); return; } struct Node* new_node =(struct Node*) malloc(sizeof(struct Node)); new_node->data = new_data; new_node->next = prev_node->next; prev_node->next = new_node; } 02-02-2023
  • 118. Department of Computer Science and Engineering 118 INSERTION AT SPECIFIED POSITION 02-02-2023
  • 119. Department of Computer Science and Engineering 119 DELETION OF A NODE If the node be deleted, that element should be search all over the list still the node find. Then it should be deleted. Deletion at the beginning position of the linked list. Deletion at the ending position of linked list. Deletion at a specified position in linked list. 02-02-2023
  • 120. Department of Computer Science and Engineering 120 DELETION AT BEGINNING • Check if (start=NULL) then, print “empty list” • Check if (start->next=start) then, declare free (t) set start:=NULL otherwise • Repeat step(a) while(t->next!=start) ▫ (a) set t:=t->next • [end of loop] • set start:=start->next • Declare free(t-next). • Set t->next:=start. • [end of if] 02-02-2023
  • 121. Department of Computer Science and Engineering 121 DELETION AT BEGINNING 02-02-2023
  • 122. Department of Computer Science and Engineering 122 DELETION AT BEGINNING Void delfront() { struct node *t=start; if (start==NULL) printf (“nempty list”); else if (start->next==start) { free (t); start=NULL; } else{ while(t->next!=start) t=t->next; start=start->next; free(t->next); t->next=start; }} 02-02-2023
  • 123. Department of Computer Science and Engineering 123 DELETION AT END • Check if (start=NULL) then, print “empty list” • Check if (start->next=start) then, declare free (t) set start:=NULL otherwise • Repeat step(a) while(t->next->next!=start) ▫ (a) set t:=t->next • [end of loop] • Declare free(t->next). • Set t->next:=start. • [end if] 02-02-2023
  • 124. Department of Computer Science and Engineering 124 DELETION AT END 02-02-2023
  • 125. Department of Computer Science and Engineering 125 Void dellast() { struct node *t=start; if (start==NULL) printf(“nempty list”); else if (start->next==start) { free (t); start=NULL ; } else { while(t->next->next!=start) t=t->next; free(t->next); t->next=start; } } DELETION AT END 02-02-2023
  • 126. Department of Computer Science and Engineering 126 DELETION AT SPECIFIED POSITION 02-02-2023
  • 127. Department of Computer Science and Engineering 127 DELETION AT SPECIFIED POSITION void deleteNode(struct Node **head, int key) { struct Node* temp = *head *prev; if (temp != NULL && temp->data == key) { *head_ref = temp->next; free(temp); return; } while (temp != NULL && temp->data != key) { prev = temp; temp = temp->next; } if (temp == NULL) return; prev->next = temp->next; free(temp); } 02-02-2023
  • 128. Department of Computer Science and Engineering 128 DELETION AT SPECIFIED POSITION 02-02-2023
  • 129. Department of Computer Science and Engineering 129 Step 1: IF HEAD == NULL WRITE "UNDERFLOW" GOTO STEP 8 [END OF IF] Step 2: Set PTR = HEAD Step 3: Set i = 0 Step 4: Repeat step 5 to 7 while PTR != NULL Step 5: IF PTR → data = item return i [END OF IF] Step 6: i = i + 1 Step 7: PTR = PTR → next Step 8: Exit FINDING A N ELEMENT 02-02-2023
  • 130. Department of Computer Science and Engineering 130 struct Node { int data; struct Node* next; // Pointer to next node in DLL struct Node* prev; // Pointer to previous node in DLL }; CREATING A NEW NODE – DOUB LY •Create a head node and assign some data to its data field. •Make sure that the previous and next address field of the head node must point to NULL. •Make the head node as last node. 02-02-2023
  • 131. Department of Computer Science and Engineering 131 INSERTION let *head -pointer to first node *p -pointer to the nodeafter whichwewant to insert anewnode. 1. Createanewnodeusingmallocfunction 2. Assigndatato theinfofieldof newnode NewNode->info=newItem; 3. Setnextof newnodeto nextof p NewNode->next=p->next; 4. Setnextof p toNewNode p->next =NewNode 5. End 02-02-2023
  • 132. Department of Computer Science and Engineering 132 INSERTION 02-02-2023
  • 133. Department of Computer Science and Engineering 133 DELETION 02-02-2023
  • 134. Department of Computer Science and Engineering 134 DELETION 02-02-2023
  • 135. Department of Computer Science and Engineering APPLICATIONS OF LIST 02-02-2023 135 and Project Management (SEPM) 1. Polynomial ADT 2. Radix Sort 3. Multilist
  • 136. Department of Computer Science and Engineering Stack ADT 02-02-2023 136 and Project Management (SEPM) • Principle-LIFO •Top pointer •Operations •Push() •Pop() •Conditions •Underflow-Empty stack •Overflow – Full stack
  • 137. Department of Computer Science and Engineering 137 Stack ADT Example: 02-02-2023
  • 138. Department of Computer Science and Engineering Why it is Used? 02-02-2023 138 and Project Management (SEPM) •Used for  Reversing elements  MS paint and Editing apps.  Expression evaluation  Backtracking algorithms To check the string is well formed parenthesis.
  • 139. Department of Computer Science and Engineering Stack Operation 02-02-2023 139 and Project Management (SEPM) • Push-Insertion To push x: top++; s[top]=x; • Pop –Deletion To pop(x) s[top]=x top--; • Peek() – return the top element • isEmpty()-to check whether stack is empty or not • isFull()- to check whether stack is full or not
  • 140. Department of Computer Science and Engineering Stack Implementation 02-02-2023 140 and Project Management (SEPM) Two types: Array Implementation Linked List Implementation
  • 141. Department of Computer Science and Engineering Array Implementation 02-02-2023 141 and Project Management (SEPM) Array Implementation of Stack ADT: •peek( ) •push( ) •pop( ) •isempty( ) •isfull( ) int peek() { return stack[top]; }
  • 142. Department of Computer Science and Engineering Array Implementation 02-02-2023 142 and Project Management (SEPM) To check whether stack is empty: bool isfull() { if(top == MAXSIZE-1) return true; else return false; } To check whether stack is empty: bool isempty() { if(top == -1) return true; else return false; }
  • 143. Department of Computer Science and Engineering Array Implementation 02-02-2023 143 and Project Management (SEPM) push(): void push(int data) { if(!isfull()) { top = top + 1; stack[top] = data; } else { printf(“Stack is full.n"); } }
  • 144. Department of Computer Science and Engineering Array Implementation 02-02-2023 144 and Project Management (SEPM) Push(50)
  • 145. Department of Computer Science and Engineering Array Implementation 02-02-2023 145 and Project Management (SEPM) pop(): int pop(int data) { if(!isempty()) { data = stack[top]; top = top - 1; return data; } else { printf("Stack is empty.n"); } }
  • 146. Department of Computer Science and Engineering Array Implementation 02-02-2023 146 and Project Management (SEPM) Pop()
  • 147. Department of Computer Science and Engineering Linked List Implementation 02-02-2023 147 and Project Management (SEPM) Node Creation: Step 1 - Define a 'Node' structure with two members data and next. Step 2 - Define a Node pointer 'top' and set it to NULL. DATA NEXT
  • 148. Department of Computer Science and Engineering CREATE AN EMPTY STACK 02-02-2023 148 and Project Management (SEPM) Stack CreateStack ( ) { Stack S; S = malloc (Sizeof (Struct Node)); if (S = = NULL) Error (" Outof Space"); MakeEmpty (s); return S; }
  • 149. Department of Computer Science and Engineering MAKE EMPTY 02-02-2023 149 and Project Management (SEPM) void MakeEmpty (Stack S) { if (S = = NULL) Error (" Create Stack First"); else while (! IsEmpty (s)) pop (s); }
  • 150. Department of Computer Science and Engineering LINKED LIST IMPLEMENTATION - PUSH 02-02-2023 150 and Project Management (SEPM) void push (int X, Stack S) { Struct Node * Tempcell; Tempcell = malloc (sizeof (Struct Node)); If (Tempcell = = NULL) Error ("Out of Space"); else { Tempcell → Element = X; Tempcell → Next = S → Next; S→Next = Tempcell; } }
  • 151. Department of Computer Science and Engineering LINKED LIST IMPLEMENTATION - PUSH 02-02-2023 151 and Project Management (SEPM)
  • 152. Department of Computer Science and Engineering LINKED LIST IMPLEMENTATION - POP 02-02-2023 152 and Project Management (SEPM) void pop (Stack S) { Struct Node *Tempcell; If (IsEmpty (S)) Error ("Empty Stack"); else { Tempcell = S→Next; S→Next = S→Next→Next; Free (Tempcell); } }
  • 153. Department of Computer Science and Engineering LINKED LIST IMPLEMENTATION - POP 02-02-2023 153 and Project Management (SEPM)
  • 154. Department of Computer Science and Engineering RETURN TOP ELEMENT 02-02-2023 154 and Project Management (SEPM) int Top (Stack S) { If (! IsEmpty (s)) return S→Next→Element; Error ("Empty Stack"); return 0; }
  • 155. Department of Computer Science and Engineering Applications 02-02-2023 155 and Project Management (SEPM)  Function call  Evaluation Arithmetic Expression •Infix to postfix •Evaluating postfix  Balancing Parenthesis Reversing a word 8 Queen problem Towers of Hanoi
  • 156. Department of Computer Science and Engineering 156 EVALUATING ARITHMETIC EXPRESSIONS INFIX notation: •Operator presents between operands: A+B POSTFIX notation: •Operator follows its two operands: AB+ PREFIX notation: •Operator precedes its two operands: +AB Operator Precedence $, ^ *,/ +,- 02-02-2023
  • 157. Department of Computer Science and Engineering 157 INFIX TO POSTFIX -ALGORITHM 1. Scan the infix expression 2. If the scanned character is an operand, output it. 3. Else, 3.1 If (precedence of scanned operator) >(precedence of stack operator) - push it. 3.2 Else, Pop all the operators from the stack which are greater than or equal to in precedence than that of the scanned operator. 02-02-2023
  • 158. Department of Computer Science and Engineering 158 4. If the scanned character is an ‘(‘, push it to the stack. 5. If the scanned character is an ‘)’, pop the stack and and output it until a ‘(‘ is encountered, and discard both the parenthesis. 6. Repeat steps 2-6 until infix expression is scanned. 7. Print the output 8. Pop and output from the stack until it is not empty. INFIX TO POSTFIX –ALGORITHM 02-02-2023
  • 159. Department of Computer Science and Engineering 159 CONVERSION OF INFIX INTO POSTFIX (2+(4-1)*3) into 241-3*+ CURRENT SYMBOL ACTION PERFORMED STACK STATUS POSTFIX EXPRESSIO N ( PUSH ( ( 2 2 2 + PUSH + (+ 2 ( PUSH ( (+( 24 4 24 - PUSH - (+(- 241 1 POP 241- ) (+ 241- * PUSH * (+* 241- 3 241-3 POP * 241-3* POP + 241-3*+ ) 02-02-2023
  • 160. Department of Computer Science and Engineering 160 1) Scan the expression from left to right. 2) If an operand is seen, push it onto stack. 3) If an operator is seen, pop of top two elements (operands) [ x & y ] from stack and perform z = operand y Push z onto stack. 4) Repeat steps (2) & (3) till scanning is over. EVALUATING POSTFIX EXPRESSION 02-02-2023
  • 161. Department of Computer Science and Engineering EVALUATING POSTFIX EXPRESSION 02-02-2023 161
  • 162. Department of Computer Science and Engineering 162 BALANCING PARENTHESIS • Declare a character stack S. • Now traverse the expression string exp.  If the current character is a starting bracket (‘(‘ or ‘{‘ or ‘[‘) then push it to stack.  If the current character is a closing bracket (‘)’ or ‘}’ or ‘]’) then pop from stack and if the popped character is the matching starting bracket then fine else parenthesis are not balanced. • After complete traversal, if there is some starting bracket left in stack then “not balanced” Balancing Parenthesis 02-02-2023
  • 163. Department of Computer Science and Engineering 163 BALANCING PARENTHESIS VALID INPUTS INVALID INPUTS { } { ( } ( { [ ] } ) ( [ ( ( ) ] ) { [ ] ( ) } { } [ ] ) [ { ( { } [ ] ( { [ { ) } ( ] } ] })}] 02-02-2023
  • 164. Department of Computer Science and Engineering TOWERS OF HANOI 02-02-2023 164 and Project Management (SEPM) void hanoi (int n, char s, char d, char i) { if (n = = 1) { print (s, d); return; } else { hanoi (n - 1, s, i, d); print (s, d) ; hanoi (n-1, i, d, s); return; } }
  • 165. Department of Computer Science and Engineering TOWERS OF HANOI 02-02-2023 165 and Project Management (SEPM)
  • 166. Department of Computer Science and Engineering FUNCTION CALLS 02-02-2023 166 and Project Management (SEPM) When a call is made to a new function all the variables local to the calling routine need to be saved, otherwise the new function will overwrite the calling routine variables. RECURSIVE FUNCTION TO FIND FACTORIAL : - int fact (int n) { int s; if (n = = 1) return (1); else s = n * fact (n - 1); return (s); }
  • 167. Department of Computer Science and Engineering Queue ADT 02-02-2023 167 and Project Management (SEPM) • FIFO •Front is a variable which refers to first position in queue •Rear is a variable which refers to last position in queue. •Element is component which has data. •MaxQueue is variable that describes maximum number of elements in a queue
  • 168. Department of Computer Science and Engineering Queue ADT 02-02-2023 168 and Project Management (SEPM) •Two pointers Front Rear •Basic Operations enqueue() – Rear end dequeue() – Front end •Conditions Underflow-Empty Queue Overflow - Full Queue
  • 169. Department of Computer Science and Engineering 169 QUEUE ADT 10 20 30 40 50 Deletion (DEQUEUE) Insertion (ENQUEUE) A[0] A[1] A[2] A[3] A[4] 02-02-2023
  • 170. Department of Computer Science and Engineering 170 Front Rear ENQUEUE • Placing an item in a queue is called “Insertion or Enqueue”, which is done at the end of the queue called “Rear”. 02-02-2023
  • 171. Department of Computer Science and Engineering 171 Front Rear DEQUEUE • Removing an item from a queue is called “deletion or dequeue”, which is done at the other end of the queue called “front”. 02-02-2023
  • 172. Department of Computer Science and Engineering 172 TYPES OF QUEUE • Linear Queue • Circular Queue • Priority Queue • Deque – Double Ended Queue  Input Restricted Deque  Output Restricted Deque 02-02-2023
  • 173. Department of Computer Science and Engineering 173 •A normal queue •insertion - Rear •deletion –Front LINEAR QUEUE 02-02-2023
  • 174. Department of Computer Science and Engineering QUEUE IMPLEMENTATION 02-02-2023 174 and Project Management (SEPM) Two types: Array Implementation Linked List Implementation arr 0 1 7 8 9 2 3 4 5 6 A B C D E F G front back Array Implementation
  • 175. Department of Computer Science and Engineering 175 void enqueue(item) { if (rear = = maxsize-1 ) print (“queue overflow”); else rear = rear + 1; Queue [rear] = item; } ENQUEUE 02-02-2023
  • 176. Department of Computer Science and Engineering 176 ENQUEUE 02-02-2023
  • 177. Department of Computer Science and Engineering 177 void dequeue() { if (front= = -1) print “queue empty”; else if(front == rear) front=rear=-1; else { front = front + 1 ; item = queue [front]; return item; }} DEQUEUE 02-02-2023
  • 178. Department of Computer Science and Engineering 178 DEQUEUE 02-02-2023
  • 179. Department of Computer Science and Engineering 179 LIST IMPLEMENTATION QUEUE using namespace std; struct QNode { int data; QNode* next; QNode(int d) { data = d; next = NULL; } }; struct Queue { QNode *front, *rear; Queue() { front = rear = NULL; } 02-02-2023
  • 180. Department of Computer Science and Engineering 180 LIST IMPLEMENTATION QUEUE void enQueue(int x) { QNode* temp = new QNode(x); if (rear == NULL) { front = rear = temp; return; } rear->next = temp; rear = temp; } 02-02-2023
  • 181. Department of Computer Science and Engineering 181 LIST IMPLEMENTATION QUEUE rear After inserting 4 02-02-2023
  • 182. Department of Computer Science and Engineering 182 LIST IMPLEMENTATION QUEUE void deQueue() { if (front == NULL) return; QNode* temp = front; front = front->next; if (front == NULL) rear = NULL; delete (temp); } }; 02-02-2023
  • 183. Department of Computer Science and Engineering 183 LIST IMPLEMENTATION QUEUE front 02-02-2023
  • 184. Department of Computer Science and Engineering 184 •The last element points to the first element. •Ring Buffer Use: consumes less memory than linear queue CIRCULAR QUEUE 02-02-2023
  • 185. Department of Computer Science and Engineering 185 CIRCULAR QUEUE 02-02-2023
  • 186. Department of Computer Science and Engineering 186 ENQUEUE -ALGORITHM Insert-Circular-Q(CQueue, Rear, Front, N, Item) Initailly Rear = 0 and Front = 0. 1. If Front = 0 and Rear = 0 then Set Front := 1 and go to step 4. 2. If Front =1 and Rear = N or Front = Rear + 1 then Print: “Circular Queue Overflow” and Return. 3. If Rear = N then Set Rear := 1 and go to step 5. 4. Set Rear := Rear + 1 5. Set CQueue [Rear] := Item. 6. Return 02-02-2023
  • 187. Department of Computer Science and Engineering 187 void CEnqueue (int X) { if (Front = = (rear + 1) % Maxsize) print ("Queue is overflow"); else { if (front = = -1) front = rear = 0; else rear = (rear + 1)% Maxsize; CQueue [rear] = X; } } ENQUEUE 02-02-2023
  • 188. Department of Computer Science and Engineering 188 DEQUEUE - ALGORITHM Delete-Circular-Q(CQueue, Front, Rear, Item) Initially, Front = 1. 1. If Front = 0 then Print: “Circular Queue Underflow” and Return. 2. Set Item := CQueue [Front] 3. If Front = N then Set Front = 1 and Return. 4. If Front = Rear then Set Front = 0 and Rear = 0 and Return. 5. Set Front := Front + 1 6. Return. 02-02-2023
  • 189. Department of Computer Science and Engineering 189 int CDequeue ( ) { if (front = = -1) print ("Queue is underflow"); else { X = CQueue [Front]; if (Front = = Rear) Front = Rear = -1; else Front = (Front + 1)% maxsize; } return (X); } DEQUEUE 02-02-2023
  • 190. Department of Computer Science and Engineering 190 EXAMPLE 02-02-2023
  • 191. Department of Computer Science and Engineering 191 EXAMPLE 02-02-2023
  • 192. Department of Computer Science and Engineering APPLICATIONS OF QUEUE 02-02-2023 192 and Project Management (SEPM) • Batch processing in an operating system • To implement Priority Queues. • Priority Queues can be used to sort the elements using Heap Sort. • Simulation. • Mathematics user Queueing theory. • Computer networks where the server takes the jobs of the client as per the queue strategy.
  • 193. Department of Computer Science and Engineering 193 RESEARCH APPLICATION • Image processing -Watershed transformation implementation by hierarchical queues • The HQ is initialized by storing tokens corresponding to the pixels labelled in image gin their respective queues. • In the case of the watershed transform (WTS), this priority level of each queue corresponds to the grey level of the token (pixel). • pixels of lower grey level have the highest priority (queues are numbered according to the grey levels, queue 0 has the highest priority). 02-02-2023
  • 194. Department of Computer Science and Engineering 194 RESEARCH APPLICATION 02-02-2023
  • 195. Department of Computer Science and Engineering 195 QUEUEING THEORY 02-02-2023
  • 196. Thank You Department of Computer Science and Engineering