4.2 Data Structures Flashcards
1
Q
Static vs Dynamic Data Structures
- when size is determined
- storage
A
- static: storage size determined before program is run (fixed size)
- dynamic: can change size during run time
- static: can waste storage space is number of data items is small compared to size
- dynamic: only take up amount of storage space required
- dynamic: need memory to store pointer to next items
2
Q
Enumerated (definition)
A
In the form of a list
3
Q
Arrays (2)
A
- elements must be of the same data type
- objects are mutable
4
Q
Lists (3)
A
- elements can be of different data types
- objects are mutable
- is a dynamic data structure
5
Q
Tuples (3)
A
- elements can be of different data types
- objects are immutable
- more efficient than lists since are immutable
6
Q
Text Files can only store
A
Strings
7
Q
Advantage of Text Files
A
They can be created, altered or prepared independently from the program
8
Q
Binary Files (3)
A
- hard for human to understand
- are directly compatible with the computer
- tend to be more secure as without correct definitions would be difficult to convert data into meaningful information
9
Q
CSV Files (4)
A
- comma separated files
- type of text file used to store a set of records
- each record is stored on a single line
- each field in the record is separated by a comma
10
Q
Types of Access of Files
- read
- write
- append
- read binary file
- write to binary file
A
- r = read
- w = write (overwrites entire file)
- a = append
- rb = read binary file
- wb = write to binary file
11
Q
Queues
- Acronym
- Number of Pointers
A
- FIFO (First In First Out)
- 2 pointers: rear and front
12
Q
Linear Queues
- type of structure
- queue = empty if …
- disadvantage
A
- static data structure
- queue = empty if front > rear
- dis: limited amount of space
12
Q
Circular Queues
- definition
- what pointers store
A
- queue which has a fixed amount of space but where the end of the queue is connected to the front
- front points to element of array which should be removed next
- rear points to last element added
13
Q
Priority Queues (2 + Enqueue)
A
- when elements are assigned they are ordered according to some rule
- each item is assigned a priority as it is added to the queue
- enqueue: same as linear queue, except value is inserted into correct position according to a given priority
14
Q
Enqueue Algorithm
A
- check if full (if rear + 1 = front)
- if not full
- increment rear by 1
- add item at the location indicated by the value of rear pointer
15
Q
Push Function + Algorithm
A
- adds data pushed to top of stack
- check isFull()
- if not full
- increment top pointer by 1
- insert data at location indicated by the value of the top pointer
15
Q
Stack
- type of structure
- acronym
- no. pointers
A
- static data structure
- LIFO (Last In First Out)
- 1 pointer: top
15
Q
Dequeue Algorithm
A
- check if empty (if front > rear)
- if not empty
- get item at location indicated by front pointer
- increment value of front pointer by 1
- return item