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

FBISE 1st Year Computer Science Unit 2 Computational Thinking & Algorithms: Short and Long Questions with Answers 2027

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

Here are the important short and long questions of Unit 2, Computational Thinking & Algorithms, from the Federal Board (FBISE) 1st Year Computer Science course (HSSC-I, Intermediate Part I), solved in full for the Annual Examination 2027.

Unit 2: Computational Thinking & Algorithms
Class 1st Year (HSSC-I), Federal Board
Subject Computer Science
Contents Short and long questions with answers
Exam FBISE Annual Examination 2027

Short Questions

Q1. Construct a trace table that records the values after each iteration of the loop, and write the final output: Step 1: Initialize i = 2; Step 2: While i <= 10; Step 3: Print i; Step 4: Increment i by 2; Step 5: End While [3] (FA26 P-1)

Iteration i Condition i <= 10 Output (Print i) i after increment
1 2 True 2 4
2 4 True 4 6
3 6 True 6 8
4 8 True 8 10
5 10 True 10 12
– 12 False β†’ loop ends – –

Final output: 2 4 6 8 10

Q2. Construct a trace table and write the final output: Step 1: For i from 1 to 5; Step 2: square = i * i; Step 3: Print square; Step 4: End For; Step 5: Stop [3] (FA26 P-2)

Iteration i square = i * i Output
1 1 1 1
2 2 4 4
3 3 9 9
4 4 16 16
5 5 25 25

Final output: 1 4 9 16 25

Q3. Write pseudocode to display first 50 natural numbers. [3] (FA26 P-3)

START

SET num = 1

WHILE num <= 50

OUTPUT num

num = num + 1

END WHILE

STOP

(FOR num FROM 1 TO 50 … OUTPUT num … END FOR is also correct.)

2.2 Common Computing Algorithms

Short Questions

Q1. Complete the trace table for the algorithm and state the final value of count: A = [5, 8, 3, 8, 2]; count = 0; For i = 0 to 4: If A[i] = 8 Then count = count + 1 [4] (Set-1 Q2-B)

i A[i] A[i] = 8 ? count
– – (initial) 0
0 5 No 0
1 8 Yes 1
2 3 No 1
3 8 Yes 2
4 2 No 2

Final value of count = 2 (number 8 occurs two times in the list).

Q2. Write the four parameters used to evaluate an algorithm. [4] (Set-1 Q3-A)

β€’ Correctness: the most fundamental parameter; the algorithm must produce the desired output for all possible valid inputs.

β€’ Efficiency: deals with time complexity (time taken to run) and space complexity (amount of memory required).

β€’ Clarity: how easily the algorithm’s logic and steps can be understood by humans.

β€’ Reliability: ability to always produce correct and accurate results with a high degree of accuracy and consistency.

Q3. Why is algorithm efficiency important? Explain briefly. [3] (SA25 Q1-A)

Efficiency of an algorithm deals with its time complexity (time taken to run) and space complexity (memory required). It is important because:

β€’ An efficient algorithm gives results quickly, even for large amounts of data (e.g. binary search finds an item in a large sorted list much faster than linear search).

β€’ It uses less memory and processing power, which saves cost and energy and lets programs run on small devices.

β€’ Faster programs improve user satisfaction and allow the system to handle more users (scalability).

Q4. Given the pseudocode (sum of even numbers up to N), modify it to print the product of odd numbers from 1–30. [3] (MP25 Q1-B)

Step 1: Initialize a variable product with 1

Step 2: Initialize a variable i with 1

Step 3: While i is less than or equal to 30

Step 4: Multiply product by i (product = product * i)

Step 5: Increment i by 2

Step 6: Print product

Changes: sum β†’ product initialized to 1 (not 0); i starts at 1 (odd); N replaced by 30; “add” replaced by “multiply”.

Q5. Categorize the scenarios by identifying whether linear or binary search is more appropriate, with reason: bounded data ranges, small data sets, large sorted data sets. [3] (MP25 Q7-A)

Scenario Search algorithm Reason
Bounded data ranges Binary search Data lies within known limits (sorted range), so the range can be halved again and again to find the item quickly.
Small data sets Linear search Simple; few comparisons needed; list need not be sorted.
Large, sorted data sets Binary search Works on sorted lists; halves the search space each step, so it is much faster for a large number of elements.

Q6. Trace the pseudocode and complete the table: SET product = 1; FOR i FROM 1 TO 3: product = product * i; END FOR; PRINT product [3] (FAM25 Q1-B)

Iteration No. Value of i Value of product (sum column) Print
1 1 1 Γ— 1 = 1 –
2 2 1 Γ— 2 = 2 –
3 3 2 Γ— 3 = 6 6 (after loop ends)

Output: 6

Q7. Trace the pseudocode and complete the table: SET sum = 0; FOR i FROM 1 TO 3: sum = sum + i; END FOR; PRINT sum [3] (FAE25 Q1-B)

Iteration No. Value of i Value of sum Print
1 1 0 + 1 = 1 –
2 2 1 + 2 = 3 –
3 3 3 + 3 = 6 6 (after loop ends)

Output: 6

Q8. Which algorithm is more efficient: insertion sort or bubble sort? Justify your choice with two reasons. [1 + 2] (FAM25 Q7-A; FAE25 Q7-A)

Insertion sort is more efficient.

β€’ Insertion sort shifts elements and inserts each item directly at its correct position, so it needs fewer swaps/movements than bubble sort, which swaps adjacent pairs again and again.

β€’ It is very fast for small or nearly sorted data, because an element stops being compared as soon as its correct position is found; therefore it is preferred for practical applications, while bubble sort is mostly used for educational purposes.

Q9. How does bubble sort differ from insertion sort in the way they arrange elements? [1.5 + 1.5] (SA25 Q7-A)

β€’ Bubble sort: repeatedly compares adjacent elements and swaps them if they are not in correct order; in each pass the largest unsorted element “bubbles” to the end of the list (sorted part grows from the right).

β€’ Insertion sort: picks each element one by one and inserts it into its correct position in the already sorted part by shifting larger elements to the right (sorted part grows from the left).

Q10. Which search algorithm, Linear or Binary, is more appropriate for finding a student’s roll number in a sorted list? Justify. [1 + 2] (FA26 P-1)

Binary search is more appropriate.

β€’ Binary search works on sorted lists, and the roll-number list is already sorted.

β€’ It compares the roll number with the middle element and discards half of the list in each step, so it finds the roll number with far fewer comparisons than linear search (ideal for a large number of elements).

Q11. Which search algorithm, Linear or Binary, is more appropriate for finding a Book ID in an unsorted library catalog? Justify. [1 + 2] (FA26 P-2)

Linear search is more appropriate.

β€’ Binary search works only on sorted lists; the catalog is unsorted, so binary search cannot be applied without sorting first.

β€’ Linear search checks each Book ID one by one from the start until a match is found; there is no compulsion that the list be sorted.

Long Questions

Q12. A student is given an unsorted list 48, 10, 14, 37, 13, 29 and must arrange it in ascending order using Bubble Sort. Demonstrate with the help of algorithm how Bubble Sort rearranges the list, showing how elements move to their correct position. Write the final sorted order after all passes. [6] (NMP26 / MP25 Q8-OR)

Given list: 48, 10, 14, 37, 13, 29 (n = 6, so at most 5 passes)

Bubble sort algorithm: (1) Start from the first element. (2) Compare it with the adjacent element; if the first is greater, swap them, otherwise move to the next pair. (3) Repeat till the end of the list – after each pass the largest unsorted element “bubbles” to its correct place at the end. (4) Repeat the passes for the remaining unsorted elements until the whole list is sorted.

Pass Comparison Action List after the step
1 48 , 10 48 > 10, swap 10, 48, 14, 37, 13, 29
48 , 14 48 > 14, swap 10, 14, 48, 37, 13, 29
48 , 37 48 > 37, swap 10, 14, 37, 48, 13, 29
48 , 13 48 > 13, swap 10, 14, 37, 13, 48, 29
48 , 29 48 > 29, swap 10, 14, 37, 13, 29, 48
2 10 , 14 no swap 10, 14, 37, 13, 29, 48
14 , 37 no swap 10, 14, 37, 13, 29, 48
37 , 13 37 > 13, swap 10, 14, 13, 37, 29, 48
37 , 29 37 > 29, swap 10, 14, 13, 29, 37, 48
3 10 , 14 no swap 10, 14, 13, 29, 37, 48
14 , 13 14 > 13, swap 10, 13, 14, 29, 37, 48
14 , 29 no swap 10, 13, 14, 29, 37, 48
4 10 , 13 no swap 10, 13, 14, 29, 37, 48
13 , 14 no swap 10, 13, 14, 29, 37, 48
β€” no swap in this pass β†’ list is sorted

Summary of passes:

β€’ After Pass 1: 10, 14, 37, 13, 29, 48 (48 reaches its correct position)

β€’ After Pass 2: 10, 14, 13, 29, 37, 48 (37 reaches its correct position)

β€’ After Pass 3: 10, 13, 14, 29, 37, 48 (29 reaches its correct position)

β€’ After Pass 4: 10, 13, 14, 29, 37, 48 (no swaps – sorting complete)

Final sorted list (ascending): 10, 13, 14, 29, 37, 48

Q13. Sort the following numbers in ascending order using the Bubble Sort algorithm: 10, 9, 26, 4, 1, 8, 37, 5 [6] (MP25 / FAM25 Q5)

Given list: 10, 9, 26, 4, 1, 8, 37, 5 (n = 8, so at most 7 passes)

Bubble sort algorithm: (1) Start from the first element. (2) Compare it with the adjacent element; if the first is greater, swap them, otherwise move to the next pair. (3) Repeat till the end of the list – after each pass the largest unsorted element “bubbles” to its correct place at the end. (4) Repeat the passes for the remaining unsorted elements until the whole list is sorted.

Pass Comparison Action List after the step
1 10 , 9 10 > 9, swap 9, 10, 26, 4, 1, 8, 37, 5
10 , 26 no swap 9, 10, 26, 4, 1, 8, 37, 5
26 , 4 26 > 4, swap 9, 10, 4, 26, 1, 8, 37, 5
26 , 1 26 > 1, swap 9, 10, 4, 1, 26, 8, 37, 5
26 , 8 26 > 8, swap 9, 10, 4, 1, 8, 26, 37, 5
26 , 37 no swap 9, 10, 4, 1, 8, 26, 37, 5
37 , 5 37 > 5, swap 9, 10, 4, 1, 8, 26, 5, 37
2 9 , 10 no swap 9, 10, 4, 1, 8, 26, 5, 37
10 , 4 10 > 4, swap 9, 4, 10, 1, 8, 26, 5, 37
10 , 1 10 > 1, swap 9, 4, 1, 10, 8, 26, 5, 37
10 , 8 10 > 8, swap 9, 4, 1, 8, 10, 26, 5, 37
10 , 26 no swap 9, 4, 1, 8, 10, 26, 5, 37
26 , 5 26 > 5, swap 9, 4, 1, 8, 10, 5, 26, 37
3 9 , 4 9 > 4, swap 4, 9, 1, 8, 10, 5, 26, 37
9 , 1 9 > 1, swap 4, 1, 9, 8, 10, 5, 26, 37
9 , 8 9 > 8, swap 4, 1, 8, 9, 10, 5, 26, 37
9 , 10 no swap 4, 1, 8, 9, 10, 5, 26, 37
10 , 5 10 > 5, swap 4, 1, 8, 9, 5, 10, 26, 37
4 4 , 1 4 > 1, swap 1, 4, 8, 9, 5, 10, 26, 37
4 , 8 no swap 1, 4, 8, 9, 5, 10, 26, 37
8 , 9 no swap 1, 4, 8, 9, 5, 10, 26, 37
9 , 5 9 > 5, swap 1, 4, 8, 5, 9, 10, 26, 37
5 1 , 4 no swap 1, 4, 8, 5, 9, 10, 26, 37
4 , 8 no swap 1, 4, 8, 5, 9, 10, 26, 37
8 , 5 8 > 5, swap 1, 4, 5, 8, 9, 10, 26, 37
6 1 , 4 no swap 1, 4, 5, 8, 9, 10, 26, 37
4 , 5 no swap 1, 4, 5, 8, 9, 10, 26, 37
β€” no swap in this pass β†’ list is sorted

Summary of passes:

β€’ After Pass 1: 9, 10, 4, 1, 8, 26, 5, 37 (37 reaches its correct position)

β€’ After Pass 2: 9, 4, 1, 8, 10, 5, 26, 37 (26 reaches its correct position)

β€’ After Pass 3: 4, 1, 8, 9, 5, 10, 26, 37 (10 reaches its correct position)

β€’ After Pass 4: 1, 4, 8, 5, 9, 10, 26, 37 (9 reaches its correct position)

β€’ After Pass 5: 1, 4, 5, 8, 9, 10, 26, 37 (8 reaches its correct position)

β€’ After Pass 6: 1, 4, 5, 8, 9, 10, 26, 37 (no swaps – sorting complete)

Final sorted list (ascending): 1, 4, 5, 8, 9, 10, 26, 37

Q14. Sort the following numbers in ascending order using Bubble sort algorithm: 17, 89, 26, 42, 3, 38 [6] (FA26 P-1)

Given list: 17, 89, 26, 42, 3, 38 (n = 6, so at most 5 passes)

Bubble sort algorithm: (1) Start from the first element. (2) Compare it with the adjacent element; if the first is greater, swap them, otherwise move to the next pair. (3) Repeat till the end of the list – after each pass the largest unsorted element “bubbles” to its correct place at the end. (4) Repeat the passes for the remaining unsorted elements until the whole list is sorted.

Pass Comparison Action List after the step
1 17 , 89 no swap 17, 89, 26, 42, 3, 38
89 , 26 89 > 26, swap 17, 26, 89, 42, 3, 38
89 , 42 89 > 42, swap 17, 26, 42, 89, 3, 38
89 , 3 89 > 3, swap 17, 26, 42, 3, 89, 38
89 , 38 89 > 38, swap 17, 26, 42, 3, 38, 89
2 17 , 26 no swap 17, 26, 42, 3, 38, 89
26 , 42 no swap 17, 26, 42, 3, 38, 89
42 , 3 42 > 3, swap 17, 26, 3, 42, 38, 89
42 , 38 42 > 38, swap 17, 26, 3, 38, 42, 89
3 17 , 26 no swap 17, 26, 3, 38, 42, 89
26 , 3 26 > 3, swap 17, 3, 26, 38, 42, 89
26 , 38 no swap 17, 3, 26, 38, 42, 89
4 17 , 3 17 > 3, swap 3, 17, 26, 38, 42, 89
17 , 26 no swap 3, 17, 26, 38, 42, 89
5 3 , 17 no swap 3, 17, 26, 38, 42, 89
β€” no swap in this pass β†’ list is sorted

Summary of passes:

β€’ After Pass 1: 17, 26, 42, 3, 38, 89 (89 reaches its correct position)

β€’ After Pass 2: 17, 26, 3, 38, 42, 89 (42 reaches its correct position)

β€’ After Pass 3: 17, 3, 26, 38, 42, 89 (38 reaches its correct position)

β€’ After Pass 4: 3, 17, 26, 38, 42, 89 (26 reaches its correct position)

β€’ After Pass 5: 3, 17, 26, 38, 42, 89 (no swaps – sorting complete)

Final sorted list (ascending): 3, 17, 26, 38, 42, 89

Q15. Sort the following numbers in ascending order using Insertion sort algorithm: 23, 4, 11, 8, 37, 15 [6] (FA26 P-2)

Given list: 23, 4, 11, 8, 37, 15

Insertion sort algorithm: (1) Assume the first element is already sorted. (2) Pick the next element (key) and compare it with the elements of the sorted part. (3) Shift the larger elements one place to the right. (4) Insert the key at its correct position. (5) Repeat for every element until the whole list is sorted.

Pass Key picked Comparison / Action List after the pass
1 4 23 > 4: shifted right; 4 inserted at position 0 4, 23, 11, 8, 37, 15
2 11 23 > 11: shifted right; 11 inserted at position 1 4, 11, 23, 8, 37, 15
3 8 23, 11 > 8: shifted right; 8 inserted at position 1 4, 8, 11, 23, 37, 15
4 37 37 > 23 – no shift, stays in place 4, 8, 11, 23, 37, 15
5 15 37, 23 > 15: shifted right; 15 inserted at position 3 4, 8, 11, 15, 23, 37

Final sorted list (ascending): 4, 8, 11, 15, 23, 37

Q16. Sort the following list of numbers in ascending order using insertion sort algorithm: 31, 6, 47, 15, 12, 22 [5] (FA26 P-3)

Given list: 31, 6, 47, 15, 12, 22

Insertion sort algorithm: (1) Assume the first element is already sorted. (2) Pick the next element (key) and compare it with the elements of the sorted part. (3) Shift the larger elements one place to the right. (4) Insert the key at its correct position. (5) Repeat for every element until the whole list is sorted.

Pass Key picked Comparison / Action List after the pass
1 6 31 > 6: shifted right; 6 inserted at position 0 6, 31, 47, 15, 12, 22
2 47 47 > 31 – no shift, stays in place 6, 31, 47, 15, 12, 22
3 15 47, 31 > 15: shifted right; 15 inserted at position 1 6, 15, 31, 47, 12, 22
4 12 47, 31, 15 > 12: shifted right; 12 inserted at position 1 6, 12, 15, 31, 47, 22
5 22 47, 31 > 22: shifted right; 22 inserted at position 3 6, 12, 15, 22, 31, 47

Final sorted list (ascending): 6, 12, 15, 22, 31, 47

Q17. Use the Linear Search algorithm to find the number 53 in: 89, 50, 36, 42, 11, 53, 65, 72, 24 [5] (FAE25 P-2 Q5)

List (index 0 to 8): 89, 50, 36, 42, 11, 53, 65, 72, 24 Item to find: 53

Linear search algorithm: start from the first element and compare each element with the target one by one; if a match is found return its location, otherwise move to the next element; if the end of the list is reached the item is not present (NULL).

Step Index Element Comparison Result
1 0 89 89 = 53 ? No, move to next
2 1 50 50 = 53 ? No, move to next
3 2 36 36 = 53 ? No, move to next
4 3 42 42 = 53 ? No, move to next
5 4 11 11 = 53 ? No, move to next
6 5 53 53 = 53 ? Match – FOUND

Result: 53 is found at index (location) 5, i.e. at position 6, after 6 comparisons.

Q18. Use the Binary Search algorithm to find the number 75 from: 9, 10, 26, 34, 41, 58, 67, 75, 83 [5] (FAM25 P-2 Q5)

Sorted list (index 0 to 8): 9, 10, 26, 34, 41, 58, 67, 75, 83 Item to find: 75

Binary search algorithm: (1) Start with the entire sorted list: low = 0, high = nβˆ’1. (2) Find middle: mid = (low + high) // 2. (3) If list[mid] = target, item found. (4) If list[mid] < target, ignore the left half (low = mid + 1); if list[mid] > target, ignore the right half (high = mid βˆ’ 1). (5) Repeat until the item is found or the list becomes empty.

Step low high mid list[mid] Comparison / Action
1 0 8 4 41 41 < 75 β†’ search right half, low = 5
2 5 8 6 67 67 < 75 β†’ search right half, low = 7
3 7 8 7 75 75 = 75 β†’ FOUND

Result: 75 is found at index (location) 7 in 3 comparisons (linear search would need 8).

Q19. Use the Binary Search algorithm to find the number 42 from: 12, 18, 25, 29, 35, 42, 47, 53, 60 [5] (SA25)

Sorted list (index 0 to 8): 12, 18, 25, 29, 35, 42, 47, 53, 60 Item to find: 42

Binary search algorithm: (1) Start with the entire sorted list: low = 0, high = nβˆ’1. (2) Find middle: mid = (low + high) // 2. (3) If list[mid] = target, item found. (4) If list[mid] < target, ignore the left half (low = mid + 1); if list[mid] > target, ignore the right half (high = mid βˆ’ 1). (5) Repeat until the item is found or the list becomes empty.

Step low high mid list[mid] Comparison / Action
1 0 8 4 35 35 < 42 β†’ search right half, low = 5
2 5 8 6 47 47 > 42 β†’ search left half, high = 5
3 5 5 5 42 42 = 42 β†’ FOUND

Result: 42 is found at index (location) 5 in 3 comparisons (linear search would need 6).

You can find the other units of 1st Year Computer Science on the main page: FBISE 1st Year Computer Science short and long questions, all units.

Questions follow the FBISE HSSC-I Computer Science syllabus and paper pattern. Please confirm all dates and figures on the official website: www.fbise.edu.pk

Need help with 1st Year Computer Science? Join our live online classes for the 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 *