Bloomberg LP Interview Question
Financial Application EngineersCountry: United States
Interview Type: Phone Interview
Consider arr[][3] as a linkedlist where arr[i][1] stores the data, arr[i][0] stores the previous index, and arr[i][2] stores the next index. Adding an element is trivial. To delete an element, modify the next index of the prev element and prev index of the next element. To prevent possible "holes" in the array on multiple deletions, maintain a "free list" that you can use to add an element to the deleted index instead of using a new slot altogether.
one way you can think of it as the index of the array as the value and the address of the next to be stored on that index. The head var would store the address of the starting array index.
In Java Library, ArrayList is a resizable-array implementation of the List interface.
LinkedList (class) is another implementation of same List interface.
Array needs to be re-sized (adding more element then initialized array) or
If linked list is implemented using array then new array needs to be created for positional updates. ie. add(index, element). New array creation and copying all the element in new array with required update.
using double array, one containing the value other containing the index of the next element.
- Anonymous April 01, 2012