1 (a) Why is it important to study program running time, and what factors influence it?
Answer:
-
Importance:
- Predict performance, optimize resource use, and compare algorithms’ efficiency.
-
Factors:
- Input size ().
- algorithm complexity
- Hardware (CPU, memory).
- Programming language and compiler.
- Operating System
1 (b) Deduce the Satisfiability problem in Clique decision problem or vice versa
Video:
Question 2
Part(a) Prove that every graph G with maximum degree r is an induced subgraph of an r- regular graph
Part (B)
Question 4
Part (b)
Question 5
Part (b)
Question 6
Part (a) & (b)
Part (c)
Question 10
Part (a)
Depth-First Search (DFS) Algorithm
Algorithm (Recursive):
- Input: A graph G and a starting vertex v.
- Mark v as visited.
- For each neighbor w of v in G:
- If w is not visited:
- Recursively call DFS(G, w).
- If w is not visited:
Algorithm (Iterative using a Stack):
- Input: A graph G and a starting vertex v.
- Create an empty stack S.
- Push v onto S.
- Mark v as visited.
- While S is not empty:
- Pop a vertex u from S.
- For each neighbor w of u in G:
- If w is not visited:
- Mark w as visited.
- Push w onto S.
- If w is not visited:
Breadth-First Search (BFS) Algorithm
Algorithm (Iterative using a Queue):
- Input: A graph G and a starting vertex v.
- Create an empty queue Q.
- Enqueue v into Q.
- Mark v as visited.
- While Q is not empty:
* Dequeue a vertex u from Q.
* For each neighbor w of u in G:
- If w is not visited:
- Mark w as visited.
- Enqueue w into Q.
- If w is not visited: