Non Primitive Data Structures
Non-primitive data structures are more complex data structures that are derived from primitive data types (like integers, floats, characters, etc.). They allow us to organize and store data in a structured way and are essential for efficient data management and processing. Here are some common non-primitive data structures:
Types of Non Primitive Data Structures
Non primitive data structures are divided into two main types: Linear and Non-Linear data structures. Let’s explain both of these.
1. Linear Data Structures
Elements are arranged sequentially, and each member element is connected to its previous and next elements. This arrangement makes it easy to traverse the structure in a single run. Various Examples of linear data structure are given below
i) Arrays: Elements are stored in contiguous memory locations, and they can be accessed using indices. Various types of arrays are
- Single-Dimensional Array
- Multi-Dimensional Array
ii) Linked Lists: Consists of nodes that contain a data part and a reference to the next node in the sequence. Here are the main types of linked lists:
- Singly Linked List
- Doubly Linked List
- Circular Singly Linked List
- Circular Doubly Linked List
iii) Stacks: Follows Last In First Out (LIFO) order where elements are added and removed from one end. Here are the main types of stacks:
- Array-based Stack
- Linked List-based Stack
- Dynamic Stack
iv) Queues: Operates on First In First Out (FIFO) basis with elements added at one end and removed from the other. Here are the main types of queues:
- Simple Queue
- Circular Queue
- Priority Queue
- Double-Ended Queue (Deque)
2. Non-Linear Data Structures
Elements are not arranged in a sequential manner and one element might be connected to one or more elements, which makes it possible to traverse the structure in multiple ways.
i) Trees: Hierarchical structure with a root element from which sub-elements branch out. There are various types of trees in non-linear data structures, They are as follows:
- Binary Tree
- Simple Tree
- Complete Binary tree
- Binary Search Tree
- AVL Trees
- B -Tree
- B+ Tree
ii) Graphs: Consists of nodes (or vertices) and edges that connect pairs of nodes which can represent various complex networks. Various types of graph are given below
- Finite Graph
- infinite Graph
- Trivial Graph
- Simple Graph
- Multi Graph
- Null Graph
- Complete Graph
- Pseudo Graph
- Regular Graph
- Weighted Graph
Non Primitive Data Structures Memory Allocation
Memory allocation for non-primitive data structures can be static or dynamic, depending on the structure’s requirements and expected data changes during program execution.
A) Static Memory Allocation
When the full set of data is known in advance and does not change during execution (runtime), is called static Memory allocation. It is useful in memory usage and processing speed because additional memory allocation or deallocation operations are not needed during runtime.
Example: Array, can be dynamic as well in some scenarios.
B) Dynamic Memory Allocation
When data is expected to change during the execution of a program, is called dynamic Memory allocation. It requires the flexibility to add or remove elements as needed to handle these changes efficiently.
Example: Link list, queue, stack etc.