wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

DSA (QUIZ 6) Hashing, Graphs, Advanced Graph Algorithms, and DP

Total questions: 20

Worksheet time: 13mins

Name
Class
Date
1.

What is the main advantage of using a hash table?

a)

Data encryption

b)

Data compression

c)

Fast access to data

d)

Sequential search

2.

Which data structure is typically used to implement a hash table?

a)

Stack

b)

Array

c)

Queue

d)

Linked List

3.

In a graph, what does a 'directed edge' imply?

a)

Bi-directional connection

b)

One-way connection

c)

Weighted path

d)

No connection

4.

Which graph algorithm is used to find the shortest path from a source to all other vertices in a graph with positive weights?

a)

Prim's

b)

Dijkstra's

c)

Kruskal's

d)

Topological Sort

5.

Which of the following is a property of dynamic programming?

a)

Recursion without memory

b)

Overlapping subproblems

c)

Random selection

d)

Loop unrolling

6.

Which of the following is an example of a greedy algorithm?

a)

Bellman-Ford

b)

Knapsack (DP)

c)

Dijkstra's

d)

Floyd-Warshall

7.

Which graph representation is more space-efficient for sparse graphs?

a)

Adjacency matrix

b)

Adjacency list

c)

Incidence matrix

d)

Edge list

8.

What does the hash function do?

a)

Deletes duplicates

b)

Translates keys into indexes

c)

Randomly shuffles data

d)

Encrypts values

9.

Which algorithm is commonly used to schedule tasks with dependencies?

a)

DFS

b)

Kruskal's

c)

Topological Sort

d)

BFS

10.

Which is not true about Dynamic Programming?

a)

Solves problems optimally

b)

Uses memoization

c)

Only works on graphs

d)

Avoids recomputation

11.

Recursion is a process where a function calls itself.

a)

True

b)

False

12.

In an undirected graph, edges have direction.

a)

True

b)

False

13.

Hash collisions can be resolved using chaining or open addressing.

a)

True

b)

False

14.

Prim's and Kruskal's are used to find shortest paths.

a)

True

b)

False

15.

Dynamic Programming is useful when problems can be broken into independent subproblems.

a)

True

b)

False

16.

What is the output of this code?

int hashFunction(int key) { return key % 10; } cout << hashFunction(25);

(a)  

17.

Given a graph with 5 vertices and 4 edges, what is the minimum number of connections needed for it to be connected?

(a)  

18.

What is the time complexity of accessing an element in a hash table (average case)?

(a)  

19.

What is the base case in this recursive function?

int fact(int n) {

if (n == 0) return 1;

return n * fact(n - 1);

}

(a)  

20.

What will be printed by this DP Fibonacci function for fib(5)?

int fib(int n) {

if (n <= 1) return n;

return fib(n-1) + fib(n-2);

}

(a)