Bird
0
0
DSA Cprogramming~20 mins

Dequeue Using Linked List in DSA C - Practice Problems & Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Dequeue Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of Dequeue Operations on Linked List
What is the printed state of the dequeue after performing these operations in order?

Operations:
1. Insert 10 at rear
2. Insert 20 at front
3. Insert 30 at rear
4. Delete from front
5. Insert 40 at front
DSA C
struct Node {
    int data;
    struct Node* next;
    struct Node* prev;
};

// After operations, print from front to rear
// Format: data1 -> data2 -> ... -> null

// Initial dequeue is empty
A20 -> 30 -> 40 -> null
B40 -> 10 -> 30 -> null
C40 -> 30 -> null
D20 -> 10 -> 30 -> null
Attempts:
2 left
💡 Hint
Remember that insert at front adds before current front, and delete from front removes the front node.
Predict Output
intermediate
2:00remaining
Result of Mixed Insert and Delete in Dequeue
Given an empty dequeue implemented using a doubly linked list, what is the state after these operations?
1. Insert 5 at front
2. Insert 15 at rear
3. Insert 25 at rear
4. Delete from rear
5. Insert 35 at front
DSA C
// Print dequeue from front to rear after operations
// Format: data1 -> data2 -> ... -> null
A35 -> 15 -> null
B15 -> 5 -> 35 -> null
C5 -> 15 -> 35 -> null
D35 -> 5 -> 15 -> null
Attempts:
2 left
💡 Hint
Deleting from rear removes the last element inserted at rear.
🔧 Debug
advanced
2:00remaining
Identify the Bug in Dequeue Delete from Front
Consider this function to delete from front in a dequeue implemented with a doubly linked list. What is the bug causing a crash or incorrect behavior?
DSA C
void deleteFront(struct Node** front, struct Node** rear) {
    if (*front == NULL) {
        printf("Dequeue is empty\n");
        return;
    }
    struct Node* temp = *front;
    *front = (*front)->next;
    free(temp);
    if (*front != NULL) {
        (*front)->prev = NULL;
    } else {
        *rear = NULL;
    }
}
ANo bug, function works correctly
BMissing check for empty dequeue before freeing temp
CDoes not set front pointer to NULL when dequeue becomes empty
DDoes not update rear pointer when dequeue becomes empty
Attempts:
2 left
💡 Hint
Check what happens when the dequeue has only one node.
🧠 Conceptual
advanced
1:30remaining
Time Complexity of Dequeue Operations Using Linked List
What is the time complexity of inserting or deleting an element at either end of a dequeue implemented using a doubly linked list?
AO(1) for insertions at front, O(n) for deletions at rear
BO(n) for insertions at rear, O(1) for deletions at front
CO(1) for all insertions and deletions at front and rear
DO(n) for all insertions and deletions
Attempts:
2 left
💡 Hint
Think about how pointers are updated in a doubly linked list.
🚀 Application
expert
3:00remaining
Design a Function to Reverse a Dequeue Using Linked List
You have a dequeue implemented as a doubly linked list with front and rear pointers. Which of the following code snippets correctly reverses the dequeue so that front becomes rear and vice versa, and the order of elements is reversed?
A
void reverseDequeue(struct Node** front, struct Node** rear) {
    struct Node* current = *front;
    struct Node* temp = NULL;
    while (current != NULL) {
        temp = current->prev;
        current->prev = current->next;
        current->next = temp;
        current = current->prev;
    }
    if (temp != NULL) {
        *rear = *front;
        *front = temp->prev;
    }
}
B
void reverseDequeue(struct Node** front, struct Node** rear) {
    struct Node* current = *front;
    struct Node* temp = NULL;
    while (current != NULL) {
        temp = current->next;
        current->next = current->prev;
        current->prev = temp;
        current = current->prev;
    }
    if (temp != NULL) {
        *rear = *front;
        *front = temp->prev;
    }
}
C
void reverseDequeue(struct Node** front, struct Node** rear) {
    struct Node* current = *front;
    struct Node* temp = NULL;
    while (current != NULL) {
        temp = current->prev;
        current->prev = current->next;
        current->next = temp;
        current = current->prev;
    }
    if (temp != NULL) {
        *front = *rear;
        *rear = temp->prev;
    }
}
D
void reverseDequeue(struct Node** front, struct Node** rear) {
    struct Node* current = *front;
    struct Node* temp = NULL;
    while (current != NULL) {
        temp = current->prev;
        current->prev = current->next;
        current->next = temp;
        current = current->prev;
    }
    if (temp != NULL) {
        *front = temp->prev;
        *rear = *front;
    }
}
Attempts:
2 left
💡 Hint
Swapping next and prev pointers reverses the list. Then update front and rear pointers accordingly.