DSA - Queue Flashcards

1
Q

what is DS

A

way to store and organize data

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

is Queue linear DS

A

yea queue is linear data str

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

is queue abstract DS

A

yes, queue is an abstract DS

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

what is FIFO

A

first in first out

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

what are operation on queue

A

enqueue, dequeue

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

what is enqueue

A

inserting node from rear end is known as enquque

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

what is dequeue

A

deleting node from front end part is known as dequeue

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

what are front and rear

A

front and rear are two variables

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

what does front part is used for

A

front part is used for deleting operation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

what is use of rear variable

A

we use rear variable to add data into the queue

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

from which node we can insert data

A

we can insert data from rear end

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

from which part we can delete data in queue

A

we can delete data from front part in queue

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

suppose there are three variables, 2, 3, 4 where would front and rear point

A

front will point to 2 and
rear will point to 4, end of queue

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

suppose there are three variables, 2, 3, 4 and now you want to insert data into queue, from where will you insert it

A

we can insert data into queue from rear end, which is pointing to last element

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

whats the first step when inserting / enqueing element into queue

A

first we increment the variable, rear++
insert data => second step

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

what is LILO

A

LILO is last in last out

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

do we have to pass parameter into enqueue()

A

yes we have to pass data, we are inserting into enqueue() function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

do we have to pass anything into dequeue() function

A

no we dont have to pass anython into dequeue()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

why we dont pass anything into dequeue()

A

by default the element is getting deleted is from front part

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

what is front() or peek() function

A

it gives us first element without deleting the element

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

isFull()

A

this function will return true if queue is empty, else it will return false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

isEmpty()

A

if queue is empty this function will return true, else this function will return false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

for which values we initialize front and rear

A

we initialize front and rear to -1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
which variable we increment while doing enqueue()
we increment rear variable while insert elements
26
which variable stays at the same position while inserting element to queue
front stays at its place while incrementing
27
what happens when we dequeue an element
we increment the value value of front
28
peek() returns what
peek() function returns position where front is pointintg
29
when front and rear become equal
when there is only one element, then the front and rear points to the same position
30
what is meaning of #define n 5
define N, makes global variable and add 5 to it
30
what is first thing we check into enqueue() function
first thing we check in enqueue() function, is that is queue is overflow or not overflow means, is queue is full or not
31
what are applications of queue
serving request from single source in OS processes are placed into queue
32
why we need to pass int x, to enqueue() function
into x, we are going to send information or data
32
how to take array for queue
int queue[5]; we can use int queue[N];
32
take two variables and initialize them to -1
int front = -1; int rear = -1;
33
do we need to declare front and rear globally
yes, we have to declare front and rear globally
33
define enqueue() function
void enqueue(int x) {}
34
how to check overflow of queue
if(rear == N - 1) { printf("overflow or queue is full \n"); }
35
how to check this second condition
else if(rear == -1 && front == -1){ front = rear = 0; queue[rear] = x; }
35
what is second we check in enqueue function
in enqueue function second thing we had to check is that, is queue is full empty or not, is that front and rear has -1 values, means that queue is not having any elementyet
35
what is third case in enqueue function
in this third condition, queue is not empty, queue is not overflow or not full filled we handle this in third case
36
what to do, when queue is not full or queue is not completely empty. write code for third condition...
else{ rear++; queue[rear]; } } // enqueue ends here
36
what is first case we have to check in dequeue() function
first thing we have to check in dequeue function is that, is queue is empty or not
36
declare dequeue function
void dequeue()'
37
what if queue is empty when we call dequeue function
if we call dequeue function, then its underflow condition
38
how to check if queue is empty or not, what variables we have to use
we have to use both front and rear variables to check if queue is empty or not
39
how to write condition
if(front == -1 && rear == -1){ printf("queue is empty that is underflow case \n"); }
39
what is second condition we have to check in dequeue function
if queue is having one element or not
39
why do we write front = rear = -1; in second condition of dequeue function
if there is only element, then after deleting it, front and rear should be having -1 value into it
39
how to check if queue is having only one element
else if(front == rear) { front = rear = -1; }
40
what we check in third condition
if there are more than one element in queue
40
write third condition for dequeue function
else{ front++; }
40
how to print dequeued element
before doing front++, we have to print element
40
write code for displaying dequeued elemetn
void dequeue(){ // if queue is empty // if queue has only one element // more than one element if(front == -1 && queue == -1){ // empty queue } else if(front == rear) { // one element only front = rear = -1; } else { printf(%d", queue[front]); } }
40
why we write front++ in dequeue
to delete we have to increment the value of front variable
41
41
42
42
42
42
43
44
44
44
44
45
45
45
45
45
46
46
47
48
48
49
50
50
50