A library that piles its books in a heap can store them, but nobody can find one. The same books arranged on labelled shelves can be found in moments. The way data is organized decides how easily a solution can use it.
What Is a Data Structure?
Definition: Data structure. A way of organizing data in memory so that the operations a solution needs can be carried out conveniently.
An algorithm describes the steps of a solution. A data structure holds the data on which those steps work. The two are designed together, because the best steps depend on how the data is arranged.
Common Ways of Organizing Data
At this stage three simple organizations are enough.
A single variable holds one value, such as a total or a count.
A list (in C, an array) holds many values of the same kind in a fixed order. Each value has a position, called its index A list suits tasks that visit every item in turn, such as adding a set of marks.
A table holds related details together in rows and columns, such as the roll number, name and mark of every student. A table suits tasks in which several facts about the same item must stay together.
Matching the Structure to the Work
The choice of structure depends on the operations the solution must perform. The questions to ask are:
- Must every item be visited in order?
- Must a particular item be found quickly?
- Will new data be added or old data removed?
- How much data is there, and how often is each operation used?
Table 1.7 matches some needs to structures.
Table 1.7: Choosing a way to organize data
| Need of the solution | Suitable organization | Reason |
|---|---|---|
| Keep a running total | Single variable | Only one value changes |
| Process 60 marks in order | List (array) | Items are visited one after another |
| Keep name and mark together | Table | Related facts share a row |
| Find an item quickly | Sorted list | Order allows faster searching |
A Structure Does Not Solve the Problem Alone
A data structure only organizes information. It still needs an algorithm that works on it. Equally, a good algorithm may become slow or awkward if the data is poorly organized. Storing sixty marks in sixty separately named variables is possible, but adding them would need sixty separate steps. Storing them in one list lets a single repeated step do the work.
Example 1.7: Choosing a structure for an average
Problem: The average of the marks 45, 82, 67, 91, 58 is required. Choose how to store the data and outline the solution.
Solution:
- All five values are of the same kind and each must be visited once, so a list is suitable.
- A single variable, total, holds the running sum and starts at 0.
- Visit each position of the list from index 0 to index 4 and add its value to total. The total becomes 45, 127, 194, 285 and finally 343.
- Divide total by the number of values, 5.
Result: The average is 343 / 5 = 68.6. The list made it possible to use one repeated step for all the values.
Common mistakes
- Using many separate variables where a list would allow one repeated step.
- Choosing a structure before deciding which operations the solution needs.
- Expecting a data structure to produce the answer without an algorithm.
Key takeaways
- A data structure organizes data so that needed operations are convenient.
- Algorithms and data structures are designed together.
- A list suits ordered processing; a table keeps related facts together.
- The operations required by the task decide the choice of structure.
Practice questions
- What is a data structure?
- Which organization suits storing the roll number, name and mark of each student?
- Why is a list better than sixty separate variables for sixty marks?
Answers to the practice questions
- A way of organizing data in memory so that the operations a solution needs can be carried out conveniently.
- A table, because related facts about one student stay together in a row.
- One repeated step can process every position of a list, while separate variables need a separate step each.
Sources
- Official BCA syllabus (NEP 2025 scheme), Problem Solving Techniques, course code 25BCA401SEC01, Unit I
