You are on page 1of 16

SRI RAMAKRISHNA ENGINEERING COLLEGE

[Educational Service : SNR Sons Charitable Trust]


[Autonomous Institution, Accredited by NAAC with ‘A’ Grade]
[Approved by AICTE and Permanently Affiliated to Anna University, Chennai]
[ISO 9001:2015 Certified and all Eligible Programmes Accredited by NBA]
VATTAMALAIPALAYAM, N.G.G.O. COLONY POST, COIMBATORE – 641 022.

Department of Information Technology

16IT207 – Data Structures and Algorithms

Presentation by
Mrs. N. Saranya
Assistant Professor (Sr.Gr)/ IT
Overview
Recap
Stack ADT
Queue ADT
Array Implementation of stack
 Array Implementation of queue

19/05/21 16IT207 - DATA STRUCTURES & ALGORITHMS - N. SARANYA 2


ADT
 Abstract data type(ADT) is a set of operations

 They are mathematical abstractions without any mention of it’s


implementation
 This can be viewed as an extension of modular design

 There is no rule stating the operations of each ADT it’s a design


decision
 Example: List ADT, Stack ADT and Queue ADT

19/05/21 16IT207 - DATA STRUCTURES & ALGORITHMS - N. SARANYA 3


List ADT
 List is an ordered sequence of data items from A 1, A2, A3, A4 ……. AN

 List from A1, A2, A3, A4 ……. AN is a list of size N

 Size of an empty list is 0

 Ai+1 Succeeds Ai

 Ai-1 Preceeds Ai

 Position of Ai is I

 First element is A1

 Last element is AN

19/05/21 16IT207 - DATA STRUCTURES & ALGORITHMS - N. SARANYA 4


Operations
 Insert

 Delete

 Find

 Position based insertion and deletion

 Find Kth element

 Print the list

19/05/21 16IT207 - DATA STRUCTURES & ALGORITHMS - N. SARANYA 5


List implementation using arrays
 List creation by initializing array of size 10

A[0] A[9]

 Insert element into the list


10,20,30

10 20 30

A[0] A[1] A[2]

19/05/21 16IT207 - DATA STRUCTURES & ALGORITHMS - N. SARANYA 6


Position Based Insertion
 Insert in specific position

10 20 30

A[0] A[1] A[2]

10 50 20 30

A[0] A[1] A[2] A[3]

19/05/21 16IT207 - DATA STRUCTURES & ALGORITHMS - N. SARANYA 7


Deletion
Delete element into the list

10 20 30

A[0] A[1] A[2]

10 20

A[0] A[1]

19/05/21 16IT207 - DATA STRUCTURES & ALGORITHMS - N. SARANYA 8


Position Based Deletion
 Delete based on position

10 20 30 40

A[0] A[1] A[2] A[3]

10 30 40

A[0] A[1] A[2]

19/05/21 16IT207 - DATA STRUCTURES & ALGORITHMS - N. SARANYA 9


Stack ADT
 Stack is a list with the restriction that insertion and deletion can be
performed in only one position namely the end of the list called the top
 It is also known as LIFO list
10,20,30,40,50

19/05/21 16IT207 - DATA STRUCTURES & ALGORITHMS - N. SARANYA 10


Operations
 Push()-insertion

 Pop() - deletion

 Peek()- topmost element

 Display

19/05/21 16IT207 - DATA STRUCTURES & ALGORITHMS - N. SARANYA 11


Push()
 Consider stack of size 4. Insert the elements 10,20,30,40,50

top 40
top 30 30 Stack full
top can’t insert
20 20 20 element 50
top 10 10 10 10

 Check for overflow


 If we try to insert element into the full stack then the condition is called stack overflow
 Increment the top
 Insert the elements

19/05/21 16IT207 - DATA STRUCTURES & ALGORITHMS - N. SARANYA 12


Pop()
 Consider stack of size 4. with element 10,20

Don’t have
top element to
20 remove
10 top
10

Top=-1
 Check for underflow
 If we try to delete element from the empty stack then the condition is called stack underflow
 Display the elements
 Decrement the top

19/05/21 16IT207 - DATA STRUCTURES & ALGORITHMS - N. SARANYA 13


Peek() and Display
 Peek()- topmost element
 Display the topmost element of stack

 Display()
 Display all the elements of stack

19/05/21 16IT207 - DATA STRUCTURES & ALGORITHMS - N. SARANYA 14


Queue ADT
 Queue is a list were insertion is done at one end and deletion is
performed at other end
 Insertion end is called rear

 Deletion end is called front

 It is also known as FIFO list


10,20,30,40,50

19/05/21 16IT207 - DATA STRUCTURES & ALGORITHMS - N. SARANYA 15


19/05/21 16IT207 - DATA STRUCTURES & ALGORITHMS - N. SARANYA 16

You might also like