Dynamic Structures using High-Level Programming Languages.

What is a Dynamic Structure?

Dynamic structures or Dynamic Data structures can remove or add memory as needed at runtime. Common examples are Linked Lists, Heaps, Stacks, Queues and Trees.

Static Memory
Static Memory means memory size is fixed and determined at compilation. Imagine a room with 3 boxes. You fill 3 boxes and can’t add more items to that room. In languages like C++, the Array data structure has a fixed size. The Vector is a dynamic length Array in C++.

// Compilation
// Array
let x = Array(3)console.log(x.length)
// returns 3
x[999]// returns undefined, because index does not exist

Dynamic Memory
Dynamic memory means that memory can grow or shrink, at code runtime. Imagine a room filled with 3 boxes, you can add and removed boxes when needed. You fill 3 boxes, and add 3 more, for a total of 6 boxes. This is the default behavior of an Array in Node.js

// Compilation
// Dynamic Array
let x = []console.log(x.length)
// returns 0
// Runtime
x.push(1)
x.push(2)
x.push(3)
console.log(x.length)
// returns 3

Coding Examples

The following code implements a simplified Linked List, in various coding languages. However, Linked Lists are data structures native to Java and C++.

C++

Java

Node.js

Python

--

--

--

I am working toward a simpler, more meaningful world. kristofferhebert.com

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Kristoffer Hebert

Kristoffer Hebert

I am working toward a simpler, more meaningful world. kristofferhebert.com

More from Medium

Setting up Circle CI for Android (Github repo)

Commits are to Code what Save Games are to Video Games

Image showing the text “Keep calm and reset to last checkpoint”

The First 5 Principles of Object Oriented Design with JavaScript