This document provides details about a course on data structures taught at Vel Tech Rangarajan Dr. Sagunthala R&D Institute of Science and Technology. It includes information such as the course code, category, unit number, topic, and faculty name. It describes the course objectives as providing an introduction to basic concepts and techniques of linear and nonlinear data structures and analyzing various algorithms. It lists prerequisite and related courses, as well as intended course outcomes. It also includes a correlation of the course outcomes with program outcomes and lists recommended textbooks and online resources.
FellowBuddy.com is an innovative platform that brings students together to share notes, exam papers, study guides, project reports and presentation for upcoming exams.
We connect Students who have an understanding of course material with Students who need help.
Benefits:-
# Students can catch up on notes they missed because of an absence.
# Underachievers can find peer developed notes that break down lecture and study material in a way that they can understand
# Students can earn better grades, save time and study effectively
Our Vision & Mission – Simplifying Students Life
Our Belief – “The great breakthrough in your life comes when you realize it, that you can learn anything you need to learn; to accomplish any goal that you have set for yourself. This means there are no limits on what you can be, have or do.”
Like Us - https://www.facebook.com/FellowBuddycom
Spatial decision support and analytics on a campus scale: bringing GIS, CAD, ...Safe Software
University and College Campuses are complex environments. The campus comprises many physical sub-systems, such as buildings, outdoor spaces, utilities, transportation, which are maintained by several divisions using multiple IT tools and different formats. Making campus-wide analytics requires bringing all these data elements and different formats (CAD, GIS, BIM) together to create a comprehensive common operating picture. In this presentation we will demonstrate how FME is a key and crucial technology to create campus wide data warehouse.
Enhancing keyword search over relational databases using ontologiescsandit
Keyword Search Over Relational Databases (KSORDB) provides an easy way for casual users
to access relational databases using a set of keywords. Although much research has been done
and several prototypes have been developed recently, most of this research implements exact
(also called syntactic or keyword) match. So, if there is a vocabulary mismatch, the user cannot
get an answer although the database may contain relevant data. In this paper we propose a
system that overcomes this issue. Our system extends existing schema-free KSORDB systems
with semantic match features. So, if there were no or very few answers, our system exploits
domain ontology to progressively return related terms that can be used to retrieve more
relevant answers to user.
ENHANCING KEYWORD SEARCH OVER RELATIONAL DATABASES USING ONTOLOGIES cscpconf
Keyword Search Over Relational Databases (KSORDB) provides an easy way for casual users to access relational databases using a set of keywords. Although much research has been done and several prototypes have been developed recently, most of this research implements exact also called syntactic or keyword) match. So, if there is a vocabulary mismatch, the user cannotget an answer although the database may contain relevant data. In this paper we propose a
system that overcomes this issue. Our system extends existing schema-free KSORDB systems with semantic match features. So, if there were no or very few answers, our system exploits
domain ontology to progressively return related terms that can be used to retrieve morerelevant answers to user.
Palestine last event orientationfvgnh .pptxRaedMohamed3
An EFL lesson about the current events in Palestine. It is intended to be for intermediate students who wish to increase their listening skills through a short lesson in power point.
FellowBuddy.com is an innovative platform that brings students together to share notes, exam papers, study guides, project reports and presentation for upcoming exams.
We connect Students who have an understanding of course material with Students who need help.
Benefits:-
# Students can catch up on notes they missed because of an absence.
# Underachievers can find peer developed notes that break down lecture and study material in a way that they can understand
# Students can earn better grades, save time and study effectively
Our Vision & Mission – Simplifying Students Life
Our Belief – “The great breakthrough in your life comes when you realize it, that you can learn anything you need to learn; to accomplish any goal that you have set for yourself. This means there are no limits on what you can be, have or do.”
Like Us - https://www.facebook.com/FellowBuddycom
Spatial decision support and analytics on a campus scale: bringing GIS, CAD, ...Safe Software
University and College Campuses are complex environments. The campus comprises many physical sub-systems, such as buildings, outdoor spaces, utilities, transportation, which are maintained by several divisions using multiple IT tools and different formats. Making campus-wide analytics requires bringing all these data elements and different formats (CAD, GIS, BIM) together to create a comprehensive common operating picture. In this presentation we will demonstrate how FME is a key and crucial technology to create campus wide data warehouse.
Enhancing keyword search over relational databases using ontologiescsandit
Keyword Search Over Relational Databases (KSORDB) provides an easy way for casual users
to access relational databases using a set of keywords. Although much research has been done
and several prototypes have been developed recently, most of this research implements exact
(also called syntactic or keyword) match. So, if there is a vocabulary mismatch, the user cannot
get an answer although the database may contain relevant data. In this paper we propose a
system that overcomes this issue. Our system extends existing schema-free KSORDB systems
with semantic match features. So, if there were no or very few answers, our system exploits
domain ontology to progressively return related terms that can be used to retrieve more
relevant answers to user.
ENHANCING KEYWORD SEARCH OVER RELATIONAL DATABASES USING ONTOLOGIES cscpconf
Keyword Search Over Relational Databases (KSORDB) provides an easy way for casual users to access relational databases using a set of keywords. Although much research has been done and several prototypes have been developed recently, most of this research implements exact also called syntactic or keyword) match. So, if there is a vocabulary mismatch, the user cannotget an answer although the database may contain relevant data. In this paper we propose a
system that overcomes this issue. Our system extends existing schema-free KSORDB systems with semantic match features. So, if there were no or very few answers, our system exploits
domain ontology to progressively return related terms that can be used to retrieve morerelevant answers to user.
Palestine last event orientationfvgnh .pptxRaedMohamed3
An EFL lesson about the current events in Palestine. It is intended to be for intermediate students who wish to increase their listening skills through a short lesson in power point.
Instructions for Submissions thorugh G- Classroom.pptxJheel Barad
This presentation provides a briefing on how to upload submissions and documents in Google Classroom. It was prepared as part of an orientation for new Sainik School in-service teacher trainees. As a training officer, my goal is to ensure that you are comfortable and proficient with this essential tool for managing assignments and fostering student engagement.
The Roman Empire A Historical Colossus.pdfkaushalkr1407
The Roman Empire, a vast and enduring power, stands as one of history's most remarkable civilizations, leaving an indelible imprint on the world. It emerged from the Roman Republic, transitioning into an imperial powerhouse under the leadership of Augustus Caesar in 27 BCE. This transformation marked the beginning of an era defined by unprecedented territorial expansion, architectural marvels, and profound cultural influence.
The empire's roots lie in the city of Rome, founded, according to legend, by Romulus in 753 BCE. Over centuries, Rome evolved from a small settlement to a formidable republic, characterized by a complex political system with elected officials and checks on power. However, internal strife, class conflicts, and military ambitions paved the way for the end of the Republic. Julius Caesar’s dictatorship and subsequent assassination in 44 BCE created a power vacuum, leading to a civil war. Octavian, later Augustus, emerged victorious, heralding the Roman Empire’s birth.
Under Augustus, the empire experienced the Pax Romana, a 200-year period of relative peace and stability. Augustus reformed the military, established efficient administrative systems, and initiated grand construction projects. The empire's borders expanded, encompassing territories from Britain to Egypt and from Spain to the Euphrates. Roman legions, renowned for their discipline and engineering prowess, secured and maintained these vast territories, building roads, fortifications, and cities that facilitated control and integration.
The Roman Empire’s society was hierarchical, with a rigid class system. At the top were the patricians, wealthy elites who held significant political power. Below them were the plebeians, free citizens with limited political influence, and the vast numbers of slaves who formed the backbone of the economy. The family unit was central, governed by the paterfamilias, the male head who held absolute authority.
Culturally, the Romans were eclectic, absorbing and adapting elements from the civilizations they encountered, particularly the Greeks. Roman art, literature, and philosophy reflected this synthesis, creating a rich cultural tapestry. Latin, the Roman language, became the lingua franca of the Western world, influencing numerous modern languages.
Roman architecture and engineering achievements were monumental. They perfected the arch, vault, and dome, constructing enduring structures like the Colosseum, Pantheon, and aqueducts. These engineering marvels not only showcased Roman ingenuity but also served practical purposes, from public entertainment to water supply.
A Strategic Approach: GenAI in EducationPeter Windle
Artificial Intelligence (AI) technologies such as Generative AI, Image Generators and Large Language Models have had a dramatic impact on teaching, learning and assessment over the past 18 months. The most immediate threat AI posed was to Academic Integrity with Higher Education Institutes (HEIs) focusing their efforts on combating the use of GenAI in assessment. Guidelines were developed for staff and students, policies put in place too. Innovative educators have forged paths in the use of Generative AI for teaching, learning and assessments leading to pockets of transformation springing up across HEIs, often with little or no top-down guidance, support or direction.
This Gasta posits a strategic approach to integrating AI into HEIs to prepare staff, students and the curriculum for an evolving world and workplace. We will highlight the advantages of working with these technologies beyond the realm of teaching, learning and assessment by considering prompt engineering skills, industry impact, curriculum changes, and the need for staff upskilling. In contrast, not engaging strategically with Generative AI poses risks, including falling behind peers, missed opportunities and failing to ensure our graduates remain employable. The rapid evolution of AI technologies necessitates a proactive and strategic approach if we are to remain relevant.
Embracing GenAI - A Strategic ImperativePeter Windle
Artificial Intelligence (AI) technologies such as Generative AI, Image Generators and Large Language Models have had a dramatic impact on teaching, learning and assessment over the past 18 months. The most immediate threat AI posed was to Academic Integrity with Higher Education Institutes (HEIs) focusing their efforts on combating the use of GenAI in assessment. Guidelines were developed for staff and students, policies put in place too. Innovative educators have forged paths in the use of Generative AI for teaching, learning and assessments leading to pockets of transformation springing up across HEIs, often with little or no top-down guidance, support or direction.
This Gasta posits a strategic approach to integrating AI into HEIs to prepare staff, students and the curriculum for an evolving world and workplace. We will highlight the advantages of working with these technologies beyond the realm of teaching, learning and assessment by considering prompt engineering skills, industry impact, curriculum changes, and the need for staff upskilling. In contrast, not engaging strategically with Generative AI poses risks, including falling behind peers, missed opportunities and failing to ensure our graduates remain employable. The rapid evolution of AI technologies necessitates a proactive and strategic approach if we are to remain relevant.
Unit 8 - Information and Communication Technology (Paper I).pdfThiyagu K
This slides describes the basic concepts of ICT, basics of Email, Emerging Technology and Digital Initiatives in Education. This presentations aligns with the UGC Paper I syllabus.
Operation “Blue Star” is the only event in the history of Independent India where the state went into war with its own people. Even after about 40 years it is not clear if it was culmination of states anger over people of the region, a political game of power or start of dictatorial chapter in the democratic setup.
The people of Punjab felt alienated from main stream due to denial of their just demands during a long democratic struggle since independence. As it happen all over the word, it led to militant struggle with great loss of lives of military, police and civilian personnel. Killing of Indira Gandhi and massacre of innocent Sikhs in Delhi and other India cities was also associated with this movement.
The French Revolution, which began in 1789, was a period of radical social and political upheaval in France. It marked the decline of absolute monarchies, the rise of secular and democratic republics, and the eventual rise of Napoleon Bonaparte. This revolutionary period is crucial in understanding the transition from feudalism to modernity in Europe.
For more information, visit-www.vavaclasses.com
2024.06.01 Introducing a competency framework for languag learning materials ...Sandy Millin
http://sandymillin.wordpress.com/iateflwebinar2024
Published classroom materials form the basis of syllabuses, drive teacher professional development, and have a potentially huge influence on learners, teachers and education systems. All teachers also create their own materials, whether a few sentences on a blackboard, a highly-structured fully-realised online course, or anything in between. Despite this, the knowledge and skills needed to create effective language learning materials are rarely part of teacher training, and are mostly learnt by trial and error.
Knowledge and skills frameworks, generally called competency frameworks, for ELT teachers, trainers and managers have existed for a few years now. However, until I created one for my MA dissertation, there wasn’t one drawing together what we need to know and do to be able to effectively produce language learning materials.
This webinar will introduce you to my framework, highlighting the key competencies I identified from my research. It will also show how anybody involved in language teaching (any language, not just English!), teacher training, managing schools or developing language learning materials can benefit from using the framework.
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)
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
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
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.
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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