SlideShare a Scribd company logo
University of Science &
Technology , Chittagong
Submitted to Submitted by
Sukanta Paul Name: PIKU DAS
Lecturer Roll No: 17010110
Department of CSE Batch No:29th
Graph Traverse
• Graph traversal means visiting every vertex and edge exactly once in a
well-defined order. While using certain graph algorithms, you must
ensure that each vertex of the graph is visited exactly once.
During a traversal , it is important that you track which vertices
have been Visited . The most common way of tracking vertices is to
mark them
Breadth First Search(BFS)
• There are many ways to traverse graphs . BFS is the most commonly
used approach .
BFS is a traversing algorithm where you should start traversing from a
selected node and traverse the graph layer-wise or you should visit
both Children of a node.
Task
• Our task is to write a procedure with input City Denver to City
Washington from the given Link Representation which will find the
shortest stops.
The Link Representation is given below
Link Representation
CITY NO CITY LEFT RIGHT ADJ
1 Atlanta 0 2 12
2 Boston 0 0 1
3 Houston 0 0 14
4 Ney York 3 8 4
5 6
6 0
7 Washington 0 0 10
8 Philadelphia 0 7 6
9 Denver 10 4 8
10 Chicago 1 0 2
Link Representation
ADJ STOP NO PRICE ORIG DEST LINK
1 201 80 2 10 3
2 202 80 10 2 0
3 301 50 2 4 0
4 302 50 4 2 5
5 303 40 4 8 7
6 304 40 8 4 9
7 305 120 4 9 0
8 306 120 9 4 13
9 401 40 8 7 0
10 402 40 7 8 11
Link Representation
ADJ STOP NO PRICE ORIG DEST LINK
11 403 80 7 1 0
12 404 80 1 7 16
13 501 80 9 3 15
14 502 80 3 9 0
15 503 140 9 1 0
16 504 140 1 9 0
17 18
18 19
19 20
20 0
Search Process
• Here we want the minimum number of stops between Denver to
Washington .
• This can be found by using BFS process beginning at Denver and
ending when Washington is encountered.
• From the given Link Representation we can draw a graph which will
notify the path of Denver to Washington , and their adjacency.
Graph
Here
Denver
Chicago New York
Atlanta Houston Philadelphia
Boston Washington
Adjacency
CITY ADJ
Denver New York ,Houston , Atlanta
Chicago Boston
Atlanta Washington , Denver
Boston Chicago , New York
New York Boston , Philadelphia , Denver
Houston Denver
Philadelphia New York ,Washington
Washington Philadelphia ,Atlanta
Steps
• Here we will use a data structure called Queue , where insertion
starts in Rear and deletion in Front.
• We will also keep track the origin of each node using an array called
origin.
• Step 1:
Initially add city Denver to Queue and add null to orig
Front =1 Queue : Denver
Rear =1 Origin : 0
Steps
• Step 2:
Remove the front element Denver and set
Front = Front + 1,
And add t0 Queue the child of Denver.
Front:2 Queue : Denver, New
York ,Houston,
Atlanta
Rear : 4 origin : 0,Denver,Denver
Denver
CITY ADJ
Denver New –York , Houston ,
Atlanta
Chicago Boston
Atlanta Washington , Denver
Boston Chicago , New York
New York Boston , Philadelphia ,
Denver
Houston Denver
Philadelphia New York ,Washington
Washington Philadelphia ,Atlanta
Steps
• Step 3:
Remove the front element New York and set
Front = Front + 2,
And add t0 Queue the child of New
York.
Front: 3 Queue : Denver, New
York ,Houston,
Atlanta , Boston , Philadelphia
Rear : 6 origin : 0,Denver,Denver
Denver , New York ,
New York
CITY ADJ
Denver New –York , Houston ,
Atlanta
Chicago Boston
Atlanta Washington , Denver
Boston Chicago , New York
New York Boston , Philadelphia ,
Denver
Houston Denver
Philadelphia New York ,Washington
Washington Philadelphia ,Atlanta
Steps
As child of Houston, Denver is already in
Queue , we need not add in Queue
Front: 4 Queue : Denver, New
York ,Houston,
Atlanta , Boston,
Philadelphia
Rear : 6 origin:0 , Denver
Denver, Denver, New-
York , New York
CITY ADJ
Denver New –York , Houston ,
Atlanta
Chicago Boston
Atlanta Washington , Denver
Boston Chicago , New York
New York Boston , Philadelphia ,
Denver
Houston Denver
Philadelphia New York ,Washington
Washington Philadelphia ,Atlanta
Steps
Step 4: Remove front element
Atlanta and add the child of Atlanta
Front: 4 Queue : Denver, New
York ,Houston,
Atlanta , Boston,
Philadelphia, Washington
Rear : 6 origin: 0 , Denver
Denver, Denver, New-
York , New York , Atlanta
CITY ADJ
Denver New –York , Houston ,
Atlanta
Chicago Boston
Atlanta Washington , Denver
Boston Chicago , New York
New York Boston , Philadelphia ,
Denver
Houston Denver
Philadelphia New York ,Washington
Washington Philadelphia ,Atlanta
• As Washington is added to the Queue we have to stop.
• We now backtrack from Washington using the array origin to find the
shortest stops
Washington Atlanta Denver
So this is the shortest way to get minimum stops from city Denver
to Washington.
Shortest Path
So
Denver
Chicago New York
Atlanta Houston Philadelphia
Boston Washington
Source Code
#include<stdio.h>
#include<stdlib.h>
#include<assert.h>
#define maxVertices 100
• typedef struct Queue
{
int capacity;
int size;
int front;
int rear;
int *elements;
}Queue;
Queue * CreateQueue(int maxElements)
{
/* Create a Queue */
Queue *Q;
Q = (Queue *)malloc(sizeof(Queue));
/* Initialise its properties */
Q->elements = (int *)malloc(sizeof(int)*maxElements);
Q->size = 0;
Q->capacity = maxElements;
Q->front = 0;
Q->rear = -1;
/* Return the pointer */
return Q;
}
Source Code
void Dequeue(Queue *Q)
{
/* If Queue size is zero then it is empty. So we cannot pop */
if(Q->size==0)
{
printf("Queue is Emptyn");
return;
}
Source Code
else
{
Q->size--;
Q->front++;
/* As we fill elements in circular fashion */
if(Q->front==Q->capacity)
{
Q->front=0;
}
}
return;
}
Source Code
int Front(Queue *Q)
{
if(Q->size==0)
{
printf("Queue is Emptyn");
exit(0);
}
/* Return the element which is at the front*/
return Q->elements[Q->front];
}
Source Code
void Enqueue(Queue *Q,int element)
{
/* If the Queue is full, we cannot push an element into it as there
is no space for it.*/
if(Q->size == Q->capacity)
{
printf("Queue is Fulln");
}
Source Code
• else
{
Q->size++;
Q->rear = Q->rear + 1;
/* As we fill the queue in circular fashion */
if(Q->rear == Q->capacity)
{
Q->rear = 0;
}
/* Insert the element in its rear side */
Q->elements[Q->rear] = element;
}
return;
}
Source Code
void Bfs(int graph[][maxVertices], int *size, int presentVertex,int *visited)
{
visited[presentVertex] = 1;
/* Iterate through all the vertices connected to the presentVertex and perform bfs on those
vertices if they are not visited before */
Queue *Q = CreateQueue(maxVertices);
Enqueue(Q,presentVertex);
while(Q->size)
{
presentVertex = Front(Q);
printf("Now visiting vertex %dn",presentVertex);
Dequeue(Q);
Source Code
int iter;
for(iter=0;iter<size[presentVertex];iter++)
{
if(!visited[graph[presentVertex][iter]])
{
visited[graph[presentVertex][iter]] = 1;
Enqueue(Q,graph[presentVertex][iter]);
}
}
}
return;
}
Source Code
int main()
{ int
graph[maxVertices][maxVertices],size[maxVertices]={0},visited[maxVert
ices]={0};
int vertices,edges,iter;
/* vertices represent number of vertices and edges represent
number of edges in the graph. */
scanf("%d%d",&vertices,&edges);
int vertex1,vertex2;
Source Code
for(iter=0;iter<edges;iter++)
{
scanf("%d%d",&vertex1,&vertex2);
assert(vertex1>=0 && vertex1<vertices);
assert(vertex2>=0 && vertex2<vertices);
graph[vertex1][size[vertex1]++] = vertex2;
}
Source Code
int presentVertex;
for(presentVertex=0;presentVertex<vertices;presentVertex++)
{
if(!visited[presentVertex])
{
Bfs(graph,size,presentVertex,visited);
}
}
return 0;
Rough Notes about the Algorithm
• Input Format: Graph is directed and unweighted. First two integers
must be number of vertices and edges which must be followed by
pairs of vertices which has an edge between them.
• maxVertices represents maximum number of vertices that can be
present in the graph.
• vertices represent number of vertices and edges represent number of
edges in the graph.
Rough Notes about the Algorithm
graph[i][j] represent the weight of edge joining i and j.
size[maxVertices] is initialed to{0}, represents the size of every vertex
i.e. the number of
• edges corresponding to the vertex.
• visited[maxVertices]={0} represents the vertex that have been visited.
Rough Notes about the Algorithm
• The Queue has five properties -
• 1. createQueue function takes argument the maximum number of
elements the Queue can hold, creates a Queue according to it and
returns a pointer to the Queue. It initializes Q- >size to 0, Q->capacity
to maxElements, Q->front to 0 and Q->rear to -1.
• 2. enqueue function - This function takes the pointer to the top of the
queue Q and the item (element) to be inserted as arguments. Check
for the emptiness of queue
Rough Notes about the Algorithm
• a. If Q->size is equal to Q->capacity, we cannot push an element into
Q as there is no space for it.
• b. Else, enqueue an element at the end of Q, increase its size by one.
Increase the value of Q->rear to Q->rear + 1. As we fill the queue in
circular fashion, if Q->rear is equal to Q->capacity make Q->rear = 0.
Now, Insert the element in its rear side Q>elements[Q->rear] =
element.
Rough Notes about the Algorithm
• 3. dequeue function - This function takes the pointer to the top of the
stack S as an argument.
If Q->size is equal to zero, then it is empty. So, we cannot dequeue.
Else, remove an element which is equivalent to incrementing index
of front by one. Decrease the size by 1. As we fill elements in circular
fashion, if Q->front is equal to Q->capacity make Q->front=0.
Rough Notes about the Algorithm
• 4. front function – This function takes the pointer to the top of the
queue Q as an argument and returns the front element of the queue
Q. It first checks if the queue is empty
• (Q->size is equal to zero). If it’s not it returns the element which is at
the front of the queue.
• Q->elements[Q->front]
Breadth first search
Breadth first search

More Related Content

PPT
presentation-225new
PDF
Pistache: A π-Calculus Internal Domain Specific Language for Scala
PDF
Building a Functional Stream in Scala
PPTX
Stack Data Structure
PPT
Data Structures and algorithms using c .ppt
PPTX
DSA_Ques ewoifhjerofhefhehfreofheek.pptx
PPTX
Data structures
PPTX
Unit 3 Stacks and Queues.pptx
presentation-225new
Pistache: A π-Calculus Internal Domain Specific Language for Scala
Building a Functional Stream in Scala
Stack Data Structure
Data Structures and algorithms using c .ppt
DSA_Ques ewoifhjerofhefhehfreofheek.pptx
Data structures
Unit 3 Stacks and Queues.pptx

Similar to Breadth first search (20)

PPTX
08_Queues.pptx showing how que works given vertex
PPTX
The presention is about the queue data structure
PPTX
My lectures circular queue
PPT
Data structures
PPTX
Queue Data Structure
PPTX
DS ppt1.pptx.c programing. Engineering. Data structure
PPTX
DS-UNIT 3 FINAL.pptx
PDF
Ai1.pdf
PPTX
Stack.pptx
DOCX
Data Structures and Algorithm AnalysisSpring 2020 Post Midterm E
PPTX
Queue(lecture8).pptx
PPT
PDF
PPT
queue (1).ppt queue notes and ppt in Data Structures
PPTX
Unit 4 queue
PPTX
Stack and Queue.pptx university exam preparation
PPTX
PPTX
PPTX
Unit ii linear data structures
08_Queues.pptx showing how que works given vertex
The presention is about the queue data structure
My lectures circular queue
Data structures
Queue Data Structure
DS ppt1.pptx.c programing. Engineering. Data structure
DS-UNIT 3 FINAL.pptx
Ai1.pdf
Stack.pptx
Data Structures and Algorithm AnalysisSpring 2020 Post Midterm E
Queue(lecture8).pptx
queue (1).ppt queue notes and ppt in Data Structures
Unit 4 queue
Stack and Queue.pptx university exam preparation
Unit ii linear data structures
Ad

Recently uploaded (20)

PPTX
IBA_Chapter_11_Slides_Final_Accessible.pptx
PDF
Galatica Smart Energy Infrastructure Startup Pitch Deck
PPTX
climate analysis of Dhaka ,Banglades.pptx
PPT
ISS -ESG Data flows What is ESG and HowHow
PDF
Lecture1 pattern recognition............
PDF
BF and FI - Blockchain, fintech and Financial Innovation Lesson 2.pdf
PPTX
Database Infoormation System (DBIS).pptx
PPT
Quality review (1)_presentation of this 21
PPT
Reliability_Chapter_ presentation 1221.5784
PPTX
Introduction to Firewall Analytics - Interfirewall and Transfirewall.pptx
PDF
Mega Projects Data Mega Projects Data
PPTX
Acceptance and paychological effects of mandatory extra coach I classes.pptx
PPTX
AI Strategy room jwfjksfksfjsjsjsjsjfsjfsj
PPTX
DISORDERS OF THE LIVER, GALLBLADDER AND PANCREASE (1).pptx
PPTX
Microsoft-Fabric-Unifying-Analytics-for-the-Modern-Enterprise Solution.pptx
PDF
[EN] Industrial Machine Downtime Prediction
PPTX
oil_refinery_comprehensive_20250804084928 (1).pptx
PDF
Introduction to the R Programming Language
PPTX
mbdjdhjjodule 5-1 rhfhhfjtjjhafbrhfnfbbfnb
IBA_Chapter_11_Slides_Final_Accessible.pptx
Galatica Smart Energy Infrastructure Startup Pitch Deck
climate analysis of Dhaka ,Banglades.pptx
ISS -ESG Data flows What is ESG and HowHow
Lecture1 pattern recognition............
BF and FI - Blockchain, fintech and Financial Innovation Lesson 2.pdf
Database Infoormation System (DBIS).pptx
Quality review (1)_presentation of this 21
Reliability_Chapter_ presentation 1221.5784
Introduction to Firewall Analytics - Interfirewall and Transfirewall.pptx
Mega Projects Data Mega Projects Data
Acceptance and paychological effects of mandatory extra coach I classes.pptx
AI Strategy room jwfjksfksfjsjsjsjsjfsjfsj
DISORDERS OF THE LIVER, GALLBLADDER AND PANCREASE (1).pptx
Microsoft-Fabric-Unifying-Analytics-for-the-Modern-Enterprise Solution.pptx
[EN] Industrial Machine Downtime Prediction
oil_refinery_comprehensive_20250804084928 (1).pptx
Introduction to the R Programming Language
mbdjdhjjodule 5-1 rhfhhfjtjjhafbrhfnfbbfnb
Ad

Breadth first search

  • 1. University of Science & Technology , Chittagong Submitted to Submitted by Sukanta Paul Name: PIKU DAS Lecturer Roll No: 17010110 Department of CSE Batch No:29th
  • 2. Graph Traverse • Graph traversal means visiting every vertex and edge exactly once in a well-defined order. While using certain graph algorithms, you must ensure that each vertex of the graph is visited exactly once. During a traversal , it is important that you track which vertices have been Visited . The most common way of tracking vertices is to mark them
  • 3. Breadth First Search(BFS) • There are many ways to traverse graphs . BFS is the most commonly used approach . BFS is a traversing algorithm where you should start traversing from a selected node and traverse the graph layer-wise or you should visit both Children of a node.
  • 4. Task • Our task is to write a procedure with input City Denver to City Washington from the given Link Representation which will find the shortest stops. The Link Representation is given below
  • 5. Link Representation CITY NO CITY LEFT RIGHT ADJ 1 Atlanta 0 2 12 2 Boston 0 0 1 3 Houston 0 0 14 4 Ney York 3 8 4 5 6 6 0 7 Washington 0 0 10 8 Philadelphia 0 7 6 9 Denver 10 4 8 10 Chicago 1 0 2
  • 6. Link Representation ADJ STOP NO PRICE ORIG DEST LINK 1 201 80 2 10 3 2 202 80 10 2 0 3 301 50 2 4 0 4 302 50 4 2 5 5 303 40 4 8 7 6 304 40 8 4 9 7 305 120 4 9 0 8 306 120 9 4 13 9 401 40 8 7 0 10 402 40 7 8 11
  • 7. Link Representation ADJ STOP NO PRICE ORIG DEST LINK 11 403 80 7 1 0 12 404 80 1 7 16 13 501 80 9 3 15 14 502 80 3 9 0 15 503 140 9 1 0 16 504 140 1 9 0 17 18 18 19 19 20 20 0
  • 8. Search Process • Here we want the minimum number of stops between Denver to Washington . • This can be found by using BFS process beginning at Denver and ending when Washington is encountered. • From the given Link Representation we can draw a graph which will notify the path of Denver to Washington , and their adjacency.
  • 9. Graph Here Denver Chicago New York Atlanta Houston Philadelphia Boston Washington
  • 10. Adjacency CITY ADJ Denver New York ,Houston , Atlanta Chicago Boston Atlanta Washington , Denver Boston Chicago , New York New York Boston , Philadelphia , Denver Houston Denver Philadelphia New York ,Washington Washington Philadelphia ,Atlanta
  • 11. Steps • Here we will use a data structure called Queue , where insertion starts in Rear and deletion in Front. • We will also keep track the origin of each node using an array called origin. • Step 1: Initially add city Denver to Queue and add null to orig Front =1 Queue : Denver Rear =1 Origin : 0
  • 12. Steps • Step 2: Remove the front element Denver and set Front = Front + 1, And add t0 Queue the child of Denver. Front:2 Queue : Denver, New York ,Houston, Atlanta Rear : 4 origin : 0,Denver,Denver Denver CITY ADJ Denver New –York , Houston , Atlanta Chicago Boston Atlanta Washington , Denver Boston Chicago , New York New York Boston , Philadelphia , Denver Houston Denver Philadelphia New York ,Washington Washington Philadelphia ,Atlanta
  • 13. Steps • Step 3: Remove the front element New York and set Front = Front + 2, And add t0 Queue the child of New York. Front: 3 Queue : Denver, New York ,Houston, Atlanta , Boston , Philadelphia Rear : 6 origin : 0,Denver,Denver Denver , New York , New York CITY ADJ Denver New –York , Houston , Atlanta Chicago Boston Atlanta Washington , Denver Boston Chicago , New York New York Boston , Philadelphia , Denver Houston Denver Philadelphia New York ,Washington Washington Philadelphia ,Atlanta
  • 14. Steps As child of Houston, Denver is already in Queue , we need not add in Queue Front: 4 Queue : Denver, New York ,Houston, Atlanta , Boston, Philadelphia Rear : 6 origin:0 , Denver Denver, Denver, New- York , New York CITY ADJ Denver New –York , Houston , Atlanta Chicago Boston Atlanta Washington , Denver Boston Chicago , New York New York Boston , Philadelphia , Denver Houston Denver Philadelphia New York ,Washington Washington Philadelphia ,Atlanta
  • 15. Steps Step 4: Remove front element Atlanta and add the child of Atlanta Front: 4 Queue : Denver, New York ,Houston, Atlanta , Boston, Philadelphia, Washington Rear : 6 origin: 0 , Denver Denver, Denver, New- York , New York , Atlanta CITY ADJ Denver New –York , Houston , Atlanta Chicago Boston Atlanta Washington , Denver Boston Chicago , New York New York Boston , Philadelphia , Denver Houston Denver Philadelphia New York ,Washington Washington Philadelphia ,Atlanta
  • 16. • As Washington is added to the Queue we have to stop. • We now backtrack from Washington using the array origin to find the shortest stops Washington Atlanta Denver So this is the shortest way to get minimum stops from city Denver to Washington.
  • 17. Shortest Path So Denver Chicago New York Atlanta Houston Philadelphia Boston Washington
  • 18. Source Code #include<stdio.h> #include<stdlib.h> #include<assert.h> #define maxVertices 100 • typedef struct Queue { int capacity; int size; int front; int rear; int *elements; }Queue;
  • 19. Queue * CreateQueue(int maxElements) { /* Create a Queue */ Queue *Q; Q = (Queue *)malloc(sizeof(Queue)); /* Initialise its properties */ Q->elements = (int *)malloc(sizeof(int)*maxElements);
  • 20. Q->size = 0; Q->capacity = maxElements; Q->front = 0; Q->rear = -1; /* Return the pointer */ return Q; }
  • 21. Source Code void Dequeue(Queue *Q) { /* If Queue size is zero then it is empty. So we cannot pop */ if(Q->size==0) { printf("Queue is Emptyn"); return; }
  • 22. Source Code else { Q->size--; Q->front++; /* As we fill elements in circular fashion */ if(Q->front==Q->capacity) { Q->front=0; } } return; }
  • 23. Source Code int Front(Queue *Q) { if(Q->size==0) { printf("Queue is Emptyn"); exit(0); } /* Return the element which is at the front*/ return Q->elements[Q->front]; }
  • 24. Source Code void Enqueue(Queue *Q,int element) { /* If the Queue is full, we cannot push an element into it as there is no space for it.*/ if(Q->size == Q->capacity) { printf("Queue is Fulln"); }
  • 25. Source Code • else { Q->size++; Q->rear = Q->rear + 1; /* As we fill the queue in circular fashion */ if(Q->rear == Q->capacity) { Q->rear = 0; } /* Insert the element in its rear side */ Q->elements[Q->rear] = element; } return; }
  • 26. Source Code void Bfs(int graph[][maxVertices], int *size, int presentVertex,int *visited) { visited[presentVertex] = 1; /* Iterate through all the vertices connected to the presentVertex and perform bfs on those vertices if they are not visited before */ Queue *Q = CreateQueue(maxVertices); Enqueue(Q,presentVertex); while(Q->size) { presentVertex = Front(Q); printf("Now visiting vertex %dn",presentVertex); Dequeue(Q);
  • 28. Source Code int main() { int graph[maxVertices][maxVertices],size[maxVertices]={0},visited[maxVert ices]={0}; int vertices,edges,iter; /* vertices represent number of vertices and edges represent number of edges in the graph. */ scanf("%d%d",&vertices,&edges); int vertex1,vertex2;
  • 29. Source Code for(iter=0;iter<edges;iter++) { scanf("%d%d",&vertex1,&vertex2); assert(vertex1>=0 && vertex1<vertices); assert(vertex2>=0 && vertex2<vertices); graph[vertex1][size[vertex1]++] = vertex2; }
  • 31. Rough Notes about the Algorithm • Input Format: Graph is directed and unweighted. First two integers must be number of vertices and edges which must be followed by pairs of vertices which has an edge between them. • maxVertices represents maximum number of vertices that can be present in the graph. • vertices represent number of vertices and edges represent number of edges in the graph.
  • 32. Rough Notes about the Algorithm graph[i][j] represent the weight of edge joining i and j. size[maxVertices] is initialed to{0}, represents the size of every vertex i.e. the number of • edges corresponding to the vertex. • visited[maxVertices]={0} represents the vertex that have been visited.
  • 33. Rough Notes about the Algorithm • The Queue has five properties - • 1. createQueue function takes argument the maximum number of elements the Queue can hold, creates a Queue according to it and returns a pointer to the Queue. It initializes Q- >size to 0, Q->capacity to maxElements, Q->front to 0 and Q->rear to -1. • 2. enqueue function - This function takes the pointer to the top of the queue Q and the item (element) to be inserted as arguments. Check for the emptiness of queue
  • 34. Rough Notes about the Algorithm • a. If Q->size is equal to Q->capacity, we cannot push an element into Q as there is no space for it. • b. Else, enqueue an element at the end of Q, increase its size by one. Increase the value of Q->rear to Q->rear + 1. As we fill the queue in circular fashion, if Q->rear is equal to Q->capacity make Q->rear = 0. Now, Insert the element in its rear side Q>elements[Q->rear] = element.
  • 35. Rough Notes about the Algorithm • 3. dequeue function - This function takes the pointer to the top of the stack S as an argument. If Q->size is equal to zero, then it is empty. So, we cannot dequeue. Else, remove an element which is equivalent to incrementing index of front by one. Decrease the size by 1. As we fill elements in circular fashion, if Q->front is equal to Q->capacity make Q->front=0.
  • 36. Rough Notes about the Algorithm • 4. front function – This function takes the pointer to the top of the queue Q as an argument and returns the front element of the queue Q. It first checks if the queue is empty • (Q->size is equal to zero). If it’s not it returns the element which is at the front of the queue. • Q->elements[Q->front]