Study Atlas › Computer Science › Data structures
Data structures: arrays, linked lists, stacks, queues
Ways to organise data so operations are efficient.
Edited by Alex C, EduAlx · Sources cited below
Explanation
Arrays give O(1) indexed access; linked lists give O(1) insertion at a known node. Stacks are last-in-first-out (function calls, undo); queues are first-in-first-out (scheduling, BFS). Choosing the right structure often matters more than micro-optimising code.
Example
Checking balanced brackets '({[]})' with a stack: push openers, pop and match closers.
Code
def balanced(s):
pairs = {')':'(', ']':'[', '}':'{'}
st = []
for ch in s:
if ch in '([{': st.append(ch)
elif ch in pairs:
if not st or st.pop() != pairs[ch]: return False
return not st
How it works, step by step
- Identify required operations
- Compare costs per structure
- Choose the structure
- Implement and test edge cases
Open the interactive page with diagrams →
People behind it
- Donald Knuth (b. 1938), Computer science, USA: Stanford professor; author of The Art of Computer Programming and creator of TeX. Turing Award 1974.
- Niklaus Wirth
References
- N. Wirth, Algorithms + Data Structures = Programs, Prentice-Hall, 1976.
Textbooks
- Introduction to Algorithms, Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, Clifford Stein (MIT Press, 4th ed. 2022). 'CLRS', the standard algorithms text.
- The Art of Computer Programming (Vols. 1–4B), Donald E. Knuth (Addison-Wesley, 1968–2023). Monumental work on algorithms.
- Algorithms, Robert Sedgewick, Kevin Wayne (Addison-Wesley, 4th ed. 2011). Practical algorithms with Java code.
Related topics
Hash tablesHeaps and priority queuesTrees and binary search treesSorting algorithms (quicksort, mergesort, heapsort)Algorithms and Big-O complexityGraph algorithms: BFS, DFS and Dijkstra's shortest pathError-detecting and error-correcting codesDynamic programmingHuman–computer interaction and usabilityTuring machines and computability