MEG 202 · Basic Software Engineering
Our notes
2 min readData structures
A data structure is a way of organising data in memory so it can be used efficiently. The choice affects how fast a program runs and how simple it is. Primitive types: integer, real (floating point), character, boolean. Structured types combine them.
Arrays
An array is a fixed-size collection of elements of the same type, stored in consecutive memory locations and accessed by an index.
- One-dimensional: a list of values. In C indices start at 0: double t[5]; holds t[0] to t[4]. (FORTRAN starts at 1 by default.)
- Address calculation: address of t[i] = base address + i × size of element. This is why access by index is instant (constant time).
- Two-dimensional: a table or matrix, a[i][j]. Stored row by row in C (row-major) and column by column in FORTRAN (column-major). This matters for speed when looping and when mixing languages.
Example (matrix addition in C):
for (i = 0; i < 3; i++)
for (j = 0; j < 3; j++)
c[i][j] = a[i][j] + b[i][j];
Strengths: fast access by index; simple. Weaknesses: fixed size; inserting or deleting in the middle means shifting elements.
Records (structures)
A record groups related items of different types under one name; each item is a field.
struct Bolt {
char grade[6];
double diameter_mm;
double tensile_MPa;
int stock;
};
Access with a dot: b.diameter_mm. An array of records is like a table: each record a row, each field a column (the basis of databases).
Files
Data in memory is lost when a program ends; files keep it on secondary storage.
- Text files: human-readable characters (CSV data from a data logger).
- Binary files: raw bytes in the program's internal format: compact and fast, but not readable in a text editor.
Basic operations: open, read, write, append, close. In C: fopen, fscanf or fread, fprintf or fwrite, fclose. Always check that a file opened successfully.
File organisation
- Sequential: records stored one after another and read in order (magnetic tape, logs). Simple; slow to find one record.
- Direct (random) access: any record reached by its position or address (fixed-length records).
- Indexed sequential: records in order with an index for quick lookup.
Terms: field → record → file → database; a key field uniquely identifies each record (a student's matriculation number).
Exams usually ask
- Define an array and compute an element's address.
- Explain row-major and column-major storage.
- Define a record and a file; compare sequential and direct access.
Common mistake
Going outside an array's bounds (t[5] in an array of 5 elements in C). C does not check, so the program may silently corrupt memory or crash.
Written by the UniHive team in our own words. Spotted a mistake? Tell us on WhatsApp.
Read
-
Best pick Introduction to Computer Science, 3.1 Introduction to Data Structures and Algorithms
(opens openstax.org in a new tab)
OpenStax, Introduction to Computer Science, 3.1 Introduction to Data Structures and Algorithms, CC BY-NC-SA 4.0 · licence
-
Array (data structure)
(opens en.wikipedia.org in a new tab)
Wikipedia, Array (data structure), CC BY-SA 4.0 · licence
-
Record (computer science)
(opens en.wikipedia.org in a new tab)
Wikipedia, Record (computer science), CC BY-SA 4.0 · licence
-
Computer file
(opens en.wikipedia.org in a new tab)
Wikipedia, Computer file, CC BY-SA 4.0 · licence
-
NOUN CIT 216: Fundamentals of Data Structures
NOUN course book (PDF, about 3.3 MB). Arrays, records, lists, stacks, queues, sorting and searching.
(opens nou.edu.ng in a new tab)
-
OpenStax, Introduction to Computer Science (whole free textbook)
The whole book, free to read online or download as a PDF (the PDF is large: Wi-Fi).
(opens openstax.org in a new tab)
OpenStax, OpenStax, Introduction to Computer Science (whole free textbook), CC BY-NC-SA 4.0 · licence
Watch
-
1.1 Arrays in Data Structure | Declaration, Initialization, Memory representation
23 min · ≈ 104 MB · about ₦58
(opens youtube.com in a new tab)
-
Data Structures: Crash Course Computer Science #14
10 min · ≈ 45 MB · about ₦25
(opens youtube.com in a new tab)
-
Data Structures Explained: Arrays, Stacks, Graphs & More | Computer Science Fundamentals
11 min · ≈ 50 MB · about ₦28
(opens youtube.com in a new tab)
-
Data Structures - Arrays, Tuples, Fields, Records
10 min · ≈ 45 MB · about ₦25
(opens youtube.com in a new tab)
-
COMP2300 Data Structures: Records and Memory Allocation
1 h 30 min · ≈ 405 MB · about ₦227
(opens youtube.com in a new tab)
We link to free material and never copy it. Every link was opened by our team before it went up; video data is a rough guide at 360p.