Loading...
Choose a data structure from the operations the problem needs. Separate its logical behaviour from one particular representation in memory.
What you'll be able to do
An array groups indexed elements of an appropriate common type. One index can identify a position in a vector, while a pair of indices can identify a row and column in a matrix. A record instead groups named fields, potentially of different types, that describe one entity.
Check index conventions and bounds before accessing an array. Python lists are flexible sequences rather than fixed-size homogeneous arrays, so they can illustrate array-style access without being identical to every language’s array implementation. A two-dimensional representation must keep its row and column meaning consistent.
An abstract data type specifies the values and permitted operations without requiring callers to know how storage is arranged. A stack can offer push and pop whether implemented with an array and top pointer or dynamically linked nodes. Its last-in, first-out behaviour is the contract.
Data abstraction lets a caller use an operation while implementation details change. Choosing a representation still affects memory use and operation cost. A logical queue does not become a stack merely because both happen to use arrays internally.
A static structure has a fixed allocation or capacity under the stated model; a dynamic structure can change as data arrives or leaves. Fixed capacity can simplify indexing and avoid repeated allocation but may waste reserved space or become full. Dynamic growth improves flexibility but can carry allocation, resizing or pointer overhead.
In a nested Python list, repeated references can accidentally make several rows share the same object. Construct independent rows when each row should change separately. Test a small grid by changing one element and checking whether unrelated rows remain unchanged.
grid = [[0 for column in range(3)] for row in range(2)]
grid[0][1] = 7
print(grid)Scroll horizontally to see the full code or table.| Structure | Logical access | Example |
|---|---|---|
| Array | By position | scores[3] |
| Record | By named field | student.name |
| Stack ADT | By operation contract | push / pop |
Attempt the task before opening its worked response. Record each change of state, explain the rule used, and check the result against the original requirements. Code examples labelled Python 3 use that language’s conventions; pseudocode states its own assumptions.
Common mistakes to avoid
Key takeaways
Test yourself
Answer a few questions, then review anything you missed.
Start with the quiz above to check the key ideas. You can also choose another topic from the practice library.