STL C++ Flashcards

1
Q

What is a STL made of?

A
  1. Container
  2. Iterator
  3. Algorithm
  4. functions
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

std::array

A

array arr;

  1. encapsulates a fixed size array.
  2. arraysize is needed at the compile time.
  3. Assign by value is actually by value.
  4. access elements: i) at() ii) [] iii) front() iv) back() v) data()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

std::vector

A

vector v(5, 0)

  1. sequence container
  2. dynamic array or ArrayList
  3. Its size can grow and diminish dynamically.
  4. access elements by i)at() ii) [] iii) front() iv) back() v) datat()
  5. modifiers: i) insert() ii) emplace() iii) push_back() iv) emplace_back() iv) pop_back() v) resize() vi)swap() vii) erase() viii) clear()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

std::set

A
  1. set is an associative container and contains a sorted set of unique objects of type key.
  2. usually implemented using red-black tree.
  3. Insertion, retrieval and deletion is O(log N)
  4. if we want to store user defined data types in some order we need to provide with a compare function.
  5. We can pass the order of sorting while constructing the set object.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

std::multiset

A
  1. multiset is an associative container and contains a sorted set of duplicate objects of type key.
  2. usually implemented using red-black tree.
  3. Insertion, retrieval and deletion is O(log N)
  4. if we want to store user defined data types in some order we need to provide with a compare function.
  5. We can pass the order of sorting while constructing the set object.
  6. Multiset is similar to set except it can contain multiple values with same value.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

std::map

A
  1. map obj; //T1 is one type T2 is of another type
  2. std::map is an associative container that store elements in key value combination where key should be unique otherwise it overrides the previous value.
  3. It is implemented using self-balancing trees (AVL/BST)
  4. It stores key value pairs in an order.
  5. Generally used in dictionary type problems.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

std::multimap

A
  1. multimap obj; //T1 is one type T2 is of another type
  2. std::multimap is an associative container that store elements in key value combination where key could be duplicate.
  3. Data structure for multimap is not specified but most people assume It is implemented using self-balancing trees (AVL/BST).
  4. It stores key value pairs in an order.
  5. Lookup: count, find, contains, equal_range, lower_bound, upper_bound.
  6. We don’t have at() or [] like we had in map.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

std::forward_list

A
  1. forward_list list1;
  2. This is a single linked list.
  3. Available operations: =, assign, front, empty, max_size, clear, insert_after, emplace_after, reverse, sort, merge, splice_after, unique, remove, remove_if, resize.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

std::list

A
  1. List is a doubly linked list.
  2. List is a sequence container that allow non-contagious memory allocation.
  3. List is faster than other sequence containers in terms of insertion,retrieval or deletion if we have an iterator.
  4. Used as DLL in C++.
  5. Operations: =, assign, front, back, empty, size, max_size, clear, insert, emplace, push_back, pop_back, push_front, pop_front, reverse, sort, merge, splice, unique, remove, remove_if, resize.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

std::deque

A
  1. Double ended queue
  2. is an indexed sequence container.
  3. Allows fast insertion at both beginning and end,
  4. Unlike vectors elements are not stored in contagious manner.
  5. uses individual allocated fixed size array, with additional bookkeeping, meaning indexed based access to deque must perform two pointer derefence as opposed to one pointer derefernce in vector.
  6. Storage is automatically expanded and contracted as needed.
  7. Expansion is cheaper than that of vector.
  8. A deque holding one element has to allocate its full internal array.
  9. Time complexity: Random access O(1), Insertion/Removal at beginning O(1), Insertion/Deletion O(N).
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

std::unordered_set

A
  1. unordered_set is an associative container that contains set of unique elements.
  2. Search, insertion and removal have average time constant time complexity.
  3. Internally the elements are organized into buckets.
  4. It uses hashing to insert elements into the buckets.
  5. Allows fast access.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

std::unordered_map

A
  1. std::unordered_map is an associative container that store elements in key value combination where key should be unique otherwise it overrides the previous value.
  2. Search, insertion and removal have average time constant time complexity.
  3. . Internally the elements are organized into buckets.
  4. It uses hashing to insert elements into the buckets.
  5. Allows fast access.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

std::pair

A
  1. std::pair is a struct template that provides a way to store two heterogeneous objects as a single unit.
  2. map, multimap, unordered_map, unordered_multimap can use pair to insert data into their structures.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

std::priority_queue

A
  1. std::priority_queue is a container adaptor that provides constant time lookup of the largest or the smallest element.
  2. By default std::vector is the container used inside.
  3. Cost of insertion and extraction is logarathmic.
  4. std::priority_queue is implemented using std::make_heap, std::push_heap, std::pop_heap functions.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

std::queue

A
  1. a container adaptor that gives the programmer the the functionality of a queue.
  2. queue is a FIFO DS.
  3. provides only specific set of functions.
  4. allows to push(insert) at front and pop(remove) at back.
  5. gives front,back, push, pop, empty, size.
  6. The standard container classes deque and list fulfill the requirements of queue. By default, if no container class is specified for a particular queue class instantiation, the standard container deque is used.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

std::stack

A
  1. a container adaptor that gives the programmer the the functionality of a queue.
  2. stack is a LIFO DS.
  3. Internally uses std::deque.
  4. Can perform push and pop functions.
  5. Functions provided: empty(), size(), top(), push(g), pop().