SlideShare a Scribd company logo
Data Structures and Algorithms
Manish Aryal
Lecture 04
Data Structures and Algorithms
◼ Queue
▪ An ordered list in which data can be added from an end
called as rear and removed from other end called as front
▪ FIFO
◼ Operations
▪ Insert/Enqueue: addition of data from rear
▪ Delete/Dequeue: remove data from front
◼ Linear, Circular and Priority Queue
2
Key Learning Points
Data Structures and Algorithms
◼ Rear points to the topmost and Front points to bottom most element of queue.
[True/False]
◼ Queue is Last-in-Last-Out list. [True/False]
◼ If we insert the elements A, B, C, D, in that order, in a Queue then ……. is the
first element we delete from the queue
◼ In a circular queue, after every insert operation rear is updated as
a. rear++ b. rear = (rear -1) % MAXQSIZE c. rear= front d. rear = (rear +1) % MAXQSIZE
◼ The condition in which we have rear=front in a Queue is called as
a. House full b. Don’t Care c. Full d. Empty
◼ An element with …………….. is processed before elements with …………. in a
priority queue.
3
Teach to Learn
◼ Static and Dynamic List Structures
◼ Array Implementation of List
◼ Queues as list
4
List
Contents
◼ After completion of this chapter you will be able to:
▪ Define list as a Data Structure
▪ Define static and dynamic list
▪ Compare static and dynamic list
▪ Implement the list in form of an array
▪ Implement Queue as a list
▪ Attempt 6 marks’ question in final exams
5
List
Objectives
◼ A linear list is a data structure each element of which
has a unique successor:
◼ Array is the simplest linear list
◼ There are two types of list:
▪ General list
▪ Restricted list
6
List
Definition
element 1 element 2 element 3
◼ General list:
▪ no restrictions on where data can be inserted/deleted, and on
which operations can be used on the list
▪ Random list:there is no ordering on data
▪ Ordered list:data are arranged according to a key
◼ Restricted list:
▪ data can be inserted/deleted and operations are performed only at
the ends of the list
▪ FIFO (First-In-First-Out): queue
▪ LIFO (Last-In-First-Out): stack
7
List
Definition {Contd..}
◼ Insertion
▪ The process of adding data to the list
◼ Deletion
▪ Is the process of searching and removing data from the
list
◼ Retrieval
▪ also requires list searching, but does not change the
contents of the list.
◼ Traversal
▪ is retrieval of all elements in sequence
8
List
Operations
◼ Insertion
▪ Random list: insertion can be made at the beginning, the middle or
the end of the list.
▪ Ordered list: the data must be inserted so that the ordering of the
list is maintained.
▪ Array requires physical shifting
9
List
Operations {Contd..}
10 20 30
25
10 20 25 30
◼ Deletion
▪ Deletion from a general list requires searching the list in
order to locate the data being deleted.
▪ Array requires physical shifting after the data is deleted.
10
List
Operations {Contd..}
25
10 20 30
10 20 25 30
◼ void menu()
◼ void create();
◼ void insert(int, int);
◼ void del(int);
◼ void find(int);
◼ void display();
◼ int isfull();
◼ int isempty();
11
List
Implementation using Array
◼ int menu()
int ch;
clrscr();
printf("nt LIST Implementation using Arrays");
printf("nt1. Creatent2. Insertnt3. Deletent4.
Countnt5. Findnt6. Displaynt7. ExitnnEnter Your
Choice:");
scanf("%d",&ch);
printf("nn");
return ch;
12
List
Implementation using Array {Contd..}
◼ void create()
int element;
int flag=1;
while(flag==1)
{
printf("nEnter an element:");
scanf("%d", &element);
l.list[l.length]=element;
l.length++;
printf("nPress '1' to insert another element!n");
scanf("%d",&flag);
}
13
List
Implementation using Array {Contd..}
◼ void insert(int, int)
int i;
if(pos==0)
{
printf("nnCannot insert at zeroth position.");
getch();
return;
}
if(pos-1>l.length)
{
printf("nnOnly %d elements exit. Cannot insert at %d
position",l.length,pos);
printf("nPress any key to continue..");
getch();
}
14
List
Implementation using Array {Contd..}
else
{
for(i=l.length;i>=pos-1;i--)
{
l.list[i+1]=l.list[i];
}
l.list[pos-1]=element;
l.length++;
}
15
List
Implementation using Array {Contd..}
◼ void del(int)
int i;
if(pos==0)
{
printf("nn No Element at zerothposition");
getch();
return;
}
if(pos>l.length)
{
printf("nnOnly%d elements. Cannot delete element at %d position.", l.length,
pos);
printf("Press any key to continue..");
return;
}
for(i=pos;i<l.length;i++)
{
l.list[i]=l.list[i+1];
}
l.length--;
16
List
Implementation using Array {Contd..}
◼ Void count()
printf("nEnter number ofelements in the list is %d",l.length);
printf("nPress any key to continue..");
17
List
Implementation using Array {Contd..}
◼ void find(int)
int i;
int flag=1;
for(i=0;i<l.length;i++)
{
if(l.list[i]==element)
{
printf("%d exists at %d position", element, i+1);
flag=0;
printf("nPress any key to continue..");
getch();
break;
}
}
if(flag==1)
{
printf("%d not found.nPress any key to continue..", element);
getch();
}
18
List
Implementation using Array {Contd..}
◼ void display()
int i;
for(i=0;i<l.length;i++)
{
printf("nElement: %dtPosition: %d",l.list[i], i+1);
}
printf("nPress any key to continue...");
getch();
19
List
Implementation using Array {Contd..}
◼ int isfull()
if(l.length==MAXNODE)
return(1);
else
return(0);
20
List
Implementation using Array {Contd..}
◼ int isempty()
if(l.length==0)
return(1);
else
return(0);
21
List
Implementation using Array {Contd..}
Next Lecture:
Linked List
Thank You.

More Related Content

PPTX
GDSC MPSTME Shirpur DSA Day 1.pptx
PPTX
Review of basic data structures
PPT
Lecture2
DOCX
List - Operations and Implementation
DOCX
CDS artificial intelligence and Machine.docx
PPTX
ds bridge.pptx
PPTX
8.DATA STRUCTURES UNIT 1 AND 2 CS3301PPT.pptx
PPTX
DATA STRUCTURE AND ALGORITHM with linked list
GDSC MPSTME Shirpur DSA Day 1.pptx
Review of basic data structures
Lecture2
List - Operations and Implementation
CDS artificial intelligence and Machine.docx
ds bridge.pptx
8.DATA STRUCTURES UNIT 1 AND 2 CS3301PPT.pptx
DATA STRUCTURE AND ALGORITHM with linked list

Similar to 3. List .pdf (20)

PPTX
TSAT Presentation1.pptx
PPT
Data Structures and algorithms using c .ppt
PPTX
Data structures and algorithms
PPTX
Data_structure.pptx
PPTX
Data structures and Algorithm analysis_Lecture 2.pptx
PPTX
EC2311 – Data Structures and C Programming
PDF
4 chapter3 list_stackqueuepart1
PPTX
Data structure
PPT
Data Structures by Maneesh Boddu
PPTX
introduction_dst.pptx
PPT
Data structures
PPT
lecture 02.2.ppt
PPTX
Bsc cs ii dfs u-2 linklist,stack,queue
PPTX
this is a very important presentation that may be use for studding
PPTX
Mca ii dfs u-3 linklist,stack,queue
PPTX
Data structures - unit 1
PPTX
General Data structures
PPTX
Data structure , stack , queue
PPTX
DSA_Ques ewoifhjerofhefhehfreofheek.pptx
PDF
DS Complete notes for Computer science and Engineering
TSAT Presentation1.pptx
Data Structures and algorithms using c .ppt
Data structures and algorithms
Data_structure.pptx
Data structures and Algorithm analysis_Lecture 2.pptx
EC2311 – Data Structures and C Programming
4 chapter3 list_stackqueuepart1
Data structure
Data Structures by Maneesh Boddu
introduction_dst.pptx
Data structures
lecture 02.2.ppt
Bsc cs ii dfs u-2 linklist,stack,queue
this is a very important presentation that may be use for studding
Mca ii dfs u-3 linklist,stack,queue
Data structures - unit 1
General Data structures
Data structure , stack , queue
DSA_Ques ewoifhjerofhefhehfreofheek.pptx
DS Complete notes for Computer science and Engineering
Ad

More from Yatru Harsha Hiski (12)

PDF
Unit-10 Graphs .pdf
PDF
Unit-9 Searching .pdf
PDF
4. Linked list .pdf
PPTX
MIC3_The Intel 8086 .pptx
PDF
ch14_1 RISC Processors .pdf
PDF
ch16_1 Memory System Design .pdf
PDF
PRINCIPAL COMPONENTS (PCA) AND EXPLORATORY FACTOR ANALYSIS (EFA) WITH SPSS.pdf
PPTX
Fault Tolerance in Distributed System
PDF
Dimensionality Reduction Principal Component Analysis (PCA).pdf
PDF
K-means slides, K-means annotated, GMM slides, GMM annotated.pdf
PDF
1. Instruction set of 8085 .pdf
PDF
6. Perspective Projection .pdf
Unit-10 Graphs .pdf
Unit-9 Searching .pdf
4. Linked list .pdf
MIC3_The Intel 8086 .pptx
ch14_1 RISC Processors .pdf
ch16_1 Memory System Design .pdf
PRINCIPAL COMPONENTS (PCA) AND EXPLORATORY FACTOR ANALYSIS (EFA) WITH SPSS.pdf
Fault Tolerance in Distributed System
Dimensionality Reduction Principal Component Analysis (PCA).pdf
K-means slides, K-means annotated, GMM slides, GMM annotated.pdf
1. Instruction set of 8085 .pdf
6. Perspective Projection .pdf
Ad

Recently uploaded (20)

PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
DOCX
573137875-Attendance-Management-System-original
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PPTX
Welding lecture in detail for understanding
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PPTX
additive manufacturing of ss316l using mig welding
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PDF
PPT on Performance Review to get promotions
PPTX
web development for engineering and engineering
PPT
Project quality management in manufacturing
PDF
Digital Logic Computer Design lecture notes
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PPTX
OOP with Java - Java Introduction (Basics)
PPTX
CH1 Production IntroductoryConcepts.pptx
PPTX
Geodesy 1.pptx...............................................
PDF
Well-logging-methods_new................
Embodied AI: Ushering in the Next Era of Intelligent Systems
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
Operating System & Kernel Study Guide-1 - converted.pdf
573137875-Attendance-Management-System-original
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
Welding lecture in detail for understanding
UNIT-1 - COAL BASED THERMAL POWER PLANTS
additive manufacturing of ss316l using mig welding
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PPT on Performance Review to get promotions
web development for engineering and engineering
Project quality management in manufacturing
Digital Logic Computer Design lecture notes
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
Model Code of Practice - Construction Work - 21102022 .pdf
OOP with Java - Java Introduction (Basics)
CH1 Production IntroductoryConcepts.pptx
Geodesy 1.pptx...............................................
Well-logging-methods_new................

3. List .pdf

  • 1. Data Structures and Algorithms Manish Aryal Lecture 04
  • 2. Data Structures and Algorithms ◼ Queue ▪ An ordered list in which data can be added from an end called as rear and removed from other end called as front ▪ FIFO ◼ Operations ▪ Insert/Enqueue: addition of data from rear ▪ Delete/Dequeue: remove data from front ◼ Linear, Circular and Priority Queue 2 Key Learning Points
  • 3. Data Structures and Algorithms ◼ Rear points to the topmost and Front points to bottom most element of queue. [True/False] ◼ Queue is Last-in-Last-Out list. [True/False] ◼ If we insert the elements A, B, C, D, in that order, in a Queue then ……. is the first element we delete from the queue ◼ In a circular queue, after every insert operation rear is updated as a. rear++ b. rear = (rear -1) % MAXQSIZE c. rear= front d. rear = (rear +1) % MAXQSIZE ◼ The condition in which we have rear=front in a Queue is called as a. House full b. Don’t Care c. Full d. Empty ◼ An element with …………….. is processed before elements with …………. in a priority queue. 3 Teach to Learn
  • 4. ◼ Static and Dynamic List Structures ◼ Array Implementation of List ◼ Queues as list 4 List Contents
  • 5. ◼ After completion of this chapter you will be able to: ▪ Define list as a Data Structure ▪ Define static and dynamic list ▪ Compare static and dynamic list ▪ Implement the list in form of an array ▪ Implement Queue as a list ▪ Attempt 6 marks’ question in final exams 5 List Objectives
  • 6. ◼ A linear list is a data structure each element of which has a unique successor: ◼ Array is the simplest linear list ◼ There are two types of list: ▪ General list ▪ Restricted list 6 List Definition element 1 element 2 element 3
  • 7. ◼ General list: ▪ no restrictions on where data can be inserted/deleted, and on which operations can be used on the list ▪ Random list:there is no ordering on data ▪ Ordered list:data are arranged according to a key ◼ Restricted list: ▪ data can be inserted/deleted and operations are performed only at the ends of the list ▪ FIFO (First-In-First-Out): queue ▪ LIFO (Last-In-First-Out): stack 7 List Definition {Contd..}
  • 8. ◼ Insertion ▪ The process of adding data to the list ◼ Deletion ▪ Is the process of searching and removing data from the list ◼ Retrieval ▪ also requires list searching, but does not change the contents of the list. ◼ Traversal ▪ is retrieval of all elements in sequence 8 List Operations
  • 9. ◼ Insertion ▪ Random list: insertion can be made at the beginning, the middle or the end of the list. ▪ Ordered list: the data must be inserted so that the ordering of the list is maintained. ▪ Array requires physical shifting 9 List Operations {Contd..} 10 20 30 25 10 20 25 30
  • 10. ◼ Deletion ▪ Deletion from a general list requires searching the list in order to locate the data being deleted. ▪ Array requires physical shifting after the data is deleted. 10 List Operations {Contd..} 25 10 20 30 10 20 25 30
  • 11. ◼ void menu() ◼ void create(); ◼ void insert(int, int); ◼ void del(int); ◼ void find(int); ◼ void display(); ◼ int isfull(); ◼ int isempty(); 11 List Implementation using Array
  • 12. ◼ int menu() int ch; clrscr(); printf("nt LIST Implementation using Arrays"); printf("nt1. Creatent2. Insertnt3. Deletent4. Countnt5. Findnt6. Displaynt7. ExitnnEnter Your Choice:"); scanf("%d",&ch); printf("nn"); return ch; 12 List Implementation using Array {Contd..}
  • 13. ◼ void create() int element; int flag=1; while(flag==1) { printf("nEnter an element:"); scanf("%d", &element); l.list[l.length]=element; l.length++; printf("nPress '1' to insert another element!n"); scanf("%d",&flag); } 13 List Implementation using Array {Contd..}
  • 14. ◼ void insert(int, int) int i; if(pos==0) { printf("nnCannot insert at zeroth position."); getch(); return; } if(pos-1>l.length) { printf("nnOnly %d elements exit. Cannot insert at %d position",l.length,pos); printf("nPress any key to continue.."); getch(); } 14 List Implementation using Array {Contd..}
  • 16. ◼ void del(int) int i; if(pos==0) { printf("nn No Element at zerothposition"); getch(); return; } if(pos>l.length) { printf("nnOnly%d elements. Cannot delete element at %d position.", l.length, pos); printf("Press any key to continue.."); return; } for(i=pos;i<l.length;i++) { l.list[i]=l.list[i+1]; } l.length--; 16 List Implementation using Array {Contd..}
  • 17. ◼ Void count() printf("nEnter number ofelements in the list is %d",l.length); printf("nPress any key to continue.."); 17 List Implementation using Array {Contd..}
  • 18. ◼ void find(int) int i; int flag=1; for(i=0;i<l.length;i++) { if(l.list[i]==element) { printf("%d exists at %d position", element, i+1); flag=0; printf("nPress any key to continue.."); getch(); break; } } if(flag==1) { printf("%d not found.nPress any key to continue..", element); getch(); } 18 List Implementation using Array {Contd..}
  • 19. ◼ void display() int i; for(i=0;i<l.length;i++) { printf("nElement: %dtPosition: %d",l.list[i], i+1); } printf("nPress any key to continue..."); getch(); 19 List Implementation using Array {Contd..}