Answer: (c) Clear goals, inputs, processes, and outputs
Exercise 3 Solutions · Unit 3: Algorithms and Problem Solving
6 reading sections · 20 MCQs · 8 short · 5 long questions
Exercise 3 — Exercise 3: MCQs, short and long questions
Answer: (d) P
Answer: (b) They cannot be solved by any algorithm
Answer: (a) Non-deterministic Polynomial time
Answer: (b) Merge Sort
Answer: (c) Problems with overlapping subproblems and optimal substructure
Answer: (c) Bubble Sort
Answer: (c) O(V + E)
Answer: (b) Time taken as a function of input size
Answer: (c) Merge Sort
Answer: A well-defined problem has a clear goal, input, process and output (e.g. check whether a number is even). An ill-defined problem has vague or ambiguous goals and requirements (e.g. how to reduce poverty in Pakistan).
Answer: 1. Generate a possible solution. 2. Test it against the required conditions. 3. If it passes, stop with that solution. 4. Otherwise generate the next candidate and repeat until a solution is found or all candidates are exhausted.
Answer: Tractable problems can be solved in polynomial time (class P), so they stay practical as input grows (e.g. sorting, O(n log n)). Intractable problems need super-polynomial, often exponential or factorial time, so they become impractical for large inputs (e.g. the Travelling Salesman Problem).
Answer: A greedy algorithm builds a solution step by step, always taking the choice that looks best right now (locally optimal), hoping that these choices give the best overall (global) solution. Example: coin change using the largest coin first.
Answer: Dynamic Programming stores the results of subproblems so each is solved only once. Advantages: it avoids redundant calculations, turns many exponential-time solutions into polynomial-time ones, and guarantees an optimal answer for problems with optimal substructure.
Answer: BFS explores level by level with a queue, so it finds the shortest path (fewest edges) and suits shallow graphs. DFS goes deep first with a stack, uses less memory on deep graphs and suits mazes, puzzles and backtracking. Both are O(V + E).
Answer: Breaking a problem into smaller parts (decomposition) makes each part easier to understand, solve, test and reuse; the parts can be solved independently or by different people and then combined, as in divide and conquer.
Answer: Time complexity (how running time grows with input size, Big O), space complexity (memory used), correctness, and scalability/efficiency for large inputs.
Answer: The Halting Problem asks for one algorithm that can decide, for any program and input, whether the program stops or runs forever. Turing proved by contradiction that such an algorithm cannot exist: a program built to do the opposite of the decider's prediction about itself makes the decider wrong. Implications: some problems can never be solved by computers; perfect bug/infinite-loop detection is impossible.
Answer: A search problem asks to find an item or solution that meets given criteria in a collection (input: data + target; output: position or 'not found'). Linear search checks every item one by one – O(n), works on unsorted data. Binary search halves a sorted list each step – O(log n), far faster for large data but needs sorted data.
Answer: An optimization problem asks for the best solution (maximum or minimum of some measure such as cost, distance, time or profit) among many possible solutions, usually under constraints. Examples: shortest route (maps, TSP), knapsack/budget selection, coin change, scheduling, resource allocation, network routing.
Answer: Bubble Sort repeatedly passes through the list comparing adjacent elements and swapping them if out of order, until a pass makes no swap; its time complexity is O(n²) (best case O(n) with an early stop). Merge Sort (divide and conquer) is O(n log n) in all cases, so it is much faster for large lists, though it needs extra memory.
Answer: Time complexity measures how running time grows with input size; space complexity measures how memory use grows. Both are written in Big O. The choice depends on the situation: when speed matters and memory is plentiful choose the faster algorithm (e.g. Merge Sort, DP tables); when memory is limited choose the algorithm using less space even if slower.
Exercises in Unit 3
- Exercise 3 solutions – Exercise 3: MCQs, short and long questions(23)