Data Structure and Algorithms — Implement Dynamic Array in Python

Y Tech
The Startup
Published in
2 min readJul 13, 2020

--

This is an introduction to dynamic array and its implementation

An array is a contiguous area of memory of equal-size elements. Array length is usually fixed, which means you need to specify the number of elements your array can hold ahead of time.

A dynamic array is an array which has an important feature: auto-resizing. With this feature, you can easily expand your array by adding more elements in it, so that you do not need to determine the size ahead of time.

In this tutorial, we will discuss about the implementation of dynamic array by using regular fixed length array.

Define Interfaces

Below is the thinking process for the design of dynamic array:

  1. Pre-Create an array with a given size (e.g. an array with size 10). All the elements in this pre-created array are Nulls.
  2. Use this pre-created array to represent our dynamic array. So now we have a dynamic array with size 0, and a potential maximum size of 10.
  3. When we want to append a new element into the dynamic array, we can keep assigning elements to the empty slots of the array, until the array is…

--

--