Component 1 Flashcards
What is the opcode and operand?
The opcode is the first part of a binary instruction and is the actual operation we need to do such as ADD, STA, DAT or whatever it may be. The operand is the second half of the binary instruction and is the actual data to be dealt with say ADD 0011 would be the instruction to add 3 to the current value of the ACC
What is the purpose of DAT in assembly?
DAT is used to name a data location, sort of like naming a variable in a high level language apart from the fact that it is often done at the end of the program
What is the purpose of STA, LDA and BRP in assembly language?
STA = Store and will store the contents of the value of the ACC in the given memory address in the operand. LDA = Load what is referenced by the given memory address into the accumulator and BRP = Branch is positive or negative meaning jump to the address given if the accumulator value is >= 0
What does it mean for a data structure to be mutable?
A mutable data structure is one that can have it’s contents changed during runtime
Is an array static or dynamic and what do they both mean?
An array is static meaning it’s length cannot be changed during runtime and dynamic means the length of the data structure can be changed during runtime
Give an advantage of an immutable data structure and an example of one
It has no opportunity to introduce runtime errors if the contents of the data structure cannot be changed. An example of this is a tuple
What is immediate addressing?
Immediate addressing is where the actual value of the operand is the bit of data that we want
What is direct addressing?
Direct addressing is where the opcode is a pointer to a memory address which contains the value of the data that we want
What is indirect addressing?
Indirect addressing is where the operand is a pointer to a memory location which is then another pointer to a final memory location which contains the data or instruction that we want
What is an advantage of indirect addressing?
It allows us to use more memory addresses than with direct addressing as there may be more bits available
What is indexed addressing?
Indexed addressing is where the operand value + some constant in the index register is the pointer for the memory address that we want
What is an advantage of indexed addressing?
It is very useful for large data structures like arrays as we only need to specify the start with the constant in the index register
What is the time complexity of searching through, an array, a list
They are both O(n) normally as we check each individual element but O(1) at the best case which is when we know where the value we are looking for is
What is the time complexity of a binary search
It is O(logn) as it uses a divide and conquer algorithm
How does a hash table work?
An input is run through a hashing algorithm to give a unique hash which then corresponds to a given index in an array which the data can then be put into
What is the time complexity of a hash table and why?
O(1) constant as it only takes a constant amount of time to run an input through a hash table which gives the index we need. This only changes to O(n) if we have collisions as we would need to check through the overflow list
What are collisions in a hash table?
Collisions are where two inputs with two distinct hashes correspond to the same array index meaning we need to put two items into one array index which isn’t possible, so we fix this by creating an overflow list which any overflows are put into
What is the algorithm for adding and removing from a hash table?
Adding an item: first we run the input through a hash algorithm and correspond that to an array index, then we check if that array index is free and if it is then we simply add that value to the given index. If it isn’t then we go to the overflow array and add it to the next free index in that array.
Removing an item: first we run the input through the hash algorithm and get a corresponding array index, then we check if the value in that index is the one we want to remove and if it is then simply remove it, if not we start traversing the overflow array until we find the one we want
What is a stack?
A stack is a last in first out data structure where items are pushed to the top of the stack and popped off the top, and so only the top of it can be accessed at any given time.
What is a queue?
A queue is a first in first out data structure meaning, you enqueue items to the back of a queue, and dequeue them from the front. This means it consists of a head and tail pointer which indicate the back and front a queue
What are the applications of a stack?
Anything that requires stepping back like the undo function or back button on a web browser, also a function call so we know which line number to return to
What are the applications of a queue?
Print queues, or process scheduling in the CPU
What is a graph?
A graph is a data structure consisting of vertices and edges where each node is connected with a pointer to any number of other nodes, a node with only one connection is known as an edge, we can have undirected graphs where connections go both ways, or directed where you can only traverse between two nodes in one way