Lecture 14 – Sequences & linear data structures Flashcards
What is an Array?
Fixed-size declared in advance
Initialize all positions to some value [often ‘0’ or null_string]
Items accessed by position (index) number, often starting at 0
- Can read/overwrite/remove any item by immediate access to its position
Multiple dimensions:
1D,2D,3D,
Advantages and Disadvantages of Arrays?
Advantages:
easy to create, easy to access items
Disadvantages:
Fixed-size →
-Need to set aside maximum space in memory that could be possibly needed
-Cannot extend/ reduce size during computation
What are Lists?
Dynamic size – can increase/decrease the size as required during computation
Initialise to the empty list ‘[]’
Access items by traversing down the list until they are found; no concept of indexing and access by index.
Advantages and Disadvantages of Lists?
Advantages:
Use space only as needed (assuming efficient Garbage Collection)
Disadvantages:
More complex & time-consuming operations required to locate, add and remove items
What are stacks?
Its items are added and deleted on a last-in-first-out (LIFO) basis
PUSH to add
POP to remove
Applications of stacks?
Expression evaluation
Compilers – syntax evaluation
Recursion
FORTH language
What is FORTH language?
Stack-based, extensible language without type-checking.
Uses “reverse Polish” (postfix) arithmetic notation
Real-time programming language originally developed to control telescopes.
Can compile itself into a new compiler!
Edit time error checking and compiling
Extremely efficient thread-based language.
Can be used to debug itself!
Many commercial applications: language translators, animation (movies, Disneyland), hard disk controllers.
What is a Queue?
A queue is a FIFO type data structure
ENQUEUE-insertion
DEQUEUE-deletion