VList
#
VListImplement an array that has flexible length. In other words, implement ArrayList in Java without using ArrayList.
- Implement 2 methods:
- void append(T element) -> should be O(1)
- T getByIndex(int index) -> should be O(log n)
- Full explanation:
- TL;DR:
- ArrayList ditches previous arrays after a new longer array is created, VList save those previous arrays and link them together
#
Knowledge Points- Do you know how does Java implement ArrayList, why is it implement that way (1, 2, 4, 8, 16...growth):
- Java implement ArrayList by making a new Array with size * 2, then copy the original elements over.
- append might be -> O(n)
- get is always -> O(1)