WorksheetsMastering Data Structures
Total questions: 15
Worksheet time: 3hrs 30mins
What is the primary difference between an array and a linked list?
Arrays can grow dynamically, while linked lists have fixed sizes.
Linked lists store data in a single block, whereas arrays use multiple blocks.
Arrays require more memory overhead than linked lists for storage.
The primary difference is that arrays use contiguous memory for storage, while linked lists use nodes with pointers to connect elements.
How do you access an element in an array?
arrayName[index]
array.fetch(index)
array.get(index)
array[index]
What are the advantages of using a linked list over an array?
More straightforward memory allocation
Fixed size and slower insertions/deletions
Advantages of linked lists over arrays include dynamic size, efficient insertions/deletions, and better memory management.
Easier to access elements randomly
Explain how a stack operates and its main principles.
A stack operates on the FIFO principle, allowing 'enqueue' and 'dequeue' actions.
A stack operates on the LIFO principle, supporting 'push' and 'pop' operations.
A stack uses a circular buffer to manage data with 'insert' and 'remove' methods.
A stack functions on a random access principle, enabling 'add' and 'delete' commands.
What is the difference between a stack and a queue?
A stack allows random access, while a queue does not.
A stack is a linear structure, while a queue is a non-linear structure.
A stack uses FIFO, while a queue uses LIFO.
A stack uses LIFO, while a queue uses FIFO.
Describe a real-world scenario where a queue would be used.
A traffic light sequence.
A line of people waiting for a bus.
A waiting list for a restaurant.
A grocery store checkout line.
What is a graph, and how is it different from a tree?
A graph is a linear structure with no cycles, while a tree can have multiple roots.
A graph consists of vertices and faces, while a tree is a circular graph with multiple connections.
A graph is a set of points with no connections, while a tree is a connected graph with loops.
A graph is a collection of nodes connected by edges, while a tree is a hierarchical, acyclic graph with a single root and one parent per node.
What are the two main types of graphs?
Directed graphs and Undirected graphs
Weighted graphs and Unweighted graphs
Linear graphs and Non-linear graphs
Cyclic graphs and Acyclic graphs
How do you represent a graph in memory?
Graphs can be represented using hash tables or queues.
Graphs can be represented using arrays or stacks.
Graphs can be represented using binary trees or linked lists.
Graphs can be represented using adjacency lists or adjacency matrices.
What is the time complexity of adding an element to a stack?
O(n^2)
O(n)
O(1)
O(log n)
Explain the concept of depth-first search in graphs.
Depth-first search (DFS) is an algorithm that explores as far as possible along each branch before backtracking.
Depth-first search (DFS) is a method that randomly selects paths without backtracking.
Depth-first search (DFS) is a technique that only explores the shortest path in a graph.
Breadth-first search (BFS) is an algorithm that visits all neighbors before going deeper.
What is a circular queue, and how does it differ from a regular queue?
A circular queue requires more memory than a regular queue for its operations.
A circular queue is a linear structure that does not wrap around, unlike a regular queue.
A circular queue is slower than a regular queue due to its complex structure.
A circular queue allows efficient use of space by wrapping around, while a regular queue can waste space and requires shifting elements.
How can you implement a stack using two queues?
Implement a stack using two queues by pushing elements to one queue and using the other queue to reverse the order for popping.
Use two stacks to implement a queue by alternating push and pop operations.
Create a stack by merging two queues and using the first for popping.
Implement a stack using a single queue by rotating elements during pop.
What is the significance of the head and tail in a linked list?
The head connects to the middle, and the tail links to the next node.
The head is the starting point for traversal, and the tail indicates the end of the list.
The head is used for data storage, while the tail is for sorting.
The head stores the last element, and the tail holds the first element.
Describe the breadth-first search algorithm and its applications.
Depth-first search (DFS) is an algorithm for sorting data structures, commonly used in data compression and file organization.
Breadth-first traversal (BFT) is a method for analyzing linear data, often applied in data encryption and image processing.
Breadth-first exploration (BFE) is a technique for optimizing search algorithms, frequently utilized in machine learning and data mining.
Breadth-first search (BFS) is an algorithm for traversing or searching tree or graph data structures, widely used in shortest path finding, network broadcasting, and puzzle solving.
