1.1 Data Structures Flashcards
Data structure
A data structure is a group / set / collection of related data items / elements
Types of data structure
· queue · stack · (binary) tree · record · Linked lists · array
Top node of a binary tree
Root (node).
Advantage and disadvantage of binary trees
Advantage: faster to add a value / search for a value
Disadvantage: more complex to program / process / May slow processing/traversal if unbalanced.
Two dimensional array of:
Narberth, Cardiff, Pontypridd, Wrexham, Rhyl, Bangor, Denbigh
Table
Explain what is meant by the term linked list.
Describe one benefit and one drawback of using a linked list compared with using an array.
A linked list is a set of data elements, where each element contains:
· the data itself
· a pointer to the next element
Benefit :
New items can be inserted into a linked list without rearranging all the other elements
· If programmed dynamically uses memory more efficiently
Drawback :
· A linked list is more complex to program / manipulate than an array
· Extra programming is required to access the data in the opposite direction
· Can only be accessed in a linear manner.
Write a simple program using the assembly language commands in the table
above to demonstrate how two numbers can be added together and stored in a register
CLR R LOD R, 0001 LOD S, 0002 ADD R,S STR R 0003 CLR R
Fetch phase of the fetch execute cycle, making clear the role of the :
PC (program counter)
MAR (memory address register)
MDR (memory data register)
· The address of the next instruction is copied from the PC to the MAR
· The instruction is copied to the MDR
· The PC is incremented so that it holds the address of the next instruction.
Difference between searching for an item in an ordered list compared with searching an unordered list.
When searching an ordered list the search can be terminated when an item greater than the search value (or less than) is reached
When searching an unordered list the search cannot be terminated until the last item has been reached.
For an ordered list a binary search can be used.
Records
A record is a set of data Items all related to a single individual/entity it can contain data of different types.
Stacks
A stack is a small register that stores the address of the last program request a stack
Describe a computer application that is the most appropriate data structure to use and explain why it is the most appropriate data structure in this case
Example could be subprogram return addresses this is because of the idea of winding back nesting of sub programs
Queues
Q pointer is a pointer that points to a part of the queue. A queue will have two pointers front and rear
FIFO
Trees
The tree is a data structure that holds a large amount of data for the process of quick searching and producing different ordered lists. The tree needs to be balanced for the accesses to be quick
Advantages and disadvantages of a binary tree
And advantage is it is faster to search/add a value
A disadvantage is it is more complex to program/process