Font size
WorksheetsDSA Final Exam
Total questions: 48
Worksheet time: 43mins
In the context of a Queue data structure, what does the acronym FIFO stand for?
First-Index, First-Output
Fast-Input, Fast-Output
First-In, First-Out
First-In, Fixed-Out
Which specific method is used to add an element to the end of a queue?
push
insert
enqueue
append
Which specific method is used to remove an element from the front of a queue?
pop
remove
delete
dequeue
In a queue, the position where new data is inserted is technically referred to as the ________?
Head
Back
Peak
Root
Which function allows you to inspect the element at the front of a queue without removing it?
view()
check()
front()
peek()
Queues are frequently used in computer science to simulate which real-world scenario?
A stack of trays in a cafeteria
A line of customers at a bank
A dictionary of words and definitions
A hierarchical family tree
Which sorting algorithm uses queues to categorize numbers into bins (0–9)?
Merge Sort
Quick Sort
Radix Sort
Heap Sort
A queue is a linear data structure most conceptually similar to which structure, but with restricted access?
Stack
Tree
Graph
Linked List
In the array-based Queue class, which JavaScript method is used inside the dequeue function?
slice()
splice()
shift()
unshift()
What is the fundamental difference between a Stack and a Queue?
Stack = LIFO, Queue = FIFO
Stack = FIFO, Queue = LIFO
Stack allows middle access, Queue does not
Stack has a size limit, Queue does not
If you enqueue "X", "Y", "Z" and then dequeue once, which is now at the front?
A. X
B. Y
C. Z
D. None
Why does the implementation use push() for enqueue and shift() for dequeue?
push() adds to end; shift() removes from beginning
push() adds to beginning; shift() removes from end
They only work with strings
unshift() and pop() require reversing
How does a Priority Queue differ from a normal Queue?
Removed by timestamp only
Removed by priority level
Can insert at both ends
Prevents duplicates
In Radix Sort, what is the purpose of the queues (bins)?
Store final sorted list
Group numbers by the current digit
Reverse digits
Compute averages
Why choose a Linked List over an Array?
O(1) access to any index
Arrays store more references
Linked Lists allow fast insert/delete
Arrays cannot store objects
A standard node in a singly linked list consists of:
value and index
element and next
data and previous
key and child
What is the primary function of the head node?
Stores count of nodes
Entry point with no data
Points to last node
Prevents memory overflow
How does traversal differ between an array and a linked list?
Arrays use pointers; lists use indices
Arrays use indices; lists use pointers
Lists follow links; arrays use indices
Lists follow links; arrays use indices
Lists only recursive; arrays iterative
No difference
What distinguishes a Doubly Linked List?
Has previous pointer
Two next pointers
Two head nodes
Circular last node
What happens structurally when a node is inserted between two existing nodes?
All subsequent nodes are shifted in memory.
The array size is doubled to accommodate data.
The pointers of the adjacent nodes are updated.
The entire list is copied to a new location.
What defines a Circularly Linked List?
It has no head node.
It can be traversed in both directions.
The last node points back to the head.
Nodes are arranged in a physical circle in memory.
What condition indicates the end of a standard Singly Linked List?
The current node is null.
The current node's value is -1.
The current node's next pointer is null.
The current node points to the head.
Why does a Doubly Linked List require more memory per node?
It stores two copies of the data.
It maintains an additional pointer field.
It uses larger integer types for indices.
It allocates a separate object for the head.
Which linked list best fits browser Back/Forward navigation?
Singly Linked List
Circularly Linked List
Doubly Linked List
Queue Linked List
In findPrevious(item), which condition is correct?
currNode.element == item
currNode.next.element == item
currNode.next == null
currNode.previous.element == item
What happens if you traverse a Circular List with while (currNode.next != null)?
Loop ends normally
Loop ends at head
Infinite loop
Error thrown
Correct syntax to create a new node:
var node = Node("Data");
var node = new Node("Data");
var node = new LinkedList("Data");
var node = create Node("Data");
Logic for advance(n):
currNode = currNode.next inside loop n times
currNode = currNode + n
currNode[n]
Recursively call find(n)
After setting newNode.next and newNode.previous, next step is:
current.next = newNode
newNode.next.previous = newNode
head.next = newNode
current.previous = newNode
Why use Array for Dictionary datastore?
Arrays do binary search
Objects cannot store string keys
When is a Dictionary more efficient than an Array?
Sequential numeric access
Frequent sorting
Finding values by non-numeric keys
Small datasets
Why does simpleHash fail for "Clayton" and "Raymond"?
Same length
Same ASCII sum
Modulo fails
Only uses 3 characters
What output showed betterHash was superior?
Alphabetical order
Keys converted to strings
All entries present; none lost
Faster time
In Separate Chaining, what changes?
Each slot stores an array
Array doubles
Replaced by BST
Collisions discarded
In Linear Probing, if index is occupied?
Use second hash
Use linked list
Check i+1, i+2, ...
Overwrite
Why set table size to a prime number?
Prevents overflow
More even distribution
Easy resizing
Required by charCodeAt
Why isn't Array.length enough for Dictionary entries?
Tracks only integer indices
Always 0
Dictionary uses Objects
Includes deleted items
How does Object.keys() help sorting?
Sorts values automatically
Returns keys for sorting
Converts keys to numbers
Builds a BST
Purpose of constant H in Horner’s method?
Multiplier to reduce collisions
Max characters
Default size
Key encryption
Perfect hash table retrieval complexity?
O(n)
O(log n)
O(1)
O(n log n)
Why does simpleHash fail with keys 10, 20, 30 & array size 10?
Too small
All mod 10 = 0 → collisions
Keys cannot use charCodeAt
Array too large
Why store both key and value in chaining?
(a)
When prefer Linear Probing over Chaining?
Array very small
Array can be twice number of elements
Memory must be minimal
Keys must be strings
How does total += H * total + charCode improve hashing?
Ignores character codes
Makes permutations different
Keeps total small
Removes need for modulo
Write the specific logic for the add(data) function in the Set class. Your code must check if the data already exists in this.dataStore using indexOf. If it does not exist, push it to the array and return true; otherwise, return false.
Write the JavaScript constructor function for a Node object used in a Binary Search Tree. It needs to accept data, left, and right as parameters and initialize this.show to a function that returns the data.
Complete the inOrder(node) function. Inside the check if (node != null), write the three lines of code required to traverse the tree in ascending order (Left, Print/Show, Right).
