Data Structures and Manipulation Flashcards
State the term used to describe data structures where the size is fixed when created.
Static
State an example of a static data structure.
Array
What are the advantages of using static data structures?
- Compiler can allocate space in memory during compilation
- Easy to program
- Easy to check for overflow
- Allows random access
What are the disadvantages of using static data structures?
- Program has to estimate maximum space needed
- Space can be wasted via over-estimation
What are the advantages of using dynamic data structures?
- Only uses the space needed at any time
- Makes efficient use of memory
- Storage no longer required can be returned to the system for other use
What are the disadvantages of using dynamic data structures?
- Difficult to program
- Can be slow to implement searches on data
- A linked list only allows serial access (time consuming for long lists)
Under what condition is a queue empty?
When front and next pointers point to the same location.
Write an algorithm to remove one data item from a queue.
- Check to see if the queue is not empty.
- If empty, report error and stop.
- Otherwise read the data pointed to by front pointer
- Increment front pointers
Write an algorithm to merge two sorted files.
- Open existing files
- Create new file
- Use points to identify records for comparison
- Compare records indicated to by pointers
- Copy earlier/smaller value record to new file
- Increment point from copied record
- Repeat until reach the end of one file
- Copy remaining records to new file
What is the main advantage to binary search?
- (usually) faster than serial because fewer items are checked/more efficient for large files
What is the main disadvantage for binary search?
- items must be in an order to allow appropriate items to be discarded
State two features of files that can be merged.
- records have a common key
- files each have records sorted into the same order
- same data type
Describe a queue data structure.
- first in, first out/FIFO/data items are added at one end & removed from the other
- two pointers are required
State uses of a queue in a computer system.
- spool queue/jobs waiting for printer
- job queue in batch processing system
- Handling of jobs in a round robin system
What validation must be done before adding data to a queue?
Check if full, if full report error and stop