# Which Are Dynamic Data Structure?

//

Heather Bennett

Dynamic data structures are an essential part of programming, allowing us to efficiently store and manipulate data. In this article, we will explore some commonly used dynamic data structures and understand their significance in software development.

## What are Dynamic Data Structures?

Dynamic data structures are containers that can grow or shrink during program execution, unlike static data structures that have a fixed size. These structures dynamically allocate memory as needed, providing flexibility in managing and organizing data.

Let’s dive into some popular dynamic data structures:

A linked list is a linear collection of elements, where each element (node) contains a value and a reference to the next element. This structure allows efficient insertion and deletion operations at any position within the list.

• Dynamic size
• Efficient insertions and deletions

Example:

```class Node {
int value;
Node next;
}

Node newNode = new Node();
newNode.value = 10;
```

### 2. Stack

A stack is a Last-In-First-Out (LIFO) structure that allows inserting and removing elements only from one end called the top. It follows the principle of “last in, first out.”

• Simple implementation
• Easily reversible operation order

Example:

```Stack stack = new Stack<>();
stack.push(1);
stack.push(2);
stack.push(3);

int topElement = stack.pop();
```

### 3. Queue

A queue is a First-In-First-Out (FIFO) structure that allows inserting elements at one end called the rear and removing elements from the other end called the front. It follows the principle of “first in, first out.”

• Order preservation
• Used in scheduling, buffering, and more

Example:

```Queue queue = new LinkedList<>();

int frontElement = queue.poll();
```

### 4. Tree

A tree is a hierarchical data structure consisting of nodes connected by edges. It has a root node and child nodes, forming a branching structure. Trees are widely used for representing hierarchical relationships and searching algorithms.

• Hierarchical organization
• Efficient searching and sorting

Example:

```class TreeNode {
int value;
List children;
}

TreeNode root = new TreeNode();
root.value = 1;

TreeNode child1 = new TreeNode();
child1.value = 2;