wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

DSA Final Exam

Total questions: 48

Worksheet time: 43mins

Name
Class
Date
1.

In the context of a Queue data structure, what does the acronym FIFO stand for?

a)

First-Index, First-Output

b)

Fast-Input, Fast-Output

c)

First-In, First-Out

d)

First-In, Fixed-Out

2.

Which specific method is used to add an element to the end of a queue?

a)

push

b)

insert

c)

enqueue

d)

append

3.

Which specific method is used to remove an element from the front of a queue?

a)

pop

b)

remove

c)

delete

d)

dequeue

4.

In a queue, the position where new data is inserted is technically referred to as the ________?

a)

Head

b)

Back

c)

Peak

d)

Root

5.

Which function allows you to inspect the element at the front of a queue without removing it?

a)

view()

b)

check()

c)

front()

d)

peek()

6.

Queues are frequently used in computer science to simulate which real-world scenario?

a)

A stack of trays in a cafeteria

b)

A line of customers at a bank

c)

A dictionary of words and definitions

d)

A hierarchical family tree

7.

Which sorting algorithm uses queues to categorize numbers into bins (0–9)?

a)

Merge Sort

b)

Quick Sort

c)

Radix Sort

d)

Heap Sort

8.

A queue is a linear data structure most conceptually similar to which structure, but with restricted access?

a)

Stack

b)

Tree

c)

Graph

d)

Linked List

9.

In the array-based Queue class, which JavaScript method is used inside the dequeue function?

a)

slice()

b)

splice()

c)

shift()

d)

unshift()

10.

What is the fundamental difference between a Stack and a Queue?

a)

Stack = LIFO, Queue = FIFO

b)

Stack = FIFO, Queue = LIFO

c)

Stack allows middle access, Queue does not

d)

Stack has a size limit, Queue does not

11.

If you enqueue "X", "Y", "Z" and then dequeue once, which is now at the front?

a)

A. X

b)

B. Y

c)

C. Z

d)

D. None

12.

Why does the implementation use push() for enqueue and shift() for dequeue?

a)

push() adds to end; shift() removes from beginning

b)

push() adds to beginning; shift() removes from end

c)

They only work with strings

d)

unshift() and pop() require reversing

13.

How does a Priority Queue differ from a normal Queue?

a)

Removed by timestamp only

b)

Removed by priority level

c)

Can insert at both ends

d)

Prevents duplicates

14.

In Radix Sort, what is the purpose of the queues (bins)?

a)

Store final sorted list

b)

Group numbers by the current digit

c)

Reverse digits

d)

Compute averages

15.

Why choose a Linked List over an Array?

a)

O(1) access to any index

b)

Arrays store more references

c)

Linked Lists allow fast insert/delete

d)

Arrays cannot store objects

16.

A standard node in a singly linked list consists of:

a)

value and index

b)

element and next

c)

data and previous

d)

key and child

17.

What is the primary function of the head node?

a)

Stores count of nodes

b)

Entry point with no data

c)

Points to last node

d)

Prevents memory overflow

18.

How does traversal differ between an array and a linked list?

a)

Arrays use pointers; lists use indices

b)

Arrays use indices; lists use pointers

19.

Lists follow links; arrays use indices

a)

Lists follow links; arrays use indices

b)

Lists only recursive; arrays iterative

c)

No difference

20.

What distinguishes a Doubly Linked List?

a)

Has previous pointer

b)

Two next pointers

c)

Two head nodes

d)

Circular last node

21.

What happens structurally when a node is inserted between two existing nodes?

a)

All subsequent nodes are shifted in memory.

b)

The array size is doubled to accommodate data.

c)

The pointers of the adjacent nodes are updated.

d)

The entire list is copied to a new location.

22.

What defines a Circularly Linked List?

a)

It has no head node.

b)

It can be traversed in both directions.

c)

The last node points back to the head.

d)

Nodes are arranged in a physical circle in memory.

23.

What condition indicates the end of a standard Singly Linked List?

a)

The current node is null.

b)

The current node's value is -1.

c)

The current node's next pointer is null.

d)

The current node points to the head.

24.

Why does a Doubly Linked List require more memory per node?

a)

It stores two copies of the data.

b)

It maintains an additional pointer field.

c)

It uses larger integer types for indices.

d)

It allocates a separate object for the head.

25.

Which linked list best fits browser Back/Forward navigation?

a)

Singly Linked List

b)

Circularly Linked List

c)

Doubly Linked List

d)

Queue Linked List

26.

In findPrevious(item), which condition is correct?

a)

currNode.element == item

b)

currNode.next.element == item

c)

currNode.next == null

d)

currNode.previous.element == item

27.

What happens if you traverse a Circular List with while (currNode.next != null)?

a)

Loop ends normally

b)

Loop ends at head

c)

Infinite loop

d)

Error thrown

28.

Correct syntax to create a new node:

a)

var node = Node("Data");

b)

var node = new Node("Data");

c)

var node = new LinkedList("Data");

d)

var node = create Node("Data");

29.

Logic for advance(n):

a)

currNode = currNode.next inside loop n times

b)

currNode = currNode + n

c)

currNode[n]

d)

Recursively call find(n)

30.

After setting newNode.next and newNode.previous, next step is:

a)

current.next = newNode

b)

newNode.next.previous = newNode

c)

head.next = newNode

d)

current.previous = newNode

31.

Why use Array for Dictionary datastore?

a)

Arrays do binary search

b)

Objects cannot store string keys

32.

When is a Dictionary more efficient than an Array?

a)

Sequential numeric access

b)

Frequent sorting

c)

Finding values by non-numeric keys

d)

Small datasets

33.

Why does simpleHash fail for "Clayton" and "Raymond"?

a)

Same length

b)

Same ASCII sum

c)

Modulo fails

d)

Only uses 3 characters

34.

What output showed betterHash was superior?

a)

Alphabetical order

b)

Keys converted to strings

c)

All entries present; none lost

d)

Faster time

35.

In Separate Chaining, what changes?

a)

Each slot stores an array

b)

Array doubles

c)

Replaced by BST

d)

Collisions discarded

36.

In Linear Probing, if index is occupied?

a)

Use second hash

b)

Use linked list

c)

Check i+1, i+2, ...

d)

Overwrite

37.

Why set table size to a prime number?

a)

Prevents overflow

b)

More even distribution

c)

Easy resizing

d)

Required by charCodeAt

38.

Why isn't Array.length enough for Dictionary entries?

a)

Tracks only integer indices

b)

Always 0

c)

Dictionary uses Objects

d)

Includes deleted items

39.

How does Object.keys() help sorting?

a)

Sorts values automatically

b)

Returns keys for sorting

c)

Converts keys to numbers

d)

Builds a BST

40.

Purpose of constant H in Horner’s method?

a)

Multiplier to reduce collisions

b)

Max characters

c)

Default size

d)

Key encryption

41.

Perfect hash table retrieval complexity?

a)

O(n)

b)

O(log n)

c)

O(1)

d)

O(n log n)

42.

Why does simpleHash fail with keys 10, 20, 30 & array size 10?

a)

Too small

b)

All mod 10 = 0 → collisions

c)

Keys cannot use charCodeAt

d)

Array too large

43.

Why store both key and value in chaining?

(a)  

44.

When prefer Linear Probing over Chaining?

a)

Array very small

b)

Array can be twice number of elements

c)

Memory must be minimal

d)

Keys must be strings

45.

How does total += H * total + charCode improve hashing?

a)

Ignores character codes

b)

Makes permutations different

c)

Keeps total small

d)

Removes need for modulo

46.

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.

4 lines
47.

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.

4 lines
48.

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).

4 lines