Score: 0/0

Question 1 of ∞

Describe three differences between static and dynamic data structures. Static data structures have a fixed size (determined at compile time), while dynamic data structures can grow or shrink in size as the program runs. Static data structures (typically) store data in consecutive memory locations, while dynamic data structures do not. Static data structures can waste storage space if the amount of data stored is small, whereas dynamic data structures only take up the exact amount of storage space required. Static data structures (typically) do not need pointers, whereas dynamic data structures use memory to store pointers to the next item.
Describe the steps of an enqueue operation on a circular queue. Check if the queue is full, with (rear_pointer + 1) % size == front_pointer. If it is, throw an error. Otherwise, set rear_pointer to (rear_pointer + 1) % size. Insert the item into the array at the index indicated by the new value of rear_pointer.
Explain how a single stack can be used to reverse the order of the items in a queue. Dequeue the queue and push the item to the stack, until the queue is empty. Pop items from the stack and enqueue them into the queue, until the stack is empty.
Diagram 1 shows a graph.

Diagram 1

Explain why the graph in Diagram 1 is not a tree. There are cycles, for example ACG, and therefore multiple paths between two nodes.

A programmer wants to implement two functions in his text-based software: undo and repeat.

The undo function will change the state of the text to how it was before the user's most recent action (e.g. changing a font) was carried out. The repeat function will apply the user's most recent action again.

Explain how the undo and repeat functions can be implemented using a single stack. A stack can be used to store the user's actions. Each time an action is completed it is pushed to the top of the stack. The undo function will pop the top item from the stack. The repeat function will peek at the top of the stack.
Explain the circumstances in which it is more appropriate to represent a graph using an adjacency list instead of an adjacency matrix. When the the graph is sparse (fewer edges between vertices). When edges are rarely changed. When the presence of a specific edge doesn't need to be tested frequently.
Explain how a key-value can be added to a hash table. The hashing algorithm is applied to the key. If this index of the array is empty, the pair is added there. Otherwise, a collision has occurred and a collision handling method must be used.
Describe the steps involved in rehashing a hash table. A larger hash table is created. Each value in the existing table is inserted into the new larger table, using a new hashing algorithm for the new table.
Calculate the angle between the vectors [2, 3] and [-1, 5]. Dot product = 13 Lengths are √13 and √26 cos(θ) = 1 / √2 θ = 45°