An SLList
In each stack implementation, at the moment a stack of items of type T has n items, the amount of memory in use is n*S + overhead.
Question 1:
The overhead is lowest, 12, when
Question 2:
The overhead is highest, 12 + 2*S*n, when
Question 3:
How is the overhead for ArrayDeque related to that for ArrayStack?
Each node of SLList
Let S = sizeof(T).
Also, sizeof(pointer) is 4 bytes.
The overhead of a stack is 12 + 4n.
The space occupied by an ArrayStack
In an ArrayStack, due to resizing policy, n ≤ length ≤ 3n.
The overhead for ArrayStack
A. The stack has just been resized
B. The stack is full
C. The stack is about to be resized down (within a pop() operation).
A. The stack has just been resized
B. The stack is full
C. The stack is about to be resized down within a pop() operation.
A. same
B. multiple of n higher
C. constant amount higher
D. length modulo n higher.
The space for SLList is 12 + (S+4)*n.
The overhead is 12 + 4*n.
If an ArrayStack has just been resized, the overhead is 12 + S*n.
(the length is 2*n).
An n element SLList has overhead of 12 + 4*n.
Conclusion SLList uses less memory for overhead when S (sizeof(T)) is large.
For instance T might be a complex record type:
A sketch of a record type T:
class Record{
string name;
string street;
string city;
string state;
float volume;
float height;
float weight;
ArrayStack
...
};