Lecture 14 – Sequences & linear data structures Flashcards Preview

CS1005-Logic and computation > Lecture 14 – Sequences & linear data structures > Flashcards

Flashcards in Lecture 14 – Sequences & linear data structures Deck (8)
Loading flashcards...
1

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,

2

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

3

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.

4

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

5

What are stacks?

Its items are added and deleted on a last-in-first-out (LIFO) basis
PUSH to add
POP to remove

6

Applications of stacks?

Expression evaluation
Compilers – syntax evaluation
Recursion
FORTH language

7

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.

8

What is a Queue?

A queue is a FIFO type data structure
ENQUEUE-insertion
DEQUEUE-deletion