Lecture 14 – Sequences & linear data structures Flashcards

1
Q

What is an Array?

A

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,

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Advantages and Disadvantages of Arrays?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are Lists?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Advantages and Disadvantages of Lists?

A

Advantages:
Use space only as needed (assuming efficient Garbage Collection)

Disadvantages:
More complex & time-consuming operations required to locate, add and remove items

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are stacks?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Applications of stacks?

A

Expression evaluation
Compilers – syntax evaluation
Recursion
FORTH language

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is FORTH language?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is a Queue?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly