SlideShare a Scribd company logo
1 of 17
Lecture # 5Lecture # 5
Abstract Data TypeAbstract Data Type
 We have looked at four different implementationsWe have looked at four different implementations
of the List data structures:of the List data structures:
 Using arraysUsing arrays
 Singly linked listSingly linked list
 Doubly linked listDoubly linked list
 Circularly linked list.Circularly linked list.
 The interface to the List stayed the same, i.e.,The interface to the List stayed the same, i.e.,
add(), get(), next(), start(), remove() etc.add(), get(), next(), start(), remove() etc.
 The list is thus an abstract data type; we use itThe list is thus an abstract data type; we use it
without being concerned with how it iswithout being concerned with how it is
implemented.implemented.
Abstract Data TypeAbstract Data Type
 What we care about is theWhat we care about is the methodsmethods that arethat are
available for use with the List ADT.available for use with the List ADT.
 We will follow this theme when we develop otherWe will follow this theme when we develop other
ADT.ADT.
 We willWe will publish the interfacepublish the interface and keep theand keep the
freedom to change the implementation of ADTfreedom to change the implementation of ADT
without effecting users of the ADT.without effecting users of the ADT.
 The C++ classes provide us the ability to createThe C++ classes provide us the ability to create
such ADTs.such ADTs.
StackStack
StackStack
 Stacks in real life: stack of books, stack ofStacks in real life: stack of books, stack of
platesplates
 Add new items at the topAdd new items at the top
 Remove an item at the topRemove an item at the top
 Stack data structure similar to real life:Stack data structure similar to real life:
collection of elements arranged in a linearcollection of elements arranged in a linear
order.order.
 Can only access element at the topCan only access element at the top
 AA stackstack is an ordered collection of items intois an ordered collection of items into
which new items may bewhich new items may be insertedinserted and fromand from
which items may bewhich items may be deleteddeleted at one end only,at one end only,
calledcalled toptop of the stack. i.e.of the stack. i.e. deletion/insertiondeletion/insertion cancan
only be done fromonly be done from toptop of the stack.of the stack.
 TheThe insertinsert operation on a stack is often calledoperation on a stack is often called
PushPush operation andoperation and deletedelete operation is calledoperation is called
PopPop operation.operation.
 Figure showing stack…..Figure showing stack…..
B
A
D
C
Top of theTop of the
StackStack
NULLNULL
 In aIn a stackstack, the element, the element deleteddeleted from the list isfrom the list is
the one mostthe one most recently insertedrecently inserted..
 Stack is also referred asStack is also referred as Last-in First-outLast-in First-out i.ei.e
LIFOLIFO..
 The example of stack is theThe example of stack is the stacks of platesstacks of plates
used in cafeterias. The order in which plates areused in cafeterias. The order in which plates are
poppedpopped from the stack is the reverse of the orderfrom the stack is the reverse of the order
in which they werein which they were pushedpushed onto the stack, sinceonto the stack, since
only theonly the top plate is accessibletop plate is accessible..
 If anIf an emptyempty stack is popped, we say stackstack is popped, we say stack
underflowsunderflows, which is normally an error. and, which is normally an error. and
 IfIf toptop of the stack exceedsof the stack exceeds nn, the stack, the stack
overflowsoverflows..
Stack OperationsStack Operations
 Push(X) – insert X as the top element ofPush(X) – insert X as the top element of
the stackthe stack
 Pop() – remove the top element of thePop() – remove the top element of the
stack and return it.stack and return it.
 Top() – return the top element withoutTop() – return the top element without
removing it from the stack.removing it from the stack.
Stack OperationStack Operation
 The last element to go into the stack is the firstThe last element to go into the stack is the first
to come out:to come out: LIFOLIFO – Last In First Out.– Last In First Out.
 What happens if we call pop() and there is noWhat happens if we call pop() and there is no
element?element?
 Have IsEmpty() boolean function that returnsHave IsEmpty() boolean function that returns
true if stack is empty, false otherwise.true if stack is empty, false otherwise.
 Throw StackEmpty exception: advanced C++Throw StackEmpty exception: advanced C++
concept.concept.
Stack Implementation: ArrayStack Implementation: Array
 Worst caseWorst case for insertion and deletion from anfor insertion and deletion from an
array when insert and delete from thearray when insert and delete from the
beginning:beginning: shift elements to the leftshift elements to the left..
 Best caseBest case for insert and delete is at the endfor insert and delete is at the end
of the array –of the array – no need to shift any elementsno need to shift any elements..
 Implement push() and pop() by inserting andImplement push() and pop() by inserting and
deleting at thedeleting at the end of an arrayend of an array
Stack Implementation: ArrayStack Implementation: Array
Stack using an ArrayStack using an Array
 In case of an array, it is possible that theIn case of an array, it is possible that the
array may “fill-up” if we push enougharray may “fill-up” if we push enough
elements.elements.
 Have a boolean functionHave a boolean function IsFull()IsFull() whichwhich
returns true if stack (array) is full, falsereturns true if stack (array) is full, false
otherwise.otherwise.
 We would call this function before callingWe would call this function before calling
push(x).push(x).
Stack Using Linked ListStack Using Linked List
 We canWe can avoid the size limitationavoid the size limitation of a stackof a stack
implemented with an array by using aimplemented with an array by using a
linked list to hold the stack elements.linked list to hold the stack elements.
 As with array, however, we need to decideAs with array, however, we need to decide
where to insert elements in the list andwhere to insert elements in the list and
where to delete them so that push andwhere to delete them so that push and
pop will run the fastest.pop will run the fastest.
Lecture5

More Related Content

What's hot

Difference between stack and queue
Difference between stack and queueDifference between stack and queue
Difference between stack and queuePulkitmodi1998
 
Queues and Stacks
Queues and StacksQueues and Stacks
Queues and StacksProf Ansari
 
Stack and Queue (brief)
Stack and Queue (brief)Stack and Queue (brief)
Stack and Queue (brief)Sanjay Saha
 
Data Structure Lecture 2
Data Structure Lecture 2Data Structure Lecture 2
Data Structure Lecture 2Teksify
 
Queue Data Structure (w/ php egs)
Queue Data Structure (w/ php egs)Queue Data Structure (w/ php egs)
Queue Data Structure (w/ php egs)Roman Rodomansky
 
23 stacks-queues-deques
23 stacks-queues-deques23 stacks-queues-deques
23 stacks-queues-dequesRishabh Jindal
 
Stack operation algorithms with example
Stack operation algorithms with exampleStack operation algorithms with example
Stack operation algorithms with exampleNamanKikani
 
Stacks & Queues By Ms. Niti Arora
Stacks & Queues By Ms. Niti AroraStacks & Queues By Ms. Niti Arora
Stacks & Queues By Ms. Niti Arorakulachihansraj
 
Stacks and queues
Stacks and queuesStacks and queues
Stacks and queuesAbbott
 
Bsc cs ii dfs u-2 linklist,stack,queue
Bsc cs ii  dfs u-2 linklist,stack,queueBsc cs ii  dfs u-2 linklist,stack,queue
Bsc cs ii dfs u-2 linklist,stack,queueRai University
 
Mca ii dfs u-3 linklist,stack,queue
Mca ii dfs u-3 linklist,stack,queueMca ii dfs u-3 linklist,stack,queue
Mca ii dfs u-3 linklist,stack,queueRai University
 

What's hot (20)

Stack and Queue
Stack and Queue Stack and Queue
Stack and Queue
 
Stack & queue
Stack & queueStack & queue
Stack & queue
 
Stack and queue
Stack and queueStack and queue
Stack and queue
 
Difference between stack and queue
Difference between stack and queueDifference between stack and queue
Difference between stack and queue
 
U3.stack queue
U3.stack queueU3.stack queue
U3.stack queue
 
Queues and Stacks
Queues and StacksQueues and Stacks
Queues and Stacks
 
Stack and Queue (brief)
Stack and Queue (brief)Stack and Queue (brief)
Stack and Queue (brief)
 
Data Structure Lecture 2
Data Structure Lecture 2Data Structure Lecture 2
Data Structure Lecture 2
 
Data Structures - Lecture 6 [queues]
Data Structures - Lecture 6 [queues]Data Structures - Lecture 6 [queues]
Data Structures - Lecture 6 [queues]
 
Queue Data Structure (w/ php egs)
Queue Data Structure (w/ php egs)Queue Data Structure (w/ php egs)
Queue Data Structure (w/ php egs)
 
23 stacks-queues-deques
23 stacks-queues-deques23 stacks-queues-deques
23 stacks-queues-deques
 
Queue
QueueQueue
Queue
 
Queue
QueueQueue
Queue
 
Stack operation algorithms with example
Stack operation algorithms with exampleStack operation algorithms with example
Stack operation algorithms with example
 
Stacks & Queues By Ms. Niti Arora
Stacks & Queues By Ms. Niti AroraStacks & Queues By Ms. Niti Arora
Stacks & Queues By Ms. Niti Arora
 
Stack, queue and hashing
Stack, queue and hashingStack, queue and hashing
Stack, queue and hashing
 
stack & queue
stack & queuestack & queue
stack & queue
 
Stacks and queues
Stacks and queuesStacks and queues
Stacks and queues
 
Bsc cs ii dfs u-2 linklist,stack,queue
Bsc cs ii  dfs u-2 linklist,stack,queueBsc cs ii  dfs u-2 linklist,stack,queue
Bsc cs ii dfs u-2 linklist,stack,queue
 
Mca ii dfs u-3 linklist,stack,queue
Mca ii dfs u-3 linklist,stack,queueMca ii dfs u-3 linklist,stack,queue
Mca ii dfs u-3 linklist,stack,queue
 

Viewers also liked

Computer notes - Josephus Problem
Computer notes - Josephus ProblemComputer notes - Josephus Problem
Computer notes - Josephus Problemecomputernotes
 
9781285852744 ppt ch18
9781285852744 ppt ch189781285852744 ppt ch18
9781285852744 ppt ch18Terry Yoast
 
Stacks in algorithems & data structure
Stacks in algorithems & data structureStacks in algorithems & data structure
Stacks in algorithems & data structurefaran nawaz
 
10. Search Tree - Data Structures using C++ by Varsha Patil
10. Search Tree - Data Structures using C++ by Varsha Patil10. Search Tree - Data Structures using C++ by Varsha Patil
10. Search Tree - Data Structures using C++ by Varsha Patilwidespreadpromotion
 
15. STL - Data Structures using C++ by Varsha Patil
15. STL - Data Structures using C++ by Varsha Patil15. STL - Data Structures using C++ by Varsha Patil
15. STL - Data Structures using C++ by Varsha Patilwidespreadpromotion
 
5. Queue - Data Structures using C++ by Varsha Patil
5. Queue - Data Structures using C++ by Varsha Patil5. Queue - Data Structures using C++ by Varsha Patil
5. Queue - Data Structures using C++ by Varsha Patilwidespreadpromotion
 
3. Stack - Data Structures using C++ by Varsha Patil
3. Stack - Data Structures using C++ by Varsha Patil3. Stack - Data Structures using C++ by Varsha Patil
3. Stack - Data Structures using C++ by Varsha Patilwidespreadpromotion
 
6. Linked list - Data Structures using C++ by Varsha Patil
6. Linked list - Data Structures using C++ by Varsha Patil6. Linked list - Data Structures using C++ by Varsha Patil
6. Linked list - Data Structures using C++ by Varsha Patilwidespreadpromotion
 
7. Tree - Data Structures using C++ by Varsha Patil
7. Tree - Data Structures using C++ by Varsha Patil7. Tree - Data Structures using C++ by Varsha Patil
7. Tree - Data Structures using C++ by Varsha Patilwidespreadpromotion
 
9. Searching & Sorting - Data Structures using C++ by Varsha Patil
9. Searching & Sorting - Data Structures using C++ by Varsha Patil9. Searching & Sorting - Data Structures using C++ by Varsha Patil
9. Searching & Sorting - Data Structures using C++ by Varsha Patilwidespreadpromotion
 
មេរៀនៈ Data Structure and Algorithm in C/C++
មេរៀនៈ Data Structure and Algorithm in C/C++មេរៀនៈ Data Structure and Algorithm in C/C++
មេរៀនៈ Data Structure and Algorithm in C/C++Ngeam Soly
 
Fundamentals of data structures
Fundamentals of data structuresFundamentals of data structures
Fundamentals of data structuresNiraj Agarwal
 

Viewers also liked (14)

Lec8
Lec8Lec8
Lec8
 
Computer notes - Josephus Problem
Computer notes - Josephus ProblemComputer notes - Josephus Problem
Computer notes - Josephus Problem
 
9781285852744 ppt ch18
9781285852744 ppt ch189781285852744 ppt ch18
9781285852744 ppt ch18
 
Stacks in algorithems & data structure
Stacks in algorithems & data structureStacks in algorithems & data structure
Stacks in algorithems & data structure
 
10. Search Tree - Data Structures using C++ by Varsha Patil
10. Search Tree - Data Structures using C++ by Varsha Patil10. Search Tree - Data Structures using C++ by Varsha Patil
10. Search Tree - Data Structures using C++ by Varsha Patil
 
15. STL - Data Structures using C++ by Varsha Patil
15. STL - Data Structures using C++ by Varsha Patil15. STL - Data Structures using C++ by Varsha Patil
15. STL - Data Structures using C++ by Varsha Patil
 
5. Queue - Data Structures using C++ by Varsha Patil
5. Queue - Data Structures using C++ by Varsha Patil5. Queue - Data Structures using C++ by Varsha Patil
5. Queue - Data Structures using C++ by Varsha Patil
 
3. Stack - Data Structures using C++ by Varsha Patil
3. Stack - Data Structures using C++ by Varsha Patil3. Stack - Data Structures using C++ by Varsha Patil
3. Stack - Data Structures using C++ by Varsha Patil
 
6. Linked list - Data Structures using C++ by Varsha Patil
6. Linked list - Data Structures using C++ by Varsha Patil6. Linked list - Data Structures using C++ by Varsha Patil
6. Linked list - Data Structures using C++ by Varsha Patil
 
7. Tree - Data Structures using C++ by Varsha Patil
7. Tree - Data Structures using C++ by Varsha Patil7. Tree - Data Structures using C++ by Varsha Patil
7. Tree - Data Structures using C++ by Varsha Patil
 
Linked list
Linked listLinked list
Linked list
 
9. Searching & Sorting - Data Structures using C++ by Varsha Patil
9. Searching & Sorting - Data Structures using C++ by Varsha Patil9. Searching & Sorting - Data Structures using C++ by Varsha Patil
9. Searching & Sorting - Data Structures using C++ by Varsha Patil
 
មេរៀនៈ Data Structure and Algorithm in C/C++
មេរៀនៈ Data Structure and Algorithm in C/C++មេរៀនៈ Data Structure and Algorithm in C/C++
មេរៀនៈ Data Structure and Algorithm in C/C++
 
Fundamentals of data structures
Fundamentals of data structuresFundamentals of data structures
Fundamentals of data structures
 

Similar to Lecture5

Similar to Lecture5 (20)

Stacks Data structure.pptx
Stacks Data structure.pptxStacks Data structure.pptx
Stacks Data structure.pptx
 
Stacks
StacksStacks
Stacks
 
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
 
DS UNIT 1.pdf
DS UNIT 1.pdfDS UNIT 1.pdf
DS UNIT 1.pdf
 
DS UNIT 1.pdf
DS UNIT 1.pdfDS UNIT 1.pdf
DS UNIT 1.pdf
 
Lecture2
Lecture2Lecture2
Lecture2
 
Stack & Queue
Stack & QueueStack & Queue
Stack & Queue
 
Stack and its operations
Stack and its operationsStack and its operations
Stack and its operations
 
Module 2 ppt.pptx
Module 2 ppt.pptxModule 2 ppt.pptx
Module 2 ppt.pptx
 
Stack linked list
Stack linked listStack linked list
Stack linked list
 
Stacks in data structure
Stacks  in data structureStacks  in data structure
Stacks in data structure
 
Introduction to stack
Introduction to stackIntroduction to stack
Introduction to stack
 
Stack data structure
Stack data structureStack data structure
Stack data structure
 
Stack and its operation implemented with array new - Copy.pptx
Stack and its operation implemented with array new - Copy.pptxStack and its operation implemented with array new - Copy.pptx
Stack and its operation implemented with array new - Copy.pptx
 
Lect 15-16 Zaheer Abbas
Lect 15-16 Zaheer  AbbasLect 15-16 Zaheer  Abbas
Lect 15-16 Zaheer Abbas
 
STACK ( LIFO STRUCTURE) - Data Structure
STACK ( LIFO STRUCTURE) - Data StructureSTACK ( LIFO STRUCTURE) - Data Structure
STACK ( LIFO STRUCTURE) - Data Structure
 
DATA STRUCTURE - STACK
DATA STRUCTURE - STACKDATA STRUCTURE - STACK
DATA STRUCTURE - STACK
 
Data structure Stack
Data structure StackData structure Stack
Data structure Stack
 
Bca ii dfs u-2 linklist,stack,queue
Bca ii  dfs u-2 linklist,stack,queueBca ii  dfs u-2 linklist,stack,queue
Bca ii dfs u-2 linklist,stack,queue
 
Stack
StackStack
Stack
 

More from Muhammad Zubair (13)

Cloud computing
Cloud computingCloud computing
Cloud computing
 
Cloud computing disadvantages
Cloud computing disadvantagesCloud computing disadvantages
Cloud computing disadvantages
 
Lecture10
Lecture10Lecture10
Lecture10
 
Lecture9 recursion
Lecture9 recursionLecture9 recursion
Lecture9 recursion
 
Lecture8
Lecture8Lecture8
Lecture8
 
Lecture7
Lecture7Lecture7
Lecture7
 
Lecture6
Lecture6Lecture6
Lecture6
 
Lecture4
Lecture4Lecture4
Lecture4
 
Lecture3
Lecture3Lecture3
Lecture3
 
Lecture3
Lecture3Lecture3
Lecture3
 
Lecture1
Lecture1Lecture1
Lecture1
 
Indin report by zubair
Indin report by zubairIndin report by zubair
Indin report by zubair
 
Cyber crime in pakistan by zubair
Cyber crime in pakistan by zubairCyber crime in pakistan by zubair
Cyber crime in pakistan by zubair
 

Recently uploaded

BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 

Recently uploaded (20)

BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 

Lecture5

  • 2. Abstract Data TypeAbstract Data Type  We have looked at four different implementationsWe have looked at four different implementations of the List data structures:of the List data structures:  Using arraysUsing arrays  Singly linked listSingly linked list  Doubly linked listDoubly linked list  Circularly linked list.Circularly linked list.  The interface to the List stayed the same, i.e.,The interface to the List stayed the same, i.e., add(), get(), next(), start(), remove() etc.add(), get(), next(), start(), remove() etc.  The list is thus an abstract data type; we use itThe list is thus an abstract data type; we use it without being concerned with how it iswithout being concerned with how it is implemented.implemented.
  • 3. Abstract Data TypeAbstract Data Type  What we care about is theWhat we care about is the methodsmethods that arethat are available for use with the List ADT.available for use with the List ADT.  We will follow this theme when we develop otherWe will follow this theme when we develop other ADT.ADT.  We willWe will publish the interfacepublish the interface and keep theand keep the freedom to change the implementation of ADTfreedom to change the implementation of ADT without effecting users of the ADT.without effecting users of the ADT.  The C++ classes provide us the ability to createThe C++ classes provide us the ability to create such ADTs.such ADTs.
  • 5. StackStack  Stacks in real life: stack of books, stack ofStacks in real life: stack of books, stack of platesplates  Add new items at the topAdd new items at the top  Remove an item at the topRemove an item at the top  Stack data structure similar to real life:Stack data structure similar to real life: collection of elements arranged in a linearcollection of elements arranged in a linear order.order.  Can only access element at the topCan only access element at the top
  • 6.  AA stackstack is an ordered collection of items intois an ordered collection of items into which new items may bewhich new items may be insertedinserted and fromand from which items may bewhich items may be deleteddeleted at one end only,at one end only, calledcalled toptop of the stack. i.e.of the stack. i.e. deletion/insertiondeletion/insertion cancan only be done fromonly be done from toptop of the stack.of the stack.  TheThe insertinsert operation on a stack is often calledoperation on a stack is often called PushPush operation andoperation and deletedelete operation is calledoperation is called PopPop operation.operation.
  • 7.  Figure showing stack…..Figure showing stack….. B A D C Top of theTop of the StackStack NULLNULL
  • 8.  In aIn a stackstack, the element, the element deleteddeleted from the list isfrom the list is the one mostthe one most recently insertedrecently inserted..  Stack is also referred asStack is also referred as Last-in First-outLast-in First-out i.ei.e LIFOLIFO..  The example of stack is theThe example of stack is the stacks of platesstacks of plates used in cafeterias. The order in which plates areused in cafeterias. The order in which plates are poppedpopped from the stack is the reverse of the orderfrom the stack is the reverse of the order in which they werein which they were pushedpushed onto the stack, sinceonto the stack, since only theonly the top plate is accessibletop plate is accessible..
  • 9.  If anIf an emptyempty stack is popped, we say stackstack is popped, we say stack underflowsunderflows, which is normally an error. and, which is normally an error. and  IfIf toptop of the stack exceedsof the stack exceeds nn, the stack, the stack overflowsoverflows..
  • 10. Stack OperationsStack Operations  Push(X) – insert X as the top element ofPush(X) – insert X as the top element of the stackthe stack  Pop() – remove the top element of thePop() – remove the top element of the stack and return it.stack and return it.  Top() – return the top element withoutTop() – return the top element without removing it from the stack.removing it from the stack.
  • 11. Stack OperationStack Operation  The last element to go into the stack is the firstThe last element to go into the stack is the first to come out:to come out: LIFOLIFO – Last In First Out.– Last In First Out.  What happens if we call pop() and there is noWhat happens if we call pop() and there is no element?element?  Have IsEmpty() boolean function that returnsHave IsEmpty() boolean function that returns true if stack is empty, false otherwise.true if stack is empty, false otherwise.  Throw StackEmpty exception: advanced C++Throw StackEmpty exception: advanced C++ concept.concept.
  • 12.
  • 13. Stack Implementation: ArrayStack Implementation: Array  Worst caseWorst case for insertion and deletion from anfor insertion and deletion from an array when insert and delete from thearray when insert and delete from the beginning:beginning: shift elements to the leftshift elements to the left..  Best caseBest case for insert and delete is at the endfor insert and delete is at the end of the array –of the array – no need to shift any elementsno need to shift any elements..  Implement push() and pop() by inserting andImplement push() and pop() by inserting and deleting at thedeleting at the end of an arrayend of an array
  • 14. Stack Implementation: ArrayStack Implementation: Array
  • 15. Stack using an ArrayStack using an Array  In case of an array, it is possible that theIn case of an array, it is possible that the array may “fill-up” if we push enougharray may “fill-up” if we push enough elements.elements.  Have a boolean functionHave a boolean function IsFull()IsFull() whichwhich returns true if stack (array) is full, falsereturns true if stack (array) is full, false otherwise.otherwise.  We would call this function before callingWe would call this function before calling push(x).push(x).
  • 16. Stack Using Linked ListStack Using Linked List  We canWe can avoid the size limitationavoid the size limitation of a stackof a stack implemented with an array by using aimplemented with an array by using a linked list to hold the stack elements.linked list to hold the stack elements.  As with array, however, we need to decideAs with array, however, we need to decide where to insert elements in the list andwhere to insert elements in the list and where to delete them so that push andwhere to delete them so that push and pop will run the fastest.pop will run the fastest.