SlideShare a Scribd company logo
Prepared By:
Dr. Chandan Kumar
Assistant Professor, Computer Science & Engineering
Department
Invertis University, Bareilly
Data
Structure
Linear
Array Stack Queue
Linked
List
Non-
Linear
Tree Graph
Figure 1: Types of Data Structure
Data Structure
 It is a way to arrange a data in a computer ; so that data
can be used effectively
 Data Structure is categorized into two groups in
computer science
 Linear Data Structure
 Non-linear Data Structure
Linear Data Structure
 Data items are organized linearly or sequentially
 Data elements attached one after another
 Traversing is done one after another
 Only one element can be directly reached while
traversing
 Implementation of these type data structure is very
easy (Because Computer memory is also organized in
sequential manner)
 Time complexity of linear data structure often
increases with increase in size.
Stack
 A stack is a linear data structure that works on the
principal of LIFO (Last-in-First-out)
 Mainly two operations are performed
 push - inserting an item onto
 Pop - deleting or removing an item from the stack
 To maintain stack only one pointer is used and called
TOS( Top of Stack) or TOP (Top of Pointer)
 i.e. accessible at only one end of the sequence
Stack
 A stack can be implemented by means of Array,
Structure, Pointer, and Linked List.
 Stack can either be a fixed size one or it may have a
sense of dynamic resizing.
Some Real life examples of stack
 A stack of books
 A stack of coins
 A stack of plates
Operations performed on stack
Figure 2: push & pop operations
PUSH operation
 Used to insert or add an element or an item onto top of the
stack
 Putting a new element onto stack called push operation
 A series of steps involved in push operation
 Step 1 − Checks if the stack is full.
 Step 2 − If the stack is full, produces an error and exit.
 Step 3 − If the stack is not full, increments top to point next
empty space.
 Step 4 − Adds data element to the stack location, where top is
pointing.
 Step 5 − Returns success.
PUSH operation representation
Figure 3: push operation representation
PUSH operation Algorithm
1. Insertion(a,top,item,max)
2. If top=max then
 print ‘STACK OVERFLOW’
 exit else
3. top=top+1 end if
4. a[top]=item
5. Exit
POP operation
 Used to delete or remove an element or an item from
top of the stack
 Removing an element from stack called pop operation
 A series of steps involved in pop operation
 Step 1 − Checks if the stack is empty.
 Step 2 − If the stack is empty, produces an error and
exit.
 Step 3 − If the stack is not empty, accesses the data
element at which top is pointing.
 Step 4 − Decreases the value of top by 1.
 Step 5 − Returns success.
POP operation representation
Figure 4: pop operation representation
POP operation Algorithm
1. Deletion(a,top,item)
2. If top=0 then
print ‘STACK UNDERFLOW’
exit else
3. item=a[top] end if
4. top=top-1
5. Exit
Applications of stack
 Used by compiler to check brackets, parenthesis and
braces for balance
 In expression evaluation, such as to evaluate prefix,
postfix and infix expressions.
 Also used in expression conversions
 In recursion all intermediate arguments and return
values will be stored on the stack of the processor.
 The return address and arguments are placed onto a
stack during a function call, and they popped off upon
return.
Queue
 It is an abstract data type (ADT) data structure like
stack
 queue is based on FIFO (First-in-First-out) principal.
 Unlike stacks, a queue is open at both its ends
 Two operations are performed
 enqueue or insertion- insert an element
 dequeue or deletion – delete an element
 To maintain queue two pointers are used
 Front
 Rear
Queue
 Placing an object in a queue is referred to as
"insertion or enqueue" at the end of the queue
called "rear."
 Removing an object from a queue is referred to as
"deletion or dequeue" at the other end of the queue
called "front“.
Some real life example of queue
 Waiting in line
Operations performed on queue
Figure 5: Enqueue & Dequeue operations
Enqueue operation
 Used to insert element at the end of the queue i.e. rear
 This operation is used to insert an element in a queue at
rear end.
 Following steps are involved to insert an element
 Step 1 − Check if the queue is full.
 Step 2 − If the queue is full, produce overflow error and exit.
 Step 3 − If the queue is not full, increment rear pointer to
point the next empty space.
 Step 4 − Add data element to the queue location, where the
rear is pointing.
 Step 5 − return success.
Enqueue operation representation
Figure 6: Enqueue operation representation
Enqueue operation Algorithm
if (rear = maxsize-1 )
print (“queue overflow”) and return
Else
rear = rear + 1 Queue [rear] =
item
Dequeue operation
 Used to delete element at the start of the queue i.e. front
 This operation is used to remove an element from a queue
at front end.
 Following steps are involved to insert an element
 Step 1 − Check if the queue is empty.
 Step 2 − If the queue is empty, produce underflow error and
exit.
 Step 3 − If the queue is not empty, access the data
where front is pointing.
 Step 4 − Increment front pointer to point to the next
available data element.
 Step 5 − Return success.
Dequeue operation representation
Figure 7: Dequeue operation representation
Dequeue operation Algorithm
If (front =rear)
print “queue empty” and return
Else
Front = front + 1
item = queue [front];
Return item
Applications of Queue
 It is used to schedule the jobs to be processed by the
CPU.
 When several users submit print jobs to a printer,
each print job is kept in the queue for printing.
 Breadth first search (BFS) uses a queue data structure
to find an element from a graph.
 Key board buffering
 Round Robin scheduling
Stack and queue
Ad

More Related Content

What's hot (20)

Stack and Queue by M.Gomathi Lecturer
Stack and Queue by M.Gomathi LecturerStack and Queue by M.Gomathi Lecturer
Stack and Queue by M.Gomathi Lecturer
gomathi chlm
 
Stacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURESStacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURES
Sowmya Jyothi
 
1.1 binary tree
1.1 binary tree1.1 binary tree
1.1 binary tree
Krish_ver2
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
Zidny Nafan
 
Stack
StackStack
Stack
Zaid Shabbir
 
single linked list
single linked listsingle linked list
single linked list
Sathasivam Rangasamy
 
Stack and its Applications : Data Structures ADT
Stack and its Applications : Data Structures ADTStack and its Applications : Data Structures ADT
Stack and its Applications : Data Structures ADT
Soumen Santra
 
Queues
QueuesQueues
Queues
Ashim Lamichhane
 
Doubly linked list
Doubly linked listDoubly linked list
Doubly linked list
chauhankapil
 
Binary search tree(bst)
Binary search tree(bst)Binary search tree(bst)
Binary search tree(bst)
Hossain Md Shakhawat
 
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Balwant Gorad
 
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
Umesh Kumar
 
Linked List
Linked ListLinked List
Linked List
Ashim Lamichhane
 
Binary search tree operations
Binary search tree operationsBinary search tree operations
Binary search tree operations
Kamran Zafar
 
Stack ADT
Stack ADTStack ADT
Stack ADT
MrsKArunasakthiCSE22
 
Unit I - Evaluation of expression
Unit I - Evaluation of expressionUnit I - Evaluation of expression
Unit I - Evaluation of expression
DrkhanchanaR
 
Binary Tree in Data Structure
Binary Tree in Data StructureBinary Tree in Data Structure
Binary Tree in Data Structure
Meghaj Mallick
 
Trees, Binary Search Tree, AVL Tree in Data Structures
Trees, Binary Search Tree, AVL Tree in Data Structures Trees, Binary Search Tree, AVL Tree in Data Structures
Trees, Binary Search Tree, AVL Tree in Data Structures
Gurukul Kangri Vishwavidyalaya - Faculty of Engineering and Technology
 
Linked list
Linked listLinked list
Linked list
KalaivaniKS1
 
Searching techniques in Data Structure And Algorithm
Searching techniques in Data Structure And AlgorithmSearching techniques in Data Structure And Algorithm
Searching techniques in Data Structure And Algorithm
03446940736
 
Stack and Queue by M.Gomathi Lecturer
Stack and Queue by M.Gomathi LecturerStack and Queue by M.Gomathi Lecturer
Stack and Queue by M.Gomathi Lecturer
gomathi chlm
 
Stacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURESStacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURES
Sowmya Jyothi
 
1.1 binary tree
1.1 binary tree1.1 binary tree
1.1 binary tree
Krish_ver2
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
Zidny Nafan
 
Stack and its Applications : Data Structures ADT
Stack and its Applications : Data Structures ADTStack and its Applications : Data Structures ADT
Stack and its Applications : Data Structures ADT
Soumen Santra
 
Doubly linked list
Doubly linked listDoubly linked list
Doubly linked list
chauhankapil
 
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Balwant Gorad
 
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
Umesh Kumar
 
Binary search tree operations
Binary search tree operationsBinary search tree operations
Binary search tree operations
Kamran Zafar
 
Unit I - Evaluation of expression
Unit I - Evaluation of expressionUnit I - Evaluation of expression
Unit I - Evaluation of expression
DrkhanchanaR
 
Binary Tree in Data Structure
Binary Tree in Data StructureBinary Tree in Data Structure
Binary Tree in Data Structure
Meghaj Mallick
 
Searching techniques in Data Structure And Algorithm
Searching techniques in Data Structure And AlgorithmSearching techniques in Data Structure And Algorithm
Searching techniques in Data Structure And Algorithm
03446940736
 

Similar to Stack and queue (20)

VCE Unit 03vv.pptx
VCE Unit 03vv.pptxVCE Unit 03vv.pptx
VCE Unit 03vv.pptx
skilljiolms
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
Poulami Das Akuli
 
Queue
QueueQueue
Queue
pooja kumari
 
Stacks-and-Queues.pdf
Stacks-and-Queues.pdfStacks-and-Queues.pdf
Stacks-and-Queues.pdf
TobyWtf
 
Difference between stack and queue
Difference between stack and queueDifference between stack and queue
Difference between stack and queue
Pulkitmodi1998
 
The presentation on stack data structure
The presentation on stack data structureThe presentation on stack data structure
The presentation on stack data structure
gaurav77712
 
The Stack in data structures .ppt
The Stack in data structures         .pptThe Stack in data structures         .ppt
The Stack in data structures .ppt
donemoremaregere376
 
Queue and its operations
Queue and its operationsQueue and its operations
Queue and its operations
V.V.Vanniaperumal College for Women
 
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority QueueWhat is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
Balwant Gorad
 
unit 5 stack & queue.ppt
unit 5 stack & queue.pptunit 5 stack & queue.ppt
unit 5 stack & queue.ppt
SeethaDinesh
 
Data Structures by Maneesh Boddu
Data Structures by Maneesh BodduData Structures by Maneesh Boddu
Data Structures by Maneesh Boddu
maneesh boddu
 
Stack and queue
Stack and queueStack and queue
Stack and queue
Anil Kumar Prajapati
 
Stacks and queues using aaray line .pptx
Stacks and queues using aaray line .pptxStacks and queues using aaray line .pptx
Stacks and queues using aaray line .pptx
ramkumar649780
 
Stack and its operations, Queue and its operations
Stack and its operations, Queue and its operationsStack and its operations, Queue and its operations
Stack and its operations, Queue and its operations
poongothai11
 
Queue
QueueQueue
Queue
Swarup Boro
 
Data structure , stack , queue
Data structure , stack , queueData structure , stack , queue
Data structure , stack , queue
Rajkiran Nadar
 
DSA_Ques ewoifhjerofhefhehfreofheek.pptx
DSA_Ques ewoifhjerofhefhehfreofheek.pptxDSA_Ques ewoifhjerofhefhehfreofheek.pptx
DSA_Ques ewoifhjerofhefhehfreofheek.pptx
arnab13984
 
Stack organization
Stack organizationStack organization
Stack organization
chauhankapil
 
هياكلبيانات
هياكلبياناتهياكلبيانات
هياكلبيانات
Rafal Edward
 
Stack.pptx
Stack.pptxStack.pptx
Stack.pptx
SherinRappai
 
VCE Unit 03vv.pptx
VCE Unit 03vv.pptxVCE Unit 03vv.pptx
VCE Unit 03vv.pptx
skilljiolms
 
Stacks-and-Queues.pdf
Stacks-and-Queues.pdfStacks-and-Queues.pdf
Stacks-and-Queues.pdf
TobyWtf
 
Difference between stack and queue
Difference between stack and queueDifference between stack and queue
Difference between stack and queue
Pulkitmodi1998
 
The presentation on stack data structure
The presentation on stack data structureThe presentation on stack data structure
The presentation on stack data structure
gaurav77712
 
The Stack in data structures .ppt
The Stack in data structures         .pptThe Stack in data structures         .ppt
The Stack in data structures .ppt
donemoremaregere376
 
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority QueueWhat is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
Balwant Gorad
 
unit 5 stack & queue.ppt
unit 5 stack & queue.pptunit 5 stack & queue.ppt
unit 5 stack & queue.ppt
SeethaDinesh
 
Data Structures by Maneesh Boddu
Data Structures by Maneesh BodduData Structures by Maneesh Boddu
Data Structures by Maneesh Boddu
maneesh boddu
 
Stacks and queues using aaray line .pptx
Stacks and queues using aaray line .pptxStacks and queues using aaray line .pptx
Stacks and queues using aaray line .pptx
ramkumar649780
 
Stack and its operations, Queue and its operations
Stack and its operations, Queue and its operationsStack and its operations, Queue and its operations
Stack and its operations, Queue and its operations
poongothai11
 
Data structure , stack , queue
Data structure , stack , queueData structure , stack , queue
Data structure , stack , queue
Rajkiran Nadar
 
DSA_Ques ewoifhjerofhefhehfreofheek.pptx
DSA_Ques ewoifhjerofhefhehfreofheek.pptxDSA_Ques ewoifhjerofhefhehfreofheek.pptx
DSA_Ques ewoifhjerofhefhehfreofheek.pptx
arnab13984
 
Stack organization
Stack organizationStack organization
Stack organization
chauhankapil
 
هياكلبيانات
هياكلبياناتهياكلبيانات
هياكلبيانات
Rafal Edward
 
Ad

More from CHANDAN KUMAR (13)

Chart and graphs in R programming language
Chart and graphs in R programming language Chart and graphs in R programming language
Chart and graphs in R programming language
CHANDAN KUMAR
 
Raid technology
Raid technologyRaid technology
Raid technology
CHANDAN KUMAR
 
Pointers in c
Pointers in cPointers in c
Pointers in c
CHANDAN KUMAR
 
Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithms
CHANDAN KUMAR
 
Searching in c language
Searching in c languageSearching in c language
Searching in c language
CHANDAN KUMAR
 
Greedy algorithm
Greedy algorithmGreedy algorithm
Greedy algorithm
CHANDAN KUMAR
 
Divide and conquer algorithm
Divide and conquer algorithmDivide and conquer algorithm
Divide and conquer algorithm
CHANDAN KUMAR
 
Arrays in c
Arrays in cArrays in c
Arrays in c
CHANDAN KUMAR
 
Loops in c programming
Loops in c programmingLoops in c programming
Loops in c programming
CHANDAN KUMAR
 
Linked List
Linked ListLinked List
Linked List
CHANDAN KUMAR
 
Technical questions for interview c programming
Technical questions for interview  c programmingTechnical questions for interview  c programming
Technical questions for interview c programming
CHANDAN KUMAR
 
Decision making using if statement
Decision making using if statementDecision making using if statement
Decision making using if statement
CHANDAN KUMAR
 
"A short and knowledgeable concept about Algorithm "
"A short and knowledgeable concept about Algorithm ""A short and knowledgeable concept about Algorithm "
"A short and knowledgeable concept about Algorithm "
CHANDAN KUMAR
 
Chart and graphs in R programming language
Chart and graphs in R programming language Chart and graphs in R programming language
Chart and graphs in R programming language
CHANDAN KUMAR
 
Searching in c language
Searching in c languageSearching in c language
Searching in c language
CHANDAN KUMAR
 
Divide and conquer algorithm
Divide and conquer algorithmDivide and conquer algorithm
Divide and conquer algorithm
CHANDAN KUMAR
 
Loops in c programming
Loops in c programmingLoops in c programming
Loops in c programming
CHANDAN KUMAR
 
Technical questions for interview c programming
Technical questions for interview  c programmingTechnical questions for interview  c programming
Technical questions for interview c programming
CHANDAN KUMAR
 
Decision making using if statement
Decision making using if statementDecision making using if statement
Decision making using if statement
CHANDAN KUMAR
 
"A short and knowledgeable concept about Algorithm "
"A short and knowledgeable concept about Algorithm ""A short and knowledgeable concept about Algorithm "
"A short and knowledgeable concept about Algorithm "
CHANDAN KUMAR
 
Ad

Recently uploaded (20)

Ancient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian HistoryAncient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian History
Virag Sontakke
 
Form View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo SlidesForm View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo Slides
Celine George
 
Pope Leo XIV, the first Pope from North America.pptx
Pope Leo XIV, the first Pope from North America.pptxPope Leo XIV, the first Pope from North America.pptx
Pope Leo XIV, the first Pope from North America.pptx
Martin M Flynn
 
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFAMEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
Dr. Nasir Mustafa
 
Myopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduateMyopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduate
Mohamed Rizk Khodair
 
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptxANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
Mayuri Chavan
 
The History of Kashmir Karkota Dynasty NEP.pptx
The History of Kashmir Karkota Dynasty NEP.pptxThe History of Kashmir Karkota Dynasty NEP.pptx
The History of Kashmir Karkota Dynasty NEP.pptx
Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
How to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo SlidesHow to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo Slides
Celine George
 
CNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscessCNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscess
Mohamed Rizk Khodair
 
Ajanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of HistoryAjanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of History
Virag Sontakke
 
How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18
Celine George
 
How to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 PurchaseHow to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 Purchase
Celine George
 
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Leonel Morgado
 
2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx
mansk2
 
Rock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian HistoryRock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian History
Virag Sontakke
 
Botany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic ExcellenceBotany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic Excellence
online college homework help
 
Transform tomorrow: Master benefits analysis with Gen AI today webinar, 30 A...
Transform tomorrow: Master benefits analysis with Gen AI today webinar,  30 A...Transform tomorrow: Master benefits analysis with Gen AI today webinar,  30 A...
Transform tomorrow: Master benefits analysis with Gen AI today webinar, 30 A...
Association for Project Management
 
E-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26ASE-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26AS
Abinash Palangdar
 
Cultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptxCultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptx
UmeshTimilsina1
 
Ancient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian HistoryAncient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian History
Virag Sontakke
 
Form View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo SlidesForm View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo Slides
Celine George
 
Pope Leo XIV, the first Pope from North America.pptx
Pope Leo XIV, the first Pope from North America.pptxPope Leo XIV, the first Pope from North America.pptx
Pope Leo XIV, the first Pope from North America.pptx
Martin M Flynn
 
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFAMEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
Dr. Nasir Mustafa
 
Myopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduateMyopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduate
Mohamed Rizk Khodair
 
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptxANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
Mayuri Chavan
 
How to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo SlidesHow to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo Slides
Celine George
 
CNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscessCNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscess
Mohamed Rizk Khodair
 
Ajanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of HistoryAjanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of History
Virag Sontakke
 
How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18
Celine George
 
How to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 PurchaseHow to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 Purchase
Celine George
 
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Leonel Morgado
 
2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx
mansk2
 
Rock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian HistoryRock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian History
Virag Sontakke
 
Botany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic ExcellenceBotany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic Excellence
online college homework help
 
Transform tomorrow: Master benefits analysis with Gen AI today webinar, 30 A...
Transform tomorrow: Master benefits analysis with Gen AI today webinar,  30 A...Transform tomorrow: Master benefits analysis with Gen AI today webinar,  30 A...
Transform tomorrow: Master benefits analysis with Gen AI today webinar, 30 A...
Association for Project Management
 
E-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26ASE-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26AS
Abinash Palangdar
 
Cultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptxCultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptx
UmeshTimilsina1
 

Stack and queue

  • 1. Prepared By: Dr. Chandan Kumar Assistant Professor, Computer Science & Engineering Department Invertis University, Bareilly
  • 3. Data Structure  It is a way to arrange a data in a computer ; so that data can be used effectively  Data Structure is categorized into two groups in computer science  Linear Data Structure  Non-linear Data Structure
  • 4. Linear Data Structure  Data items are organized linearly or sequentially  Data elements attached one after another  Traversing is done one after another  Only one element can be directly reached while traversing  Implementation of these type data structure is very easy (Because Computer memory is also organized in sequential manner)  Time complexity of linear data structure often increases with increase in size.
  • 5. Stack  A stack is a linear data structure that works on the principal of LIFO (Last-in-First-out)  Mainly two operations are performed  push - inserting an item onto  Pop - deleting or removing an item from the stack  To maintain stack only one pointer is used and called TOS( Top of Stack) or TOP (Top of Pointer)  i.e. accessible at only one end of the sequence
  • 6. Stack  A stack can be implemented by means of Array, Structure, Pointer, and Linked List.  Stack can either be a fixed size one or it may have a sense of dynamic resizing.
  • 7. Some Real life examples of stack  A stack of books  A stack of coins  A stack of plates
  • 8. Operations performed on stack Figure 2: push & pop operations
  • 9. PUSH operation  Used to insert or add an element or an item onto top of the stack  Putting a new element onto stack called push operation  A series of steps involved in push operation  Step 1 − Checks if the stack is full.  Step 2 − If the stack is full, produces an error and exit.  Step 3 − If the stack is not full, increments top to point next empty space.  Step 4 − Adds data element to the stack location, where top is pointing.  Step 5 − Returns success.
  • 10. PUSH operation representation Figure 3: push operation representation
  • 11. PUSH operation Algorithm 1. Insertion(a,top,item,max) 2. If top=max then  print ‘STACK OVERFLOW’  exit else 3. top=top+1 end if 4. a[top]=item 5. Exit
  • 12. POP operation  Used to delete or remove an element or an item from top of the stack  Removing an element from stack called pop operation  A series of steps involved in pop operation  Step 1 − Checks if the stack is empty.  Step 2 − If the stack is empty, produces an error and exit.  Step 3 − If the stack is not empty, accesses the data element at which top is pointing.  Step 4 − Decreases the value of top by 1.  Step 5 − Returns success.
  • 13. POP operation representation Figure 4: pop operation representation
  • 14. POP operation Algorithm 1. Deletion(a,top,item) 2. If top=0 then print ‘STACK UNDERFLOW’ exit else 3. item=a[top] end if 4. top=top-1 5. Exit
  • 15. Applications of stack  Used by compiler to check brackets, parenthesis and braces for balance  In expression evaluation, such as to evaluate prefix, postfix and infix expressions.  Also used in expression conversions  In recursion all intermediate arguments and return values will be stored on the stack of the processor.  The return address and arguments are placed onto a stack during a function call, and they popped off upon return.
  • 16. Queue  It is an abstract data type (ADT) data structure like stack  queue is based on FIFO (First-in-First-out) principal.  Unlike stacks, a queue is open at both its ends  Two operations are performed  enqueue or insertion- insert an element  dequeue or deletion – delete an element  To maintain queue two pointers are used  Front  Rear
  • 17. Queue  Placing an object in a queue is referred to as "insertion or enqueue" at the end of the queue called "rear."  Removing an object from a queue is referred to as "deletion or dequeue" at the other end of the queue called "front“.
  • 18. Some real life example of queue  Waiting in line
  • 19. Operations performed on queue Figure 5: Enqueue & Dequeue operations
  • 20. Enqueue operation  Used to insert element at the end of the queue i.e. rear  This operation is used to insert an element in a queue at rear end.  Following steps are involved to insert an element  Step 1 − Check if the queue is full.  Step 2 − If the queue is full, produce overflow error and exit.  Step 3 − If the queue is not full, increment rear pointer to point the next empty space.  Step 4 − Add data element to the queue location, where the rear is pointing.  Step 5 − return success.
  • 21. Enqueue operation representation Figure 6: Enqueue operation representation
  • 22. Enqueue operation Algorithm if (rear = maxsize-1 ) print (“queue overflow”) and return Else rear = rear + 1 Queue [rear] = item
  • 23. Dequeue operation  Used to delete element at the start of the queue i.e. front  This operation is used to remove an element from a queue at front end.  Following steps are involved to insert an element  Step 1 − Check if the queue is empty.  Step 2 − If the queue is empty, produce underflow error and exit.  Step 3 − If the queue is not empty, access the data where front is pointing.  Step 4 − Increment front pointer to point to the next available data element.  Step 5 − Return success.
  • 24. Dequeue operation representation Figure 7: Dequeue operation representation
  • 25. Dequeue operation Algorithm If (front =rear) print “queue empty” and return Else Front = front + 1 item = queue [front]; Return item
  • 26. Applications of Queue  It is used to schedule the jobs to be processed by the CPU.  When several users submit print jobs to a printer, each print job is kept in the queue for printing.  Breadth first search (BFS) uses a queue data structure to find an element from a graph.  Key board buffering  Round Robin scheduling
  翻译: