wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

PUTANGINA MO

Total questions: 38

Worksheet time: 24mins

Name
Class
Date
1.

Given the following tentative distances just before extraction: d[a] = 0, d[b] = 3, d[c] = 2, d[d] = 5. Which node is extracted next?

a)

a

b)

b

c)

c

d)

d

2.

Consider building a min-heap (where parent ≤ children) from the elements inserted in that order into an array-based heap starting empty at index 1. After all insertions and heapifications, what is the array content (indices 1 to 6), and which property holds?

a)

Root is minimum, last level filled left-to-right.

b)

Heapify swaps only with larger child in min-heap.

c)

Smallest element always at a leaf after insert.

d)

Complete binary tree shape preserved.

3.

Which traversal guarantees discovering all vertices reachable from a source using a queue and explores by layers of distance?

a)

Dijkstra’s algorithm

b)

Breadth-first search (BFS)

c)

Depth-first search (DFS)

d)

Kruskal’s algorithm

4.

Suppose we extract vertex u with d[u] = 7. It has neighbors v, w, x, y, z, and a with edge weights w(u,v) = 2, w(u,w) = 4, w(u,x) = 3, w(u,y) = 5, w(u,z) = 1, and w(u,a) = 6. Current distances: d[v] = 10, d[w] = 13, d[x] = 11, d[y] = 14, d[z] = 9, d[a] = 15. After relaxing all edges from u, which statement is true?

a)

d[v] = 10, d[w] = 13, d[x] = 11, d[y] = 14, d[z] = 9, d[a] = 15

b)

d[v] = 9, d[w] = 11, d[x] = 10, d[y] = 12, d[z] = 8, d[a] = 15

c)

d[v] = 8, d[w] = 12, d[x] = 9, d[y] = 10, d[z] = 8

d)

d[v] = 9, d[w] = 11, d[x] = 10, d[y] = 12, d[z] = 8, d[a] = 13

5.

In open addressing with linear probing, what happens after a collision at an index?

a)

A new bucket is allocated and appended to the array

b)

A new hash function is sampled for the collided key

c)

Keys are moved into a linked list at that index

d)

The next index is probed sequentially until an empty slot is found

6.

What does entry A_ij represent in the adjacency matrix A of a simple, unweighted directed graph?

a)

Whether there is an edge from j to i

b)

The degree of vertex j

c)

The number of vertices adjacent to vertex i

d)

Whether there is an edge from i to j

7.

A hash table has size 10. The String "MANGO" has a hashCode of ____. What bucket does it go to?

a)

0

b)

5

c)

1

d)

9

8.

What is a collision in a hash table?

a)

When a key is deleted from the table

b)

When two keys map to the same bucket index

c)

When a key maps outside the bucket array bounds

d)

When two keys produce different hash codes

9.

You perform a DFS traversal starting from vertex s in a directed graph. During traversal, you reach vertex u and then vertex v via an edge (u,v). Later, you find another edge (v,u) that was not used during traversal. What is true about the DFS tree?

a)

The edge (v,u) will be part of the DFS tree

b)

The edge (v,u) will be a forward edge

c)

The edge (v,u) will be a cross edge

d)

The edge (v,u) will be a back edge

10.

Which operation breaks the heap-order property in a min-heap and thus must be followed by a sift-down?

a)

Decreasing a key of an internal node

b)

Replacing the root with the last element after extract-min

c)

Swapping two sibling leaves

d)

Inserting a new key at the end and sifting up

11.

Given d[u] = 9, neighbors v and z have weights w(u,v) = 1 and w(u,z) = 4, while d[v] = 11 and d[z] = 12. After relaxation, what is true?

a)

d[v] = 9, d[z] = 12

b)

d[v] = 10, d[z] = 12

c)

d[v] = 11, d[z] = 13

d)

d[v] = 10, d[z] = 9

12.

Suppose you perform a BFS traversal starting from vertex s in an undirected graph. During traversal, you visit vertex u before vertex v. Later, you find that there is a direct edge (u,v) with weight 2, but v was discovered earlier than u in the BFS tree. What is the most likely reason?

a)

BFS does not guarantee shortest paths in weighted graphs

b)

The edge (u,v) was not considered during BFS

c)

The graph contains a cycle that affected the order

d)

BFS always visits vertices in increasing order of their distance from s

13.

Which statement best characterizes a minimum spanning tree (MST) in a connected, undirected, weighted graph?

a)

It maximizes the sum of edge weights.

b)

It contains all edges of minimum weight in the graph.

c)

It minimizes the number of edges.

d)

It connects all vertices with no cycles and minimum total weight.

14.

Which approach efficiently updates an MST when a single edge weight decreases?

a)

Add the edge, and if it creates a cycle with the current MST, remove the heaviest edge on that cycle

b)

Switch to shortest path trees since they update faster

c)

Recompute the MST from scratch using Kruskal’s algorithm

d)

Remove all edges adjacent to the changed edge and rebuild locally

15.

Suppose we extract vertex u with d[u] = 7. It has neighbors v and x with edge weights w(u,v)=2 and w(u,x)=5. The current distances are d[v]=11 and d[x]=12. After relaxing edges from u to v and x, what happens?

a)

d[v] remains 11 and d[x] becomes 10

b)

d[v] becomes 9; d[x] becomes 12

c)

d[v] becomes 9; d[x] becomes 10

d)

d[v] becomes 11 and d[x] becomes 12

16.

What is the primary goal of a hash function in a hash table?

a)

To sort keys in ascending order.

b)

To compress data to a smaller size.

c)

To encrypt data for confidentiality.

d)

To map keys uniformly to indices.

17.

Which component directly stores the key–value pairs in a separate chaining hash table?

a)

Universal hash family

b)

Load factor controller

c)

Open addressing probe sequence

d)

Bucket array entries that hold linked lists or dynamic arrays

18.

Which condition breaks Dijkstra’s correctness about finalized nodes having the lowest cumulative cost?

a)

Use of adjacency lists instead of matrices

b)

Multiple edges between the same pair of nodes

c)

Presence of zero-weight edges

d)

Presence of negative edge weights

19.

In linear probing:

A hash table has size 10. Which of the following is the correct hash index for the key 65?

a)

7

b)

3

c)

9

d)

5

20.

You are using Prim’s algorithm to build an MST starting from vertex s. At some point, you add edge (u,v) with weight 4 to the MST. Later, you find another edge (u,w) with weight 3 that connects u to a vertex not yet in the MST. What happens next?

a)

The edge (u,w) is skipped because u is already in the MST

b)

The edge (u,w) is added to the MST

c)

The algorithm stops and reports an error

d)

The edge (u,w) replaces (u,v) in the MST

21.

In a hash table using separate chaining, what happens when two keys collide?

a)

Both keys are stored in a bucket structure.

b)

Keys are merged into a single entry.

c)

One key is discarded

d)

The table is rehashed immediately.

22.

Which statement best defines a simple undirected graph?

a)

A graph where every edge has a direction

b)

A graph in which every vertex has the same degree

c)

A graph in which multiple edges between the same pair of vertices are allowed

d)

A graph with no parallel edges and no self-loops

23.

In Dijkstra’s algorithm, what is the first invariant maintained at every iteration?

a)

All neighbors of the current node already have finalized distances

b)

The current node has the globally minimal tentative distance among all unvisited nodes

c)

The sum of all tentative distances strictly decreases each iteration

d)

All edges incident to finalized nodes are removed from the graph

24.

A graph is represented using an adjacency list. You notice that vertex u has a list containing vertices v, w, and x, but vertex v’s list does not contain u. What does this imply about the graph?

a)

The graph is undirected and the lists should be symmetric

b)

The graph is directed and there is an edge from u to v, but not from v to u

c)

The adjacency list representation is incomplete

d)

The graph is weighted and the lists only show outgoing edges

25.

Which of the following lists contains all the edges in the graph?

a)

A→B, B→C, C→D, D→A

b)

A→C, B→D, C→B, D→A

c)

A→B, A→D, B→C, C→D, D→B

d)

A→B, A→C, B→D, C→D, D→A

26.

A hash table has a capacity of 10. The String "BAT" has a computed hashCode of ____. What is its index?

a)

0

b)

5

c)

7

d)

2

27.

What is the role of the modulus operation in computing a bucket index from a hash code?

a)

It ensures the index stays within the bucket array bounds

b)

It eliminates all collisions

c)

It randomizes the hash code

d)

It sorts the indices

28.

Which property of linear probing helps ensure that previously unused table slots are eventually utilized?

a)

Primary clustering

b)

Double hashing step sizes

c)

Separate chaining with lists

d)

Sequential slot exploration

29.

Which of the following is NOT a typical application of a weighted graph?

a)

Cost of traveling between nodes

b)

Distance between cities

c)

Time to complete tasks

d)

Color of the vertices

30.

Which statement best defines a minimum spanning tree (MST)?

a)

A subgraph with the fewest edges regardless of connectivity

b)

A tree that connects all vertices with no cycles and minimum total edge weight

c)

A directed acyclic graph with minimum in-degree

d)

A path that visits every vertex exactly once with minimum cost

31.

Why do clusters in linear probing tend to grow?

a)

Deletions automatically break clusters into smaller parts

b)

Resizing immediately removes all clusters

c)

The hash function prevents consecutive occupied cells

d)

More insertions probe into existing clusters and are likely to stop at their ends

32.

Suppose we are running Dijkstra’s algorithm and extract vertex u with d[u] = 8. It has neighbors v, w, x, y, z, and a with edge weights w(u,v) = 3, w(u,w) = 2, w(u,x) = 4, w(u,y) = 1, w(u,z) = 5, and w(u,a) = 6. Current distances: d[v] = 12, d[w] = 11, d[x] = 10, d[y] = 10, d[z] = 15, d[a] = 14. However, after relaxing all edges from u, we notice that d[y] remains unchanged. What is the most likely reason?

a)

The relaxation process skipped y due to a programming error

b)

The edge (u,y) has a negative weight

c)

d[u] + w(u,y) is not less than d[y]

d)

Vertex y was already processed and removed from the queue

33.

Which of the following lists contains all the edges in the graph?

a)

A→B, A→E, B→C, C→D, D→A, E→C

b)

A→B, B→C, C→D, D→E, E→A

c)

A→C, B→D, C→E, D→B, E→A

d)

A→B, A→C, B→E, C→D, D→A

34.

Suppose a graph has 5 vertices and is represented using an adjacency matrix. You notice that the entry at row 2, column 4 is 1, but the entry at row 4, column 2 is 0. What is the most likely explanation?

a)

The adjacency matrix is incorrectly filled

b)

The graph is directed and there is an edge from vertex 2 to vertex 4 only

c)

The graph is undirected and the matrix is symmetric

d)

The graph is weighted and the values represent weights

35.

In a sparsely populated hash table, what advantage does linear probing offer in terms of index utilization?

a)

It compacts keys, minimizing unused slots between them

b)

It leaves gaps to reduce clustering

c)

It uses a secondary structure to reuse empty slots

d)

It requires rehashing after each insertion

36.

In a min-heap with array (indices 1-6), after extract-min (remove root 10, move 30 to root, heapify-down), what is the final array, assuming heapify swaps with the smaller child?

a)

Swapped down right path.

b)

Swapped with left child only.

c)

No swap needed post-move.Links to an external site.

d)

Heapify skips comparisons.

37.

What is the primary purpose of the hash code produced by a hash function?

a)

To compress the key for serialization

b)

To sort keys in ascending order

c)

To index into a bucket array.

d)

To encrypt the key for secure storage

38.

What does Dijkstra’s algorithm compute when all edge weights are nonnegative?

a)

A maximum flow

b)

A minimum spanning tree

c)

Single source shortest path distance

d)

All-pairs shortest paths