Standard Template Library Flashcards
What kind of iterators are available?
- Input
- Output
- Forward
- Bidirectional
- Random access
What is a priority queue?
Priority queues are a type of container adapters, specifically designed such that the first element of the queue is the greatest of all elements in the queue and elements are in non decreasing order
Are keys in unordered sets unique?
Unordered sets are containers that store unique elements
What is a heap?
What can it retrieve?
Heap data structure can be implemented in a range using STL which allows faster input into heap and retrieval of a number always results in the largest number i.e. largest number of the remaining numbers is popped out each time.
Unordered Maps. How are the elements organized in memory?
They are not organized based on the key, but organized into buckets depending on their hash values to allow for fast access to individual elements directly by their key values
What can I add to a map?
{key, value}
Do list provide random access?
No, since they are not contiguous in memory
What is the time complexity of insert to priority queue?
Logarithmic
What is a bidirectional iterator?
They can move in both directions (forward and backward)
How much time does it take to remove the last element in a vector?
Removing the last element takes only constant time because no resizing happens.
What is the time complexity of access to priority queue?
Constant O(1) to largest element
What is a pair? How do I create one?
What is contained in a pair?
The pair container is a simple container defined in header consisting of two data elements or objects.
The first element is referenced as ‘first’ and the second element as ‘second’ and the order is fixed (first, second).
Pair is used to combine together two values which may be different in type. Pair provides a way to store two heterogeneous objects as a single unit.
How can I move an iterator forward or backward by a given amount?
advance(pointer, quantity). Quantity can be positive or negative
What is the time complexity of insert into stack?
Inserting into a stack can only happen at the top, so insertion is O(1).
What is the erase time complexity of vector?
Removing the last element takes only constant time because no resizing happens. Inserting and erasing at the beginning or in the middle is linear in time.
How can I sum all the elements in a container?
accumulate(first_iterator, last_iterator, initial value of sum)
What is the access time complexity of list?
O(1) if you already have the iterator to the element, O(N) if not
Where can I add elements to a vector?
In the back, with push_back()
Are key values unique in a map?
Yes, a map has unique keys
Are lists faster or slower to traverse than vectors?
As compared to vector, list has slow traversal, but once a position has been found, insertion and deletion are quick.
How can I implement a deque?
1) Doubly-linked list, allowing add/remove from both ends.
2) Dynamic array
What is the time complexity of access in a map?
Logarithmic
What is the time complexity of erasing from stack?
Deleting from a stack only happens at the to, so deletion is O(1).
What is the time complexity of access to queue?
O(N)