|
I don't follow the question. An insert operation must specify an index and a value. The index is the target for binary search in the first component, and the value goes in the corresponding second component. For example, consider the sparse array that contains 0 everywhere except index 1 contains 50, index 2 contains 43, index 27 contains 10, and index 128 contains 100: {1,50} {2,43} {27,10} {128,100}Notice that the first components, which are indexes in the sparse array, are in order. But the second components, which are contents of the sparse array, are not in order. Now, if we insert the value 2 at index 31, we get {1,50} {2,43} {27,10} {31,2} {128,100}Binary search for the index 31 shows where the insertion should go: between {27,10} and {128,100}. Insertion is time consuming, because we have to move down every {index,content} pair following the inserted pair. Mike O'D. |
Thanks by Avi Schwab, 2001, Oct 29
to: