2nd Exam Flashcards

1
Q

Q: What does the QFront() operation return in a queue?

A

A: The QFront() operation returns the first element of the queue.

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

Q: When does a circular queue become full?

A

A: A circular queue becomes full when the front is greater than the rear by 1.

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

Q: When is a circular queue empty?

A

A: A circular queue is empty when both the front and rear are equal to -1.

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

Q: What policy does a queue implement?

A

A: A queue implements the first-in, first-out (FIFO) policy.

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

Q: What is the inchworm effect in queue implementation?

A

A: The inchworm effect is noticeable when implementing array-based queues.

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

Q: What operation returns the first element of a queue?

A

A: The Queue.Front() operation returns the first element.

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

Q: What is the solution to the problem encountered with array-based queues?

A

A: A circular queue is the solution for problems encountered with array-based queues.

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

Q: What does Tenqueue(QFront() * 2) do?

A

A: It correctly inserts a value that is 2 times the value of the first element of the queue named T.

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

Q: What does the Dequeue() operation do in a queue?

A

A: The Dequeue() operation removes the element at the front of the queue.

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

Q: What does the head pointer in a queue provide?

A

A: The head pointer provides information about the memory address location.

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

Q: When does a circular queue become full (alternate condition)?

A

A: A circular queue becomes full when the front is equal to the rear.

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

Q: What happens to the next oldest element after a Dequeue() operation?

A

A: The next oldest element becomes the front element after a Dequeue().

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

Q: What does the Dequeue() operation remove in a queue?

A

A: The Dequeue() operation removes the element at the front of the queue.

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

Q: What type of data structure is a queue?

A

A: A queue is a linear data structure that follows the First In First Out (FIFO) order.

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

Q: What is a real-world example of a queue?

A

A: A line of customers waiting for service at a bank.

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

Q: What happens to a newly inserted element in a circular queue after an Enqueue() on an empty queue?

A

A: The new element becomes the rear element.

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

Q: How does the queue differ from a stack?

A

A: In a stack, the most recently added item is removed first, while in a queue, the least recently added item is removed first.

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

Q: What is the front or head in a queue?

A

A: It is the end of the queue where all deletions (removals) are made.

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

Q: What operation inserts an element at the rear of a queue?

A

A: The Enqueue operation.

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

Q: What is the rear or tail in a queue?

A

A: It is the end of the queue where all insertions are made.

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

Q: What is queue overflow?

A

A: Queue overflow occurs when you try to insert an element into a full queue.

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

Q: What operation removes an element from the front of a queue?

A

A: The Dequeue operation.

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

Q: What are two operations that observe the state of a queue?

A

A: Full() (returns 1 if the queue is full) and Empty() (returns 1 if the queue is empty).

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

Q: What is queue underflow?

A

A: Queue underflow occurs when you try to remove an element from an empty queue.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q: What does Rear() operation return in a queue?
A: It returns the value of the last element in the queue.
19
Q: What does Front() operation return in a queue?
A: It returns the value of the first element in the queue.
20
Q: What does Count() operation do in a queue?
A: It returns the number of elements in the queue.
21
Q: In a linear queue, what does the Enqueue() operation do when called multiple times?
A: It adds elements sequentially at the rear.
21
Q: What is a linear (non-circular) queue?
A: It is a FIFO ordered list where elements are added at one end and deleted from the other end, resembling a straight line.
21
Q: What is a circular queue?
A: A queue where the last element is connected to the first element, forming a ring structure.
22
Q: What problem is caused by the array-based implementation of queues?
A: The inchworm effect, where elements slide to the right after several Dequeue operations.
22
Q: How can the inchworm effect be solved in queue implementation?
A: By using circular arrays.
23
Q: In a circular queue, what happens when the queue is full in actual?
A: No overflow condition is generated until the queue is completely full.
23
Q: What happens to the rear pointer in a circular queue when the array is full?
A: The rear pointer wraps around to the first position if space is available.
24
Q: What does the isFull() function check in a queue?
A: It checks if the queue is full and returns true if so.
25
Q: What does the isEmpty() function check in a queue?
A: It checks if the queue is empty and returns true if so.
26
Q: What happens when you call Dequeue() on an empty queue?
A: Queue underflow error occurs.
27
Q: What happens when you call Enqueue() on a full queue?
A: Queue overflow error occurs.
27
Q: What is the purpose of the isEmpty() function in a queue or linked list?
A: It returns true if the queue or list is empty, otherwise false.
27
Q: What happens to the queue state after multiple Dequeue() and Enqueue() operations?
A: The front and rear pointers will move circularly within the array.
28
Q: In a circular queue, what happens after multiple Dequeue() operations when the front moves to the last element?
A: The front wraps back to the start of the array.
28
Q: What happens to the rear pointer after multiple Enqueue() operations in a circular queue?
A: The rear pointer wraps around to continue adding elements at the start of the array.
29
Q: What does the Dequeue() operation do in a queue?
A: It removes the element at the front of the queue.
29
Q: In a queue with size 10, what happens if you Enqueue() beyond the capacity?
A: Queue overflow will occur, preventing further insertions.
30
Q: After several Dequeue() operations in a circular queue, what will the Front() return?
A: The value of the oldest remaining element in the queue.
30
Q: What does Rear() return after several Enqueue() operations in a circular queue?
A: The value of the most recently added element.
30
Q: What does the Enqueue() operation do in a queue?
A: It inserts an element at the rear of the queue.
31
Q: How does a circular queue differ from a linear queue?
A: A circular queue treats the array as a ring, where the next element of the last position is the first position, preventing the inchworm effect.
31
Q: How do you delete a node at a specific position in a linked list?
A: Traverse the list to the node before the position, then update its pointer to bypass the node to be deleted, and finally delete the node.
31
Q: Describe the problem of an inchworm effect in a linear queue.
A: It occurs when elements slide right during deletions, leading to wasted space, which can be solved using a circular queue.
31
Q: What happens when head == rear in a queue?
A: The queue is either full or empty depending on the context.
31
Q: How does a circular queue resolve the problem of queue overflow?
A: A circular queue allows reuse of empty spaces by wrapping around when the rear reaches the end of the queue array.
31
Q: What does the addAtFirst(Item x) function do in a linked list?
A: It inserts a new node containing the data x at the beginning of the linked list.
31
Q: How do you delete the first node of a linked list?
A: Set the head's next pointer to the node pointed to by the first node and delete the first node.
31
32
Q: What does the traverseList() operation in a linked list do?
A: It processes or visits each node in the list, typically used for displaying or manipulating each node.
32
Q: What is the listCount() operation in a linked list?
A: It returns the number of nodes currently present in the list.
32
Q: What does the addAtMiddle(Item x, int position) function do?
A: It inserts a new node containing the data x at the specified position in the linked list.
32
Q: Describe the removeLast() operation in a linked list.
A: It deletes the last node by traversing to the second last node and updating its next pointer to null.
32
Q: What is the significance of the head node in a linked list?
A: The head node serves as the starting point and contains the link to the first node in the list.