Dynamic array | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Dynamic array

I was thinking about a data structure which would guarantee constant indexing and constant addition. It would differ from normal dynamic arrays as addition of a new item wouldn't be amortized. The idea is to provide an array with fixed sized in which the last item would point to a new array if the data structure needs to grow. That way I would avoid copying the array when capacity is reached. Also, there would be a pointer which points to the current last item so that I can know where to add a new item. Finally, of course, I would keep track of the amount of inner arrays that have been created. What do you think of this idea? Would it be efficient?

12th Feb 2019, 3:13 PM
Jhon
Jhon - avatar
2 Answers
+ 1
Okay. The idea you are suggesting is already present, not exactly, buy similar. There is a data structure called linked list. In linked list, you can expand the array on the go just like you said. Please do look up linked list on Google once. It's really great if you thought about that on your own though. Noice
25th Feb 2019, 11:45 PM
Prajwal Anagani
Prajwal Anagani - avatar
0
I am aware of linked lists. However, they do not provide constant indexing, as a matter of fact, indexing is O(n) which is not that good compared to dynamic arrays. With my idea, I was thinking about providing constant indexing as in dynamic arrays and constant addition as in linked lists. Just like a mix of this two data structures
26th Feb 2019, 9:34 AM
Jhon
Jhon - avatar