What is a data structure?

The key idea

A data structure organises information so a program can perform operations on it. The choice affects how you access, search, insert and remove values, as well as memory use. It is more than a way to store a list of names.

Begin with the operations your problem needs. A collection used mostly for indexed reading has different requirements from a sequence used to undo the most recent action.

Ask four questions before choosing

  1. How will I find an element: by position, key or traversal?
  2. Where and how often will values be inserted or removed?
  3. Must order be preserved, sorted or irrelevant?
  4. What size and memory constraints apply?

Answer with the workload you expect, and mark uncertain assumptions. There is no universally best structure for every program.

Compare a few common choices

NeedA structure to investigateMain question
Read by positionArray or vectorAre the index and current size valid?
Process most recent firstStackWhat happens when it is empty?
Process earliest arrival firstQueueIs first-in-first-out really the rule?
Find a value by keyHash tableWhat costs and collision behaviour apply?
Represent ordered relationshipsA suitable treeIs it balanced and how is it traversed?

These are starting points rather than automatic decisions. For example, hash-table lookup is commonly described by expected average performance under suitable assumptions; that does not promise constant time in every case.

Try a selection exercise

Imagine three small tools. A revision app needs the latest action undone first. A print simulator processes jobs in arrival order. A table of weekly totals is read by day position.

A stack fits the first operation rule, a queue fits the second, and an indexed array or vector is a natural candidate for the third. Explain the operation before naming the structure. If the print simulator introduces urgent priorities, a plain FIFO queue may no longer express the required rule.

Learn representation and interface separately

A stack describes allowed operations and ordering. It can be implemented using different underlying storage. Understanding that distinction prevents you from assuming that every abstract data type has only one implementation.

When studying an implementation, draw what changes after an insertion or removal. Check empty and single-element cases. Explain which invariants must stay true after every operation.

How should you prepare for the course?

Gammal Tech's Data Structures course requires C++. Review functions, basic collections and the language concepts required by the course before starting. Algorithms follows Data Structures in this route.

Keep a comparison notebook with operation, cost, assumption and example. You will use it later when evaluating algorithms. The aim is to justify a choice, not merely recite a catalogue of structure names.

Choose your next step with Gammal Tech

Choose one skill you want to demonstrate, then review the relevant course and its prerequisites. Ask Gammal Tech about the content, study arrangements and current fees before enrolling.

References and course details

Use these references for further study. The examples and exercises in this article are educational; consult the catalogue for course details.

Articles & Guides