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
Q

which variable we increment while doing enqueue()

A

we increment rear variable while insert elements

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

which variable stays at the same position while inserting element to queue

A

front stays at its place while incrementing

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

what happens when we dequeue an element

A

we increment the value value of front

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

peek() returns what

A

peek() function returns position where front is pointintg

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

when front and rear become equal

A

when there is only one element, then the front and rear points to the same position

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

what is meaning of
#define n 5

A

define N, makes global variable and add 5 to it

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

what is first thing we check into enqueue() function

A

first thing we check in enqueue() function, is that is queue is overflow or not

overflow means, is queue is full or not

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

what are applications of queue

A

serving request from single source

in OS processes are placed into queue

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

why we need to pass int x, to enqueue() function

A

into x, we are going to send information or data

32
Q

how to take array for queue

A

int queue[5];

we can use

int queue[N];

32
Q

take two variables and initialize them to -1

A

int front = -1;
int rear = -1;

33
Q

do we need to declare front and rear globally

A

yes, we have to declare front and rear globally

33
Q

define enqueue() function

A

void enqueue(int x) {}

34
Q

how to check overflow of queue

A

if(rear == N - 1) {
printf(“overflow or queue is full \n”);
}

35
Q

how to check this second condition

A

else if(rear == -1 && front == -1){

front = rear = 0;
queue[rear] = x;

}

35
Q

what is second we check in enqueue function

A

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
Q

what is third case in enqueue function

A

in this third condition, queue is not empty, queue is not overflow or not full filled

we handle this in third case

36
Q

what to do, when queue is not full or queue is not completely empty.

write code for third condition…

A

else{
rear++;
queue[rear];
}

} // enqueue ends here

36
Q

what is first case we have to check in dequeue() function

A

first thing we have to check in dequeue function is that, is queue is empty or not

36
Q

declare dequeue function

A

void dequeue()’

37
Q

what if queue is empty when we call dequeue function

A

if we call dequeue function, then its underflow condition

38
Q

how to check if queue is empty or not, what variables we have to use

A

we have to use both front and rear variables to check if queue is empty or not

39
Q

how to write condition

A

if(front == -1 && rear == -1){
printf(“queue is empty that is underflow case \n”);
}

39
Q

what is second condition we have to check in dequeue function

A

if queue is having one element or not

39
Q

why do we write
front = rear = -1;
in second condition of dequeue function

A

if there is only element, then after deleting it, front and rear should be having -1 value into it

39
Q

how to check if queue is having only one element

A

else if(front == rear) {
front = rear = -1;
}

40
Q

what we check in third condition

A

if there are more than one element in queue

40
Q

write third condition for dequeue function

A

else{

front++;

}

40
Q

how to print dequeued element

A

before doing front++, we have to print element

40
Q

write code for displaying dequeued elemetn

A

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
Q

why we write front++ in dequeue

A

to delete we have to increment the value of front variable

41
Q
A
41
Q
A
42
Q
A
42
Q
A
42
Q
A
42
Q
A
43
Q
A
44
Q
A
44
Q
A
44
Q
A
44
Q
A
45
Q
A
45
Q
A
45
Q
A
45
Q
A
45
Q
A
46
Q
A
46
Q
A
47
Q
A
48
Q
A
48
Q
A
49
Q
A
50
Q
A
50
Q
A
50
Q
A