Skip to content
πŸ“š Free notes, MCQ tests & past papers β€” FBISE & BISE Rawalpindi
πŸ“’ Latest Updates

1st Year Computer Science Chapter 3 Algorithms and Problem Solving: Exercise Solutions 2027 (Punjab Board / BISE Rawalpindi)

Reviewed by Sadia Shahid, Senior Science teacher (Maths, Physics, Chemistry, Biology, Computer Science)

These are the solved end-of-unit exercises for Unit 3, Algorithms and Problem Solving, from the PECTAA Computer Science and Entrepreneurship-11 textbook used by BISE Rawalpindi, Lahore and the other Punjab boards. Every answer is written from the text of the unit, for the 1st Year (HSSC Part I) Annual Examination 2027. The textbook calls its chapters “units”.

This unit covers computational problems and their types, the generate-and-test method, solvable and unsolvable problems, tractable and intractable problems, time and space complexity, algorithm design techniques, and common algorithms such as Bubble Sort, Selection Sort, Linear and Binary Search, BFS and DFS.

Unit 3: Algorithms and Problem Solving
Class 1st Year (HSSC Part I), Punjab boards
MCQs answered 10
Questions solved 13

Exercise questions deleted in the ALP Smart Syllabus 2027

Under PECTAA’s ALP Smart Syllabus 2027 for Computer Science and Entrepreneurship-11, the following content of Unit 3 is not part of the 2027 annual exam: Topic 3.3.3 Complexity Classes (P, NP, NP-hard, NP-complete) Β· MCQs 2, 3 and 4 Β· Long Question 1. These questions are marked below and still solved, so you can practise them if you want.

Multiple Choice Questions

Q. Correct option Reason from the textbook
1 (c) Clear goals, inputs, processes, and outputs A well-defined problem has a clear goal, input, process and output, for example checking whether a number is even.
2 (ALP deleted) (d) P Class P contains problems that a computer can solve efficiently, even as the problem grows.
3 (ALP deleted) (b) They cannot be solved by any algorithm An unsolvable problem has no algorithm that gives a solution in all cases, for example the Halting Problem.
4 (ALP deleted) (a) Non-deterministic Polynomial time NP stands for Non-deterministic Polynomial time.
5 (d) Quick Sort The book recommends Quick Sort or Merge Sort for large datasets instead of Bubble Sort. The official key gives (d).
6 (c) Problems with overlapping subproblems and optimal substructure Dynamic Programming is most useful for problems with these two properties.
7 (c) Bubble Sort Bubble Sort compares adjacent elements and swaps them if they are in the wrong order.
8 (c) O(V + E) DFS visits every vertex (V) and edge (E) once.
9 (b) Time taken as a function of input size Time complexity measures how running time grows as the input size grows.
10 (c) Merge Sort Merge Sort runs in O(n log n) time.

Short Questions

Q.1 Differentiate between well-defined and ill-defined problems within the realm of computational problem-solving.

Well-defined problem Ill-defined problem
Has a clear goal, clear inputs, a clear process and a clear output. Has unclear or vague goals and requirements.
Can be solved directly with an algorithm. Must first be made clearer before an algorithm can be designed.
Example: decide whether a number is even. Input: one integer. Process: check whether it is divisible by 2. Output: even or odd. Example: “How to reduce poverty in Pakistan”. The goal is broad and the input and output are not clear.

Q.2 Outline the main steps involved in the Generate-and-Test method.

  1. Generate: produce one possible solution to the problem.
  2. Test: check whether this solution meets the required conditions.
  3. Decide: if the solution is correct, stop. If it is incorrect, go back and generate the next possible solution.
  4. Repeat until a correct solution is found or all possible solutions have been tried.

The method suits problems with a small solution space, or problems with no clear strategy where trying options is necessary. Heuristics (rules) can be used to reduce the number of solutions generated.

Q.3 Compare tractable and intractable problems in the context of computational complexity.

Tractable problems Intractable problems
Can be solved in polynomial time (class P). Need super-polynomial time, often growing exponentially.
Time grows at a manageable rate as the input grows, so they are “efficiently solvable”. Time becomes unmanageable for large inputs, so exact solutions are impractical.
Example: sorting a list with Merge Sort or Quick Sort, O(n log n). Example: the Travelling Salesman Problem, where the number of routes grows factorially with the number of cities.

Q.4 Summarize the key idea behind Greedy Algorithms.

  • A greedy algorithm builds a solution step by step. At each step it makes the choice that looks best at that moment (locally optimal), hoping this leads to the best overall (globally optimal) solution.
  • Example (coin change): to make an amount with the fewest coins, keep choosing the largest coin that does not exceed the remaining amount, subtract it, and repeat.
  • Greedy algorithms are fast and easy to write, but they do not always give the best solution, so check first that the greedy approach suits the problem.

Q.5 Discuss the advantages of using Dynamic Programming.

  • It breaks a problem into simpler subproblems and stores the result of each subproblem.
  • Stored results are reused instead of being recalculated, which avoids repeated work and saves a great deal of time.
  • It suits problems with overlapping subproblems and optimal substructure.
  • Example: to find Fibonacci numbers, each number is calculated once and stored. Later steps read the stored values, so the number of calculations drops sharply.

Q.6 Compare the advantages of Breadth-First Search (BFS) with Depth-First Search (DFS) in graph traversal.

BFS DFS
Explores the graph level by level from the starting (root) node, using a queue. Goes as deep as possible along one branch before backtracking, using a stack.
Advantage: finds the shortest path between two nodes, for example the degree of separation between two people in a social network. Advantage: good for puzzles such as mazes. It follows one path to the end and backtracks at a dead end.
More suited to shallow graphs. More memory-efficient for deep graphs.
Time complexity O(V + E). Time complexity O(V + E).

Q.7 Explain the importance of breaking down a problem into smaller components in algorithmic thinking.

  • A large problem is hard to solve in one go. Breaking it into smaller parts makes each part simple enough to understand and solve.
  • Each smaller part can be solved independently, and the answers are combined to solve the original problem. This is the idea of Divide and Conquer, for example Merge Sort splits a list, sorts the small lists and merges them.
  • It helps us identify the input, process and output of each part clearly.
  • Solutions to small parts can be reused, as Dynamic Programming does by storing subproblem results.

Q.8 Identify the key factors used to evaluate the performance of an algorithm.

  • Time complexity: how the running time increases as the input size grows. It is written in Big O notation, for example O(1), O(log n), O(n), O(nΒ²).
  • Space complexity: how much memory the algorithm needs as the input size grows.
  • Together they predict how efficient and scalable the algorithm is, and help us choose the best algorithm for a task.

Long Questions

Q.1 Provide a detailed explanation of why the Halting Problem is considered unsolvable and its implications in computer science. (Deleted in ALP Smart Syllabus 2027)

The problem: given any program and its input, decide whether the program will eventually stop (halt) or keep running forever.

Why it is unsolvable: a problem is solvable only if an algorithm can solve it in a finite time for every possible input. Alan Turing proved that no general algorithm can answer the halting question for all possible program-input pairs. A checker might work for some programs, but no single procedure can guarantee a correct answer every time. So the Halting Problem is the classic example of an unsolvable problem.

Implications in computer science:

  • It shows that computers have limits: some well-stated problems cannot be solved by any algorithm.
  • No tool can be built that checks every program and always tells us whether it will freeze in an endless loop.
  • Before working on a hard problem, it is worth checking whether it is solvable at all, which saves time and resources.

Q.2 Discuss the characteristics of search problems and compare the efficiency of Linear Search and Binary Search algorithm.

Search problems ask us to find a solution or an item that meets certain criteria, for example finding a name in a list or a record in a database. Their characteristics are: a collection of data to look through (input), a target to find, and an output that is the position of the item or a message that it is not present. Search algorithms are used in information retrieval, database queries and decision making.

Linear Search Binary Search
Checks items one by one from the start until the item is found or the list ends. Starts at the middle element and halves the search interval each time.
Works on sorted and unsorted lists. Works only on a sorted list.
Time complexity O(n): the time grows directly with the list size. Time complexity O(log n): much faster for large datasets.
Example: finding Islamabad in [Karachi, Lahore, Islamabad, Faisalabad] takes 3 checks. Example: finding 78 in [21, 34, 43, 57, 66, 78]. Middle 43: 78 is greater, go right. Middle 66: 78 is greater, go right. Found 78.

Conclusion: linear search is simple and needs no sorting, but binary search is far more efficient when the data is large and sorted.

Q.3 Discuss the nature of optimization problems and provide examples of their applications in real-world scenarios.

Nature: an optimization problem does not ask for just any solution. It asks for the best solution according to some criteria, such as the shortest, cheapest, fastest or most valuable. Many solutions may be possible, and they must be compared. Some optimization problems are tractable, while others such as the Travelling Salesman Problem are intractable for large inputs. Techniques such as greedy algorithms and dynamic programming are used to solve them.

Real-world examples:

  • Route planning (Travelling Salesman Problem): a delivery van must visit several cities and return home by the shortest route.
  • Knapsack problem: choose the most valuable set of items that fits within a bag’s weight limit, for example loading a truck with the most valuable goods.
  • Coin change: a shopkeeper returns change using the fewest coins.
  • Network routes: finding the shortest path between two places on a road map or between two people in a network.

Q.4 Explain the process and time complexity of the Bubble Sort algorithm. Compare it with another sorting algorithm of your choice in terms of efficiency.

Process: start at the beginning of the list, compare each pair of adjacent elements, and swap them if they are in the wrong order. One full pass moves the largest remaining value to the end. Repeat the passes until no swaps are needed.

Example: sort [5, 3, 8, 4, 2] in ascending order.

Pass List after the pass What happened
1 [3, 5, 4, 2, 8] 5↔3 swapped, 8↔4 swapped, 8↔2 swapped. 8 reaches the end.
2 [3, 4, 2, 5, 8] 5↔4 swapped, 5↔2 swapped.
3 [3, 2, 4, 5, 8] 4↔2 swapped.
4 [2, 3, 4, 5, 8] 3↔2 swapped.
5 [2, 3, 4, 5, 8] No swaps, so the list is sorted and the algorithm stops.

Time complexity: O(nΒ²). Each pass compares neighbouring pairs, and about n passes may be needed, so the work grows with the square of the list size. It is easy to understand and fine for small lists, but slow for large datasets.

Comparison with Merge Sort:

Bubble Sort Merge Sort
Repeatedly swaps adjacent elements. Uses divide and conquer: splits the list into halves, sorts them and merges them.
O(nΒ²) O(n log n)
Slow for large lists. Much faster for large lists.
Simple to write, good for learning. More steps to write, but suited to real use on big data.

Q.5 Discuss the differences between time complexity and space complexity. How do they impact the choice of an algorithm for a specific problem?

Time complexity Space complexity
Measures how running time increases as the input size grows. Measures how the memory used increases as the input size grows.
Tells us how fast the algorithm is on larger data. Tells us how efficiently the algorithm uses memory on larger data.
Expressed in Big O, for example Binary Search O(log n), Bubble Sort O(nΒ²). Example: an algorithm that stores a list of n numbers needs memory that grows with n.

Impact on choosing an algorithm:

  • For large inputs, choose an algorithm with lower time complexity: Merge Sort O(n log n) instead of Bubble Sort O(nΒ²), or Binary Search O(log n) instead of Linear Search O(n) on sorted data.
  • When memory is limited, prefer the algorithm that uses less space. DFS, for example, is more memory-efficient than BFS on deep graphs.
  • For small inputs a simple algorithm may be good enough, even if its complexity is higher.
  • Analysing both measures predicts performance before the program is written, so the best algorithm can be chosen for the task.

More for 1st Year Computer Science

The exercise questions are from the PECTAA Computer Science and Entrepreneurship-11 textbook. The deleted list follows the PECTAA ALP Smart Syllabus 2027. Please confirm all dates and figures on the official website: pectaa.edu.pk

Need help with 1st Year Computer Science? Join our live online classes for Intermediate (Punjab and Federal Board). Book a free demo class.

All chapters of this subject

πŸ“Œ Struggling with this chapter? Join our live online tuition β€” one-to-one or small group classes with experienced teachers. Book a free demo class β†’

Ask a question about this topic

Your email address will not be published. Required fields are marked *