Types of Data Structures

Learn Types of Data Structures with practical examples, explanations, best practices, and real-world coding techniques.

Data structures can be classified into different categories based on how they organize data, how their size changes, and how their elements are related. Understanding these classifications makes it easier to choose an appropriate structure for a programming problem.

The most commonly discussed classifications include linear and non-linear data structures and static and dynamic data structures. Data structures may also be described according to whether they store similar or different types of values.

Main Types of Data Structures

A useful high-level classification of data structures is shown below.

Category Examples Main Characteristic
Linear Array, Linked List, Stack, Queue Elements follow a sequential arrangement
Non-linear Tree, Graph, Trie Elements form hierarchical or network relationships
Static Fixed-size Array Size is determined when storage is allocated
Dynamic Linked List, Dynamic Array Structure can grow or shrink during execution

Linear Data Structures

A linear data structure organizes elements in a sequential or logically ordered arrangement. Except for special cases, each element generally has a predecessor and successor relationship.

Common linear data structures include arrays, linked lists, stacks, and queues.

const numbers = [10, 20, 30, 40];

for (const number of numbers) {
  console.log(number);
}

The values in this array can be traversed sequentially from one position to another.

Characteristics of Linear Structures

  • Elements follow a sequential arrangement.
  • Traversal is generally performed from one element to another.
  • They are suitable for many sequential processing problems.
  • Different linear structures provide different insertion, deletion, and access characteristics.

Array

An array stores elements in an indexed sequence. It is particularly useful when direct access by position is important.

const scores = [85, 92, 78, 95];

console.log(scores[2]);

The element at index 2 can be accessed directly without traversing the preceding elements.

Linked List

A linked list consists of nodes connected through references. Each node can contain a value and a reference to another node.

const first = {
  value: 10,
  next: null
};

const second = {
  value: 20,
  next: null
};

first.next = second;

console.log(first.value);
console.log(first.next.value);

Linked lists are useful when the relationships between neighboring elements are more important than direct index-based access.

Stack

A stack is a linear data structure that follows the Last In, First Out (LIFO) principle. The most recently added element is processed first.

const stack = [];

stack.push("Page 1");
stack.push("Page 2");
stack.push("Page 3");

console.log(stack.pop());

Stacks are commonly used for undo operations, expression processing, depth-first search, and function call management.

Queue

A queue is a linear data structure that follows the First In, First Out (FIFO) principle. The element that enters first is processed first.

const queue = [];

queue.push("Request 1");
queue.push("Request 2");
queue.push("Request 3");

console.log(queue.shift());

Queues are commonly used for task processing, scheduling, background jobs, and message handling. The implementation should be chosen carefully when efficient dequeue operations are required.

Non-Linear Data Structures

A non-linear data structure does not organize elements as one simple sequence. Instead, elements can have hierarchical or many-to-many relationships.

Trees and graphs are the most common examples. Tries, heaps, and other specialized structures are also based on non-linear relationships.

Trees

A tree represents hierarchical relationships between elements. A tree normally contains nodes connected through parent-child relationships.

const organization = {
  name: "Engineering",
  children: [
    {
      name: "Backend",
      children: []
    },
    {
      name: "Frontend",
      children: []
    }
  ]
};

Trees are useful for file systems, organizational hierarchies, search structures, indexes, and nested application data.

Graphs

A graph represents relationships between entities. It consists of vertices and edges connecting those vertices.

const graph = {
  A: ["B", "C"],
  B: ["A", "D"],
  C: ["A"],
  D: ["B"]
};

Graphs can model road networks, social connections, dependencies, communication networks, and relationships between software components.

Trie

A trie, also called a prefix tree, organizes strings according to their characters. It is particularly useful for prefix-based searching.

Tries can be used in autocomplete systems, dictionaries, search suggestions, spell-checking, and prefix matching.

Static Data Structures

A static data structure has a size that is determined when its storage is allocated and does not normally change during the structure's lifetime.

A fixed-size array is a common conceptual example.

const scores = new Array(5);

scores[0] = 80;
scores[1] = 90;
scores[2] = 75;

console.log(scores.length);

In languages with fixed-size arrays, the number of elements is determined when the array is created. Some languages also provide dynamic array abstractions that can resize automatically.

Dynamic Data Structures

A dynamic data structure can change its size during program execution. Elements can be added or removed as the amount of data changes.

const tasks = [];

tasks.push("Build project");
tasks.push("Run tests");
tasks.push("Deploy application");

tasks.pop();

console.log(tasks);

Modern programming languages provide several dynamic collection types. Their internal resizing strategies vary by implementation.

Homogeneous Data Structures

A homogeneous data structure stores elements of the same or compatible type. This classification is particularly relevant in languages with strong static typing and fixed-type collections.

const numbers = [10, 20, 30, 40];

console.log(numbers);

The exact type rules depend on the programming language. For example, a statically typed language may require every element of a collection to have the declared type.

Non-Homogeneous Data Structures

A non-homogeneous data structure can contain values of different types or represent records composed of different fields.

const user = {
  id: 101,
  name: "Alex",
  active: true,
  skills: ["Python", "SQL"]
};

console.log(user);

Objects and records commonly represent this style of structured information, although the exact classification depends on the programming language.

Primitive and Non-Primitive Structures

Another common introductory classification divides data into primitive and non-primitive categories.

Primitive types represent basic values provided directly by a programming language, such as numbers, characters, and Boolean values.

const age = 30;
const active = true;
const grade = "A";

Non-primitive structures organize multiple values or relationships and include arrays, linked lists, stacks, queues, trees, graphs, and hash-based collections.

Linear vs Non-Linear Data Structures

The distinction between linear and non-linear structures is one of the most useful classifications when learning data structures.

Feature Linear Non-Linear
Organization Sequential Hierarchical or network-based
Examples Array, Linked List, Stack, Queue Tree, Graph, Trie
Traversal Usually sequential Can follow multiple paths
Typical relationships Neighbor-based Parent-child or many-to-many

Static vs Dynamic Data Structures

Static and dynamic classifications describe how the size or storage of a structure behaves during execution.

Feature Static Dynamic
Size Generally fixed Can change
Memory behavior Allocated for a known size Can allocate or release storage as needed
Example Fixed-size array Linked list or dynamic array
Useful when Size is known and stable Data size changes frequently

Common Data Structures at a Glance

The following summary connects common structures with the problems they are designed to address.

Structure Category Typical Purpose
Array Linear Indexed data
Linked List Linear Node-based sequences
Stack Linear LIFO processing
Queue Linear FIFO processing
Hash Table Hash-based Key-based lookup
Tree Non-linear Hierarchical data
Heap Non-linear Priority-based processing
Graph Non-linear Networks and relationships

How to Choose Between Data Structure Types

Classification is useful, but choosing a data structure should ultimately depend on the operations the application needs to perform.

  1. Identify whether the data is sequential, hierarchical, or relationship-based.
  2. Determine whether the collection size is fixed or likely to change.
  3. Identify whether fast access, search, insertion, or deletion is most important.
  4. Consider whether duplicate values are allowed.
  5. Consider whether ordering is important.
  6. Analyze the expected time and space complexity.
  7. Select the structure that best matches the application's workload.

Example: Selecting a Structure for Different Requirements

Different requirements naturally lead to different data structure choices.

// Fast membership testing
const registeredUsers = new Set([
  "alex",
  "sam",
  "jordan"
]);

// Key-based lookup
const users = new Map([
  [101, "Alex"],
  [102, "Sam"]
]);

// LIFO processing
const tasks = [];
tasks.push("Task A");
tasks.push("Task B");

console.log(tasks.pop());

Each structure addresses a different requirement. This is why learning the properties of data structures is more useful than memorizing their names alone.

Data Structures in Real Applications

  • Arrays: search results, product lists, scores, and ordered records.
  • Linked lists: specialized sequences and node-based structures.
  • Stacks: undo history, expression evaluation, and depth-first processing.
  • Queues: request processing, background jobs, and scheduling.
  • Hash tables: caches, dictionaries, indexes, and fast lookups.
  • Trees: file systems, indexes, menus, and hierarchical records.
  • Heaps: priority queues and scheduling.
  • Graphs: maps, social networks, dependencies, and communication systems.

Why Classification Matters

Learning the categories of data structures gives developers a mental model for recognizing which structures are appropriate for different types of problems.

For example, a hierarchical file system suggests a tree, while a network of connected locations suggests a graph. A requirement to process items in arrival order suggests a queue, while processing the most recently added item first suggests a stack.

Common Beginner Mistakes

  • Assuming one data structure is suitable for every problem.
  • Confusing linear and dynamic classifications.
  • Thinking that all arrays are fixed-size in every programming language.
  • Choosing a structure without considering its common operations.
  • Ignoring memory usage when selecting a data structure.
  • Memorizing categories without understanding the relationships they describe.
  • Assuming a language's built-in collection name always reveals its underlying implementation.

Key Takeaways

  • Data structures can be classified in several ways depending on organization and behavior.
  • Linear structures include arrays, linked lists, stacks, and queues.
  • Non-linear structures include trees, graphs, tries, and heaps.
  • Static structures generally have a fixed size, while dynamic structures can change size.
  • Homogeneous structures generally store values of the same type, while non-homogeneous structures can represent different types or fields.
  • Primitive and non-primitive classifications describe basic values versus structures that organize multiple values.
  • Hash tables are commonly discussed separately because they organize data using hashing and key-based access.
  • The best data structure depends on the operations, relationships, size, and performance requirements of the problem.
  • Understanding data structure classifications provides a foundation for studying more advanced algorithms and structures.

Code Examples

const scores = [85, 90, 78, 95];

console.log("First score:", scores[0]);
console.log("Third score:", scores[2]);
    
const stack = [];

stack.push("Page 1");
stack.push("Page 2");
stack.push("Page 3");

console.log("Removed:", stack.pop());
console.log("Stack:", stack);
    
const queue = [];

queue.push("Request 1");
queue.push("Request 2");
queue.push("Request 3");

console.log("Processing:", queue.shift());
console.log("Queue:", queue);
    
const skills = new Set([
  "JavaScript",
  "Python",
  "JavaScript",
  "SQL"
]);

console.log("Unique skills:", skills);
console.log("Has Python:", skills.has("Python"));
    
const graph = {
  A: ["B", "C"],
  B: ["A", "D"],
  C: ["A"],
  D: ["B"]
};

console.log(graph);
console.log("Neighbors of A:", graph.A);
    

Pro Tip

Do not choose a data structure based only on whether it is linear or non-linear. Start with the operations your application needs most often—such as access, search, insertion, deletion, ordering, or relationship traversal—and then compare the relevant structures by their time and space complexity.

🎨 IgKnight Docs

Master HTML, CSS, JS, Python, .NET and more with easy-to-follow lessons and practical code examples.

© 2025 IgKnight Learning Platform. All rights reserved.