SlideShare a Scribd company logo
1 of 64
Data Structures through C++
 Review of Basic Data Structures
 The List ADT
 Stack ADT
 Queue ADT
 Array and Linked Implementations using
Template Classes in C++.
2
 To learn the implementation of list, stack,
and queueADTs in C++ using templates.
3
Array Representation
4
 A data object is a set of instances or values.
 Examples:
 An instance may be primitive or may be
composed of other instances. (Eg: 123, total)
5
 A data structure is a data object together with
the relationships that exist among the
instances and among the individual elements
that compose an instance.
 These relationships are provided by specifying the
operations of interest.
 Most frequently used data objects and their
operations are already implemented in C++ as
primitive data types.
▪ Boolean (bool)
▪ Integer (int)
6
 Each instance of linear list (or ordered list) is an
ordered collection of elements.
 e0, e1, e2, e3, e4, …, en-1
 Index of ei is i.
 n is the list length or size.
 When n = 0, the list is empty.
 When n > 0, e0 is the zeroth element, en-1 is the last.
 e0 comes before e1, e1 comes before e2, and so on.
 Examples:
 List of students in a class in alphabetic order.
 List of percentages of students in decreasing order.
7
 Operations on a Linear List
8
 ADT provides a specification of
 Instances, and
 Operations that are to be performed.
 It is independent of any programming
language.
 All representations of ADT must satisfy the
specification.
9
10
11
 An array is used to store the list of elements.
 If we use one dimensional array, the elements of
the array are accessed as:
 A[0] accesses zeroth element.
 A[1] accesses first element.
 A[n] accesses nth element.
 Elements are mapped to positions in the array.
 location (i) = i is the most natural mapping.
 other ways of mapping are also possible.
12
 Different ways of mapping [5, 2, 4, 8, 1]
13
14
15
Linked Representation
16
 Each element of an instance of a data object
is represented in a cell or a node.
 Each node keeps the location of next node,
called a link or a pointer.
 As each node links to only one other node,
the structure is called as a singly linked list or
a chain.
17
 Removing the third element from the list
involves:
 Locating the second node.
 Linking the second node to the fourth node.
 Similar steps are followed for removing any
element.
18
19
 To insert an element as ith element,
 Find the location on i-1th element.
 Insert the new node after that element.
20
21
 Defines a data type called chainNode for
storing nodes.
22
 Implements a
linear list as
singly linked
list of nodes.
23
Array and Linked List Representation
24
 A stack is a linear list in which insertions and
removals take place at the same end, called
top.The other end is called bottom.
 Insertions are also called as pushes.
 Removals are also called as pops.
 A stack is a LIFO (Last In First Out) list.
25
 Adding element E to the following stack.
26
 Stack of books in a library.
 Stack of CDs.
 Stack of papers in a printer.
 Identify more examples of stacks from real
world?
27
 For implementing function calls.
 For implementing recursive functions.
 For converting infix expression to postfix.
 For evaluating postfix expressions.
 For construction of compilers.
 For depth first search of a graph.
28
29
30
 Can be implemented in two ways:
 derivedArrayStack
▪ Derived from arrayList and stack classes.
▪ Uses the methods of arrayList for performing push and
pop operations.
▪ Efficiency of this class is low due to the usage of
methods of arrayList for push and pop.
 arrayStack
▪ Derived from stack class.
▪ Improves the run-time performance.
31
32
 Better in
performance than
derivedArrayStack
33
34
35
 Left end of the chain or the right end of the
chain can be used as a stack top.
 Using right end as top takes more time.
 So, left end of the stack is used as top.
 Push and pop operations are done at the left
end.
36
 Can be implemented in two ways:
 derivedLinkedStack
▪ Derived from chain and stack classes.
▪ Can be obtained by changing derivedArrayStack.
 linkedStack
▪ Derived from stack.
▪ Improves the run-time performance.
37
38
Array and Linked Representations
39
 A queue is a linear list in which insertions take
place from rear end and deletions take place
from front end.
40
 Railway reservation counters.
 Soda vending machines.
 Normally at all service centers.
 What other example queues can you think of?
41
 For job processing in operating systems.
 For printing documents in printers.
 For breadth-first search of a graph.
 For file handling in distributed file systems.
42
43
44
 ith element may be stored in ith location.
 location(i) = i
 queueFront and queueBack are used to
denote front and rear of the queue.
 queueFront = 0.
 Queue size = queueBack+1.
 queueBack = -1, for empty queue.
45
46
 Insertion
 Increments queueBack by 1.
 Places new element in queue[queueBack].
 Takes O(1) time.
 Deletion
 Shifts all the elements one position to the left.
 Takes O(n) time, where n is number of elements.
 Very time consuming.
47
 We can improve the deletion operation by the
following method:
 Use the equation
▪ location(i) = location(front element) + i.
 Does not require shifting of elements by one
position to the left.
 Increment queueFront by 1 for every deletion.
 Queue is empty, if queueBack < queueFront.
 Takes O(1) time.
48
49
 When the second equation is used, every
deletion increments queueFront by 1.
 This may result in a situation shown below,
where no new elements can be inserted even
when space is available.
50
 One method is
 To shift all the elements to the left end, which
leaves space at the right end allowing insertions.
 Deletion time is O(1).
 Insertion time is O(arrayLength) in worst case.
51
 Another method is
 To insert the elements from the queueFront when
no space is available at the queueBack.
 Both insertion and deletion take O(1) time.
 In this case, the array is viewed as a circle.
 The queue is called as a circular queue.
52
53
 Position 0 is preceded by arrayLength-1.
 When queueBack = arrayLength-1, then the
new element is inserted into position 0.
 Uses the following equation:
 location(i) = (location(front element) + i) %
arrayLength
 Queue is empty iff
 queueFront = queueBack = 0 (initially)
 queueFront = queueBack (otherwise)
54
 Even when Queue is full, the condition
queueFront = queueBack becomes true.
 To avoid this confusion , a queue is never
made full, and the size is doubled whenever
such a situation arises.
55
 Same as arrayStack, except push operation.
56
 May be implemented in the following two
ways:
 But, which is better?
57
 Initial values
 queueFront = queueBack = NULL.
 Boundary value
 queueFront = NULL iff queue is empty.
 All operations require O(1) time.
58
59
60
61
62
 Linear Lists
 Array lists
 Linked lists
 Stacks
 Array implementation
 Linked implementation
 Queues
 Array implementation
 Linked implementation
63
Review of Basic Data Structures
64

More Related Content

What's hot

Stack Data Structure
Stack Data StructureStack Data Structure
Stack Data StructureRabin BK
 
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 Data Structures - Lecture 9 [Stack & Queue using Linked List] Data Structures - Lecture 9 [Stack & Queue using Linked List]
Data Structures - Lecture 9 [Stack & Queue using Linked List]Muhammad Hammad Waseem
 
Stacks & Queues By Ms. Niti Arora
Stacks & Queues By Ms. Niti AroraStacks & Queues By Ms. Niti Arora
Stacks & Queues By Ms. Niti Arorakulachihansraj
 
Fallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queues
Fallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queuesFallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queues
Fallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queuesSnehilKeshari
 
Data Structure -List Stack Queue
Data Structure -List Stack QueueData Structure -List Stack Queue
Data Structure -List Stack Queuesurya pandian
 
Presentation on queue
Presentation on queuePresentation on queue
Presentation on queueRojan Pariyar
 
Data Structure Using C
Data Structure Using CData Structure Using C
Data Structure Using Ccpjcollege
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data StructureSriram Raj
 
Presentation on Elementary data structures
Presentation on Elementary data structuresPresentation on Elementary data structures
Presentation on Elementary data structuresKuber Chandra
 
UNIT II LINEAR DATA STRUCTURES – STACKS, QUEUES
UNIT II 	LINEAR DATA STRUCTURES – STACKS, QUEUES	UNIT II 	LINEAR DATA STRUCTURES – STACKS, QUEUES
UNIT II LINEAR DATA STRUCTURES – STACKS, QUEUES Kathirvel Ayyaswamy
 

What's hot (20)

Queue ppt
Queue pptQueue ppt
Queue ppt
 
Queue
QueueQueue
Queue
 
stack & queue
stack & queuestack & queue
stack & queue
 
Stack and queue
Stack and queueStack and queue
Stack and queue
 
Stack Data Structure
Stack Data StructureStack Data Structure
Stack Data Structure
 
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 Data Structures - Lecture 9 [Stack & Queue using Linked List] Data Structures - Lecture 9 [Stack & Queue using Linked List]
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 
Stacks & Queues By Ms. Niti Arora
Stacks & Queues By Ms. Niti AroraStacks & Queues By Ms. Niti Arora
Stacks & Queues By Ms. Niti Arora
 
Fallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queues
Fallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queuesFallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queues
Fallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queues
 
Data Structure -List Stack Queue
Data Structure -List Stack QueueData Structure -List Stack Queue
Data Structure -List Stack Queue
 
The Stack And Recursion
The Stack And RecursionThe Stack And Recursion
The Stack And Recursion
 
Presentation on queue
Presentation on queuePresentation on queue
Presentation on queue
 
stack presentation
stack presentationstack presentation
stack presentation
 
Stacks and Queue - Data Structures
Stacks and Queue - Data StructuresStacks and Queue - Data Structures
Stacks and Queue - Data Structures
 
Chapter 6 ds
Chapter 6 dsChapter 6 ds
Chapter 6 ds
 
Data Structure Using C
Data Structure Using CData Structure Using C
Data Structure Using C
 
Queues-handouts
Queues-handoutsQueues-handouts
Queues-handouts
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
Presentation on Elementary data structures
Presentation on Elementary data structuresPresentation on Elementary data structures
Presentation on Elementary data structures
 
UNIT II LINEAR DATA STRUCTURES – STACKS, QUEUES
UNIT II 	LINEAR DATA STRUCTURES – STACKS, QUEUES	UNIT II 	LINEAR DATA STRUCTURES – STACKS, QUEUES
UNIT II LINEAR DATA STRUCTURES – STACKS, QUEUES
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
 

Viewers also liked

Ms power point Slideshow
Ms power point SlideshowMs power point Slideshow
Ms power point SlideshowB Priyadarshana
 
Practica de pawer point transiciones animaciones
Practica de pawer point transiciones animaciones Practica de pawer point transiciones animaciones
Practica de pawer point transiciones animaciones Norman Lucero
 
Microsoft Power point
Microsoft Power pointMicrosoft Power point
Microsoft Power pointSeun Ayilara
 
First day - first day of school power point ms powerpoint 1997
First day  - first day of school power point ms powerpoint 1997First day  - first day of school power point ms powerpoint 1997
First day - first day of school power point ms powerpoint 1997anthonymaiorano
 
Remuneration of ceos in india
Remuneration of ceos in indiaRemuneration of ceos in india
Remuneration of ceos in indiaChandan Arora
 
MS Power Point 2007 bab 1
MS Power Point 2007 bab 1MS Power Point 2007 bab 1
MS Power Point 2007 bab 1Timyudhis
 
English 9 - Linear vs. Non-Linear Text
English 9 - Linear vs. Non-Linear TextEnglish 9 - Linear vs. Non-Linear Text
English 9 - Linear vs. Non-Linear TextJuan Miguel Palero
 
2016 ms excel_bm
2016 ms excel_bm2016 ms excel_bm
2016 ms excel_bmRajesh Math
 
Lesson 5 ms office word 2007
Lesson 5   ms office word 2007Lesson 5   ms office word 2007
Lesson 5 ms office word 2007Ahaly
 
MS OFFICE 2010 VS 2007
MS OFFICE 2010 VS 2007MS OFFICE 2010 VS 2007
MS OFFICE 2010 VS 2007Gurpreet Singh
 
Lecture 07 Data Structures - Basic Sorting
Lecture 07 Data Structures - Basic SortingLecture 07 Data Structures - Basic Sorting
Lecture 07 Data Structures - Basic SortingHaitham El-Ghareeb
 
First Day of School PowerPoint
First Day of School PowerPointFirst Day of School PowerPoint
First Day of School PowerPointeshockey
 

Viewers also liked (20)

Ms power point Slideshow
Ms power point SlideshowMs power point Slideshow
Ms power point Slideshow
 
Practica de pawer point transiciones animaciones
Practica de pawer point transiciones animaciones Practica de pawer point transiciones animaciones
Practica de pawer point transiciones animaciones
 
Microsoft Power point
Microsoft Power pointMicrosoft Power point
Microsoft Power point
 
First day - first day of school power point ms powerpoint 1997
First day  - first day of school power point ms powerpoint 1997First day  - first day of school power point ms powerpoint 1997
First day - first day of school power point ms powerpoint 1997
 
Office automation
Office automationOffice automation
Office automation
 
Basic data-structures-v.1.1
Basic data-structures-v.1.1Basic data-structures-v.1.1
Basic data-structures-v.1.1
 
Remuneration of ceos in india
Remuneration of ceos in indiaRemuneration of ceos in india
Remuneration of ceos in india
 
MS Power Point 2007 bab 1
MS Power Point 2007 bab 1MS Power Point 2007 bab 1
MS Power Point 2007 bab 1
 
MS Excel 2nd
MS Excel 2ndMS Excel 2nd
MS Excel 2nd
 
English 9 - Linear vs. Non-Linear Text
English 9 - Linear vs. Non-Linear TextEnglish 9 - Linear vs. Non-Linear Text
English 9 - Linear vs. Non-Linear Text
 
Ms excel
Ms excelMs excel
Ms excel
 
DSA - 2012 - Conclusion
DSA - 2012 - ConclusionDSA - 2012 - Conclusion
DSA - 2012 - Conclusion
 
Vb file
Vb fileVb file
Vb file
 
2016 ms excel_bm
2016 ms excel_bm2016 ms excel_bm
2016 ms excel_bm
 
Sorting
SortingSorting
Sorting
 
Lesson 5 ms office word 2007
Lesson 5   ms office word 2007Lesson 5   ms office word 2007
Lesson 5 ms office word 2007
 
MS OFFICE 2010 VS 2007
MS OFFICE 2010 VS 2007MS OFFICE 2010 VS 2007
MS OFFICE 2010 VS 2007
 
Lecture 07 Data Structures - Basic Sorting
Lecture 07 Data Structures - Basic SortingLecture 07 Data Structures - Basic Sorting
Lecture 07 Data Structures - Basic Sorting
 
Visual Basic 6.0
Visual Basic 6.0Visual Basic 6.0
Visual Basic 6.0
 
First Day of School PowerPoint
First Day of School PowerPointFirst Day of School PowerPoint
First Day of School PowerPoint
 

Similar to Review of basic data structures

unit 5 stack & queue.ppt
unit 5 stack & queue.pptunit 5 stack & queue.ppt
unit 5 stack & queue.pptSeethaDinesh
 
23 stacks-queues-deques
23 stacks-queues-deques23 stacks-queues-deques
23 stacks-queues-dequesRishabh Jindal
 
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,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
 
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
 
Data Structures by Maneesh Boddu
Data Structures by Maneesh BodduData Structures by Maneesh Boddu
Data Structures by Maneesh Boddumaneesh boddu
 
VCE Unit 03vv.pptx
VCE Unit 03vv.pptxVCE Unit 03vv.pptx
VCE Unit 03vv.pptxskilljiolms
 
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbbqueuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbbRAtna29
 
stacks and queues for public
stacks and queues for publicstacks and queues for public
stacks and queues for publiciqbalphy1
 
chapter three ppt.pptx
chapter three ppt.pptxchapter three ppt.pptx
chapter three ppt.pptxselemonGamo
 
basics of queues
basics of queuesbasics of queues
basics of queuessirmanohar
 
هياكلبيانات
هياكلبياناتهياكلبيانات
هياكلبياناتRafal Edward
 
Difference between stack and queue
Difference between stack and queueDifference between stack and queue
Difference between stack and queuePulkitmodi1998
 
chapter-4-data-structure.pdf
chapter-4-data-structure.pdfchapter-4-data-structure.pdf
chapter-4-data-structure.pdfstudy material
 

Similar to Review of basic data structures (20)

unit 5 stack & queue.ppt
unit 5 stack & queue.pptunit 5 stack & queue.ppt
unit 5 stack & queue.ppt
 
23 stacks-queues-deques
23 stacks-queues-deques23 stacks-queues-deques
23 stacks-queues-deques
 
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
 
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
 
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
 
Stacks, Queues, Deques
Stacks, Queues, DequesStacks, Queues, Deques
Stacks, Queues, Deques
 
Data Structures by Maneesh Boddu
Data Structures by Maneesh BodduData Structures by Maneesh Boddu
Data Structures by Maneesh Boddu
 
DS UNIT2QUEUES.pptx
DS UNIT2QUEUES.pptxDS UNIT2QUEUES.pptx
DS UNIT2QUEUES.pptx
 
VCE Unit 03vv.pptx
VCE Unit 03vv.pptxVCE Unit 03vv.pptx
VCE Unit 03vv.pptx
 
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbbqueuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
 
Data structures
Data structuresData structures
Data structures
 
stacks and queues for public
stacks and queues for publicstacks and queues for public
stacks and queues for public
 
chapter three ppt.pptx
chapter three ppt.pptxchapter three ppt.pptx
chapter three ppt.pptx
 
basics of queues
basics of queuesbasics of queues
basics of queues
 
هياكلبيانات
هياكلبياناتهياكلبيانات
هياكلبيانات
 
Difference between stack and queue
Difference between stack and queueDifference between stack and queue
Difference between stack and queue
 
chapter-4-data-structure.pdf
chapter-4-data-structure.pdfchapter-4-data-structure.pdf
chapter-4-data-structure.pdf
 
1.1 ADS data-structure.pdf
1.1 ADS data-structure.pdf1.1 ADS data-structure.pdf
1.1 ADS data-structure.pdf
 
LEC4-DS ALGO.pdf
LEC4-DS  ALGO.pdfLEC4-DS  ALGO.pdf
LEC4-DS ALGO.pdf
 
Data Structure
Data StructureData Structure
Data Structure
 

More from Deepa Rani

Speed controller of dc motor
Speed controller of dc motorSpeed controller of dc motor
Speed controller of dc motorDeepa Rani
 
Foot step power generator
Foot step power generatorFoot step power generator
Foot step power generatorDeepa Rani
 
Crime investigation system
Crime investigation systemCrime investigation system
Crime investigation systemDeepa Rani
 
android content providers
android content providersandroid content providers
android content providersDeepa Rani
 
android sqlite
android sqliteandroid sqlite
android sqliteDeepa Rani
 
android dilaogs
android dilaogsandroid dilaogs
android dilaogsDeepa Rani
 
android layouts
android layoutsandroid layouts
android layoutsDeepa Rani
 
android activity
android activityandroid activity
android activityDeepa Rani
 
android architecture,life cycle,sdk,execution process
android architecture,life cycle,sdk,execution processandroid architecture,life cycle,sdk,execution process
android architecture,life cycle,sdk,execution processDeepa Rani
 
Android the first app - hello world - copy
Android   the first app - hello world - copyAndroid   the first app - hello world - copy
Android the first app - hello world - copyDeepa Rani
 
Android styles and themes
Android   styles and themesAndroid   styles and themes
Android styles and themesDeepa Rani
 
Fabric innovation
Fabric innovationFabric innovation
Fabric innovationDeepa Rani
 
Typical problem
Typical problemTypical problem
Typical problemDeepa Rani
 
straight line
straight line straight line
straight line Deepa Rani
 
Section of solids
Section of solidsSection of solids
Section of solidsDeepa Rani
 

More from Deepa Rani (20)

Speed controller of dc motor
Speed controller of dc motorSpeed controller of dc motor
Speed controller of dc motor
 
Foot step power generator
Foot step power generatorFoot step power generator
Foot step power generator
 
Crime investigation system
Crime investigation systemCrime investigation system
Crime investigation system
 
android content providers
android content providersandroid content providers
android content providers
 
android sqlite
android sqliteandroid sqlite
android sqlite
 
android menus
android menusandroid menus
android menus
 
android dilaogs
android dilaogsandroid dilaogs
android dilaogs
 
android layouts
android layoutsandroid layouts
android layouts
 
android activity
android activityandroid activity
android activity
 
android architecture,life cycle,sdk,execution process
android architecture,life cycle,sdk,execution processandroid architecture,life cycle,sdk,execution process
android architecture,life cycle,sdk,execution process
 
Android the first app - hello world - copy
Android   the first app - hello world - copyAndroid   the first app - hello world - copy
Android the first app - hello world - copy
 
Android styles and themes
Android   styles and themesAndroid   styles and themes
Android styles and themes
 
Blue Brain
Blue BrainBlue Brain
Blue Brain
 
Tcp
TcpTcp
Tcp
 
Dc machiness
Dc machinessDc machiness
Dc machiness
 
Maddy android
Maddy androidMaddy android
Maddy android
 
Fabric innovation
Fabric innovationFabric innovation
Fabric innovation
 
Typical problem
Typical problemTypical problem
Typical problem
 
straight line
straight line straight line
straight line
 
Section of solids
Section of solidsSection of solids
Section of solids
 

Recently uploaded

Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...anjaliyadav012327
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
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
 
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
 
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
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
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
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxShobhayan Kirtania
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
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
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 

Recently uploaded (20)

INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
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
 
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
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
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
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
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
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 

Review of basic data structures

  • 2.  Review of Basic Data Structures  The List ADT  Stack ADT  Queue ADT  Array and Linked Implementations using Template Classes in C++. 2
  • 3.  To learn the implementation of list, stack, and queueADTs in C++ using templates. 3
  • 5.  A data object is a set of instances or values.  Examples:  An instance may be primitive or may be composed of other instances. (Eg: 123, total) 5
  • 6.  A data structure is a data object together with the relationships that exist among the instances and among the individual elements that compose an instance.  These relationships are provided by specifying the operations of interest.  Most frequently used data objects and their operations are already implemented in C++ as primitive data types. ▪ Boolean (bool) ▪ Integer (int) 6
  • 7.  Each instance of linear list (or ordered list) is an ordered collection of elements.  e0, e1, e2, e3, e4, …, en-1  Index of ei is i.  n is the list length or size.  When n = 0, the list is empty.  When n > 0, e0 is the zeroth element, en-1 is the last.  e0 comes before e1, e1 comes before e2, and so on.  Examples:  List of students in a class in alphabetic order.  List of percentages of students in decreasing order. 7
  • 8.  Operations on a Linear List 8
  • 9.  ADT provides a specification of  Instances, and  Operations that are to be performed.  It is independent of any programming language.  All representations of ADT must satisfy the specification. 9
  • 10. 10
  • 11. 11
  • 12.  An array is used to store the list of elements.  If we use one dimensional array, the elements of the array are accessed as:  A[0] accesses zeroth element.  A[1] accesses first element.  A[n] accesses nth element.  Elements are mapped to positions in the array.  location (i) = i is the most natural mapping.  other ways of mapping are also possible. 12
  • 13.  Different ways of mapping [5, 2, 4, 8, 1] 13
  • 14. 14
  • 15. 15
  • 17.  Each element of an instance of a data object is represented in a cell or a node.  Each node keeps the location of next node, called a link or a pointer.  As each node links to only one other node, the structure is called as a singly linked list or a chain. 17
  • 18.  Removing the third element from the list involves:  Locating the second node.  Linking the second node to the fourth node.  Similar steps are followed for removing any element. 18
  • 19. 19
  • 20.  To insert an element as ith element,  Find the location on i-1th element.  Insert the new node after that element. 20
  • 21. 21
  • 22.  Defines a data type called chainNode for storing nodes. 22
  • 23.  Implements a linear list as singly linked list of nodes. 23
  • 24. Array and Linked List Representation 24
  • 25.  A stack is a linear list in which insertions and removals take place at the same end, called top.The other end is called bottom.  Insertions are also called as pushes.  Removals are also called as pops.  A stack is a LIFO (Last In First Out) list. 25
  • 26.  Adding element E to the following stack. 26
  • 27.  Stack of books in a library.  Stack of CDs.  Stack of papers in a printer.  Identify more examples of stacks from real world? 27
  • 28.  For implementing function calls.  For implementing recursive functions.  For converting infix expression to postfix.  For evaluating postfix expressions.  For construction of compilers.  For depth first search of a graph. 28
  • 29. 29
  • 30. 30
  • 31.  Can be implemented in two ways:  derivedArrayStack ▪ Derived from arrayList and stack classes. ▪ Uses the methods of arrayList for performing push and pop operations. ▪ Efficiency of this class is low due to the usage of methods of arrayList for push and pop.  arrayStack ▪ Derived from stack class. ▪ Improves the run-time performance. 31
  • 32. 32
  • 33.  Better in performance than derivedArrayStack 33
  • 34. 34
  • 35. 35
  • 36.  Left end of the chain or the right end of the chain can be used as a stack top.  Using right end as top takes more time.  So, left end of the stack is used as top.  Push and pop operations are done at the left end. 36
  • 37.  Can be implemented in two ways:  derivedLinkedStack ▪ Derived from chain and stack classes. ▪ Can be obtained by changing derivedArrayStack.  linkedStack ▪ Derived from stack. ▪ Improves the run-time performance. 37
  • 38. 38
  • 39. Array and Linked Representations 39
  • 40.  A queue is a linear list in which insertions take place from rear end and deletions take place from front end. 40
  • 41.  Railway reservation counters.  Soda vending machines.  Normally at all service centers.  What other example queues can you think of? 41
  • 42.  For job processing in operating systems.  For printing documents in printers.  For breadth-first search of a graph.  For file handling in distributed file systems. 42
  • 43. 43
  • 44. 44
  • 45.  ith element may be stored in ith location.  location(i) = i  queueFront and queueBack are used to denote front and rear of the queue.  queueFront = 0.  Queue size = queueBack+1.  queueBack = -1, for empty queue. 45
  • 46. 46
  • 47.  Insertion  Increments queueBack by 1.  Places new element in queue[queueBack].  Takes O(1) time.  Deletion  Shifts all the elements one position to the left.  Takes O(n) time, where n is number of elements.  Very time consuming. 47
  • 48.  We can improve the deletion operation by the following method:  Use the equation ▪ location(i) = location(front element) + i.  Does not require shifting of elements by one position to the left.  Increment queueFront by 1 for every deletion.  Queue is empty, if queueBack < queueFront.  Takes O(1) time. 48
  • 49. 49
  • 50.  When the second equation is used, every deletion increments queueFront by 1.  This may result in a situation shown below, where no new elements can be inserted even when space is available. 50
  • 51.  One method is  To shift all the elements to the left end, which leaves space at the right end allowing insertions.  Deletion time is O(1).  Insertion time is O(arrayLength) in worst case. 51
  • 52.  Another method is  To insert the elements from the queueFront when no space is available at the queueBack.  Both insertion and deletion take O(1) time.  In this case, the array is viewed as a circle.  The queue is called as a circular queue. 52
  • 53. 53
  • 54.  Position 0 is preceded by arrayLength-1.  When queueBack = arrayLength-1, then the new element is inserted into position 0.  Uses the following equation:  location(i) = (location(front element) + i) % arrayLength  Queue is empty iff  queueFront = queueBack = 0 (initially)  queueFront = queueBack (otherwise) 54
  • 55.  Even when Queue is full, the condition queueFront = queueBack becomes true.  To avoid this confusion , a queue is never made full, and the size is doubled whenever such a situation arises. 55
  • 56.  Same as arrayStack, except push operation. 56
  • 57.  May be implemented in the following two ways:  But, which is better? 57
  • 58.  Initial values  queueFront = queueBack = NULL.  Boundary value  queueFront = NULL iff queue is empty.  All operations require O(1) time. 58
  • 59. 59
  • 60. 60
  • 61. 61
  • 62. 62
  • 63.  Linear Lists  Array lists  Linked lists  Stacks  Array implementation  Linked implementation  Queues  Array implementation  Linked implementation 63
  • 64. Review of Basic Data Structures 64