Topics in this sectionData Structures1 topic
- Types of Data Structures
When we write programs to solve problems, we need a way to store and organize information. A data structure is a particular way of organizing and storing data in a computer so that it can be accessed and used efficiently. Choosing the right data structure makes our programs faster and easier to write.
Data structures are divided into two main groups based on how the data is arranged: linear data structures and nonlinear data structures.
In a linear data structure, data elements are arranged in a sequence — one after another, like people standing in a line at a boma market. Each element connects to the one before it and the one after it. You can traverse all elements in one pass.
The main types of linear data structures are arrays, linked lists, stacks, and queues.
Array
An array is a collection of items stored at adjacent memory locations. Think of it like a row of numbered rooms in a hotel — each room has an index number, and you can go directly to any room if you know its number.
For example, if we store the ages of five students in an array, it might look like this in a program:
ages = [14, 15, 14, 16, 15]
The first student's age is at position 0, the second at position 1, and so on. Arrays let you access any element quickly if you know its position.
Linked List
A linked list is like a treasure hunt — each item contains data AND a pointer to the next item in the sequence. To find a particular item, you must start at the beginning and follow the chain.
Unlike arrays, linked lists can grow or shrink easily during program execution. Each element is called a node.
Stack
A stack works like a stack of plates in a school dining hall. You add new items to the top, and you can only remove items from the top. This is called Last In, First Out (LIFO).
In programming, stacks are used when you need to undo actions — for example, when you press the back button in a web browser, the browser remembers the pages you visited using a stack.
Queue
A queue works like people waiting for a shared taxi in Juba. The first person to arrive is the first to get in. This is called First In, First Out (FIFO).
Queues are used in real-world situations like printing documents — the first document sent to the printer is the first one printed.
In a nonlinear data structure, data elements are not arranged in a sequence. Instead, they branch out or connect to each other in many ways. You cannot traverse all elements in a single pass.
The main types are trees and graphs.
Tree
A tree data structure has a hierarchical structure — there is one top element called the root, and each element can have multiple "children" branching below it. Think of a family tree or the organization chart of a county government.
In a tree, there is only one path between any two nodes. The binary tree is a common type where each node has at most two children.
Graph
A graph is the most flexible structure — it consists of points called nodes (or vertices) connected by lines called edges. Unlike a tree, there can be multiple paths between nodes.
A road map of South Sudan can be thought of as a graph: cities like Juba, Wau, and Malakal are nodes, and the roads connecting them are edges.
| Property | Linear Structures | Nonlinear Structures |
|---|---|---|
| Arrangement | Sequential | Branched or networked |
| Traversal | Single path | Multiple paths possible |
| Examples | Array, Linked List, Stack, Queue | Tree, Graph |
| Complexity | Simpler to implement | More complex but more flexible |
Imagine you are managing a small shop in Wau and you want to track your sorghum stock. You could use:
- An array if you know you will always have exactly 10 types of grain in stock
- A linked list if the number of grain types changes frequently
- A queue if customers arrive and are served in the order they came (first come, first served)
For a company's employee hierarchy, a tree would be best. For mapping delivery routes between different towns, a graph would be most useful.
In everyday life, data structures are used without most people realizing it. When a teacher at a county school records student marks using a simple list, that is an array. When a mobile money agent in Malakal processes transactions in the order customers arrived, that is a queue. The tree structure appears in family relationships and in the administrative hierarchy from the national government down to payams and bomas. Understanding data structures helps anyone working with computers — from writing simple programs to managing information systems in hospitals or government offices.
Question
What are the two main groups into which data structures are divided?
Sign in to submit your answer and have it count toward your mastery.
Sign in to practiceTutor
Stuck? Ask me anything about this topic.
Sign in to ask the Sonza AI Tutor about this question.
Sign in to askDiscussions
No questions yet