Which header file must be included to use `deque` in C++?
A
<queue> B
<deque> C
<stack> D
<list>
Analysis & Theory
`std::deque` is defined in the `<deque>` header file.
Which of the following operations is allowed in a `deque`?
A
Insert at front B
Insert at back C
Delete from front D
All of the above
Analysis & Theory
`deque` supports insertion and deletion at both ends efficiently.
What is the time complexity of insertion at the front in a `deque`?
A
O(n) B
O(log n) C
O(1) D
O(n log n)
Analysis & Theory
`deque` allows constant time insertion at both ends: O(1).
Which function is used to add an element at the end of a `deque`?
A
add() B
push_back() C
append() D
enqueue()
Analysis & Theory
`push_back()` adds an element at the rear of a `deque`.
Which function removes the front element from a `deque`?
A
pop() B
remove() C
pop_front() D
erase()
Analysis & Theory
`pop_front()` removes the first element from the `deque`.
What does `deque.size()` return?
A
Maximum capacity B
Memory size C
Number of elements in the deque D
Number of bytes used
Analysis & Theory
`size()` gives the number of elements currently in the `deque`.
How do you access the first element of a `deque`?
A
front() B
top() C
first() D
begin()
Analysis & Theory
`front()` returns a reference to the first element in the `deque`.
Which function returns a reference to the last element of a `deque`?
A
rear() B
back() C
end() D
tail()
Analysis & Theory
`back()` returns the last element of the `deque`.
What happens if you call `pop_front()` on an empty `deque`?
A
Nothing happens B
Returns false C
Throws runtime error or causes undefined behavior D
Returns 0
Analysis & Theory
Calling `pop_front()` on an empty `deque` causes undefined behavior.
Which of the following is true about `deque`?
A
It allows random access B
It is implemented as a dynamic array C
It does not support iterators D
It only allows operations at one end
Analysis & Theory
`deque` supports random access just like `vector`.