Question
Recall that the C++ vector data structure dynamically doubles its size if there is not an available slot to insert an item. (The vector::push_back operation
Recall that the C++ vector data structure dynamically doubles its size if there is not an available slot to insert an item. (The vector::push_back operation increases the number of elements by 1. It also doubles its capacity if there was an available slot to insert an item.) The load factor describes how full the data structure is. It is defined as the vector's size divided by it's capacity. (Empty vectors are given a load factor of 1.) Suppose we allow vector to also contract it's size by 2/3 when its load factor drops below 1/3. (The vector::pop_back operation reduces the number of elements by 1. It also reduces the capacity to 2/3 if the new load factor drops below 1/3. Using the potential function show that the amortized cost of vector::pop back that uses this strategy is bounded above by a constant.
Remember that.
2V.size - V.capacityStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started