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

FBISE 2nd 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) 2nd Year Computer Science course (HSSC-II, Intermediate Part II), solved in full for the Annual Examination 2027.

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

Short Questions with Answers: Unit 2

Q1. How is the binary search algorithm useful in searching large datasets efficiently? Give any three key points. [Model Paper 2025 (New Curriculum)] (03)

Answer:

  • Halves the search space at each step: it compares the target with the middle element and discards half of the list, so it needs very few comparisons.

  • Fast, logarithmic time complexity O(log n): e.g. at most about 20 comparisons for 1 million items, against up to 1 million for linear search.

  • Works on sorted data and uses little memory: it is efficient for large sorted datasets (dictionaries, databases, indexes) and can be done iteratively with O(1) extra space.

Q2. Perform the in-order traversal and write the correct sequence of node visits for the following tree: [Model Paper 2025 (New Curriculum)] (03)

[figure]

Answer:

  • In-order traversal rule: Left subtree β†’ Root β†’ Right subtree.

  • Sequence: D, B, E, A, C, F

Diagram: Perform the in-order traversal and write the correct sequence of node visits for the following tree: [Model Pa

In-order traversal; numbers show order of visits

Q3. How do we assess the effectiveness of a computational solution? [Model Paper 2025 (New Curriculum)] (03)

Answer:

  • Correctness: the solution must produce the right output for all valid inputs, including edge cases (tested with test cases).

  • Efficiency: analyse time complexity (how running time grows with input size, Big-O) and space complexity (memory used).

  • Other qualities: scalability (works for large data), simplicity/readability and maintainability, and robustness (handles errors and invalid input).

Q4. A company needs to store hierarchical employee data. Which data structure would you recommend, and how would you apply it? [Model Paper 2025 (New Curriculum)] (1+2)

Answer:

  • Recommended data structure: a tree (hierarchical / general tree).

  • Application:

  • The CEO is stored as the root node. Managers are its child nodes, and employees under each manager are their children. Employees with no subordinates are leaf nodes.

  • Each node stores employee data (ID, name, post) and links to its children. Traversals (DFS/BFS) can list all employees under a manager, find an employee, or count the levels of hierarchy.

Q5. Give a real-world example of how tree data structures are used in computing. [Model Paper 2025 (New Curriculum)] (03)

Answer:

  • File system of an operating system: folders (directories) and files are organised as a tree. The root drive (C:) is the root node, folders are internal nodes and files are leaf nodes.

  • (Other examples: HTML DOM tree of a web page, decision trees in machine learning, binary search trees and B-trees for database indexing, routing tables.)

Q6. A search engine needs to quickly find a keyword from a sorted list of millions of words. Which algorithm would be most efficient, and how does it work? [Model Paper 2025 (New Curriculum)] (1+2)

Answer:

  • Binary search is the most efficient algorithm for a sorted list.

  • How it works:

  • Find the middle element. If it equals the keyword, the search is successful.

  • If the keyword is smaller (alphabetically), search only the left half; if larger, search the right half.

  • Repeat on the remaining half until it is found or the range is empty.

  • Time complexity is O(log n): about 20 comparisons for 1 million words.

Q7. Differentiate between stack and queue with real life examples. [Annual 2026 – Paper B] (1.5+1.5)

Answer:

Stack Queue
Works on LIFO (Last In, First Out) Works on FIFO (First In, First Out)
Insertion (push) and deletion (pop) at the same end (top) Insertion (enqueue) at the rear, deletion (dequeue) at the front
Real life: a pile of plates or books; undo in text editor Real life: a line of people at a bank or ticket counter; printer queue
Diagram: Differentiate between stack and queue with real life examples. [Annual 2026 – Paper B] (1.5+1.5)

Stack and queue

Q8. What is β€˜linked list’? Also write down its advantages. [Annual 2026 – Paper B] (1+2)

Answer:

  • A linked list is a linear data structure made of nodes. Each node contains data and a pointer (link) to the next node. Nodes are not stored in contiguous memory, and the last node points to NULL.

  • Advantages:

  • Dynamic size: it can grow or shrink at run time; no fixed size needs to be declared.

  • Easy insertion and deletion of nodes (only pointers change; no shifting of elements, unlike arrays).

  • Efficient memory use: memory is allocated only when needed.

Q9. What is the difference between time complexity and space complexity in evaluating computational solutions? [Annual 2026 – Paper B] (1.5+1.5)

Answer:

Time complexity Space complexity
Measures the amount of time (number of steps) an algorithm takes as input size n grows Measures the amount of memory (storage) an algorithm needs as input size n grows
Expressed in Big-O, e.g. linear search O(n), binary search O(log n) e.g. an extra array of size n is O(n); a few variables are O(1)
Shows the speed and efficiency of the solution Shows the memory efficiency of the solution

Q10. Write down the purpose of Enqueue, Dequeue and Front operations of Queue. [Annual 2026 – Paper B] (03)

Answer:

  • Enqueue: inserts (adds) a new element at the rear of the queue.

  • Dequeue: removes the element at the front of the queue (the first one inserted).

  • Front (peek): returns (views) the front element without removing it.

Q11. What is the advantage of using arrays? Write its two types. [Annual 2026 – Paper B] (1+2)

Answer:

  • Advantages of arrays: an array stores many values of the same type under one name in contiguous memory, and allows fast random access to any element using its index in O(1) time. It is easy to traverse with loops and to sort/search.

  • Types:

  • One-dimensional array: a single row/list, e.g. marks[5].

  • Two-dimensional (multi-dimensional) array: rows and columns (matrix), e.g. table[3][4].

Q12. Write down any three operations of Queue. [Annual 2026 – Paper D] (1Γ—3)

Answer:

  • Enqueue: insert an element at the rear.

  • Dequeue: remove the element from the front.

  • Peek/Front: view the front element. (Also isEmpty, isFull and size.)

Q13. What is an array? Explain with an example. [Annual 2026 – Paper D] (2+1)

Answer:

  • An array is a collection of a fixed number of elements of the same data type, stored in contiguous memory locations and accessed by a common name with an index (starting from 0).

  • Example (Python list used as array):

marks = [85, 90, 78, 92, 66]

print(marks[2]) # output: 78 (3rd element, index 2)

Q14. What is the concept of correctness in algorithm? Give an example. [Annual 2026 – Paper D] (2+1)

Answer:

  • Correctness means an algorithm always produces the correct (expected) output for every valid input and terminates after a finite number of steps. It is checked by testing (including boundary cases) and logical proof.

  • Example: an algorithm to find the maximum of a list is correct if it returns 9 for [3, 9, 2] and also works for a list of one element, for negative numbers and for equal values.

Q15. How does a doubly linked list differ from a singly linked list? Give example. [Annual 2026 – Paper D] (1.5+1.5)

Answer:

Singly linked list Doubly linked list
Each node has data + one pointer (next) Each node has data + two pointers (prev and next)
Can be traversed in one direction only Can be traversed in both directions
Uses less memory Uses more memory; deletion and backward traversal are easier
  • Example: a singly list is like a music playlist that only plays “next”. A doubly list is like browser history with Back and Forward buttons.

Diagram: How does a doubly linked list differ from a singly linked list? Give example. [Annual 2026 – Paper D] (1.5+1.5

Singly and doubly linked lists

Q16. Write down the purpose of push, pop and top operations of stack. [Annual 2026 – Paper D] (1Γ—3)

Answer:

  • Push: inserts (adds) an element on the top of the stack.

  • Pop: removes (deletes) the top element from the stack.

  • Top (peek): returns the top element without removing it.

Q17. What will be the time and space complexity of finding the sum of digits in a list? [Annual 2026 – Paper D] (03)

Answer:

def sum_list(nums):

total = 0

for x in nums: # loop runs n times

total += x

return total

  • Time complexity: O(n). Each of the n elements is visited once, so the time grows linearly with the size of the list.

  • Space complexity: O(1). Only a fixed number of extra variables (total, x) are used, whatever the list size (not counting the input).

  • (If “sum of digits” of each number is meant, time is O(n Γ— d), where d is the number of digits.)

Long Questions with Answers: Unit 2

Q1. A company manages its organizational hierarchy using a tree/graph data structure as provided. The company wants to find a specific employee (node) using an efficient search algorithm. [Model Paper 2025 (New Curriculum)] (3+2)

[figure]

(a) Search the Security department using Depth-First Search (DFS) and Breadth-First Search (BFS).

(b) Outline the sequence of node visits in the selected search method.

Answer:

Tree (hierarchy)

  • CEO β†’ CTO, CFO; CTO β†’ Eng (Engineering), IT; CFO β†’ Finance; Eng β†’ DevOps; IT β†’ Security.

Diagram: (b) Outline the sequence of node visits in the selected search method.

Organisational hierarchy tree

(a) Searching “Security”

  • Depth-First Search (DFS): goes as deep as possible along one branch before backtracking (uses a stack/recursion).

  • Visit order: CEO β†’ CTO β†’ Eng β†’ DevOps β†’ (backtrack) β†’ IT β†’ Security. Found after 6 visits.

  • Breadth-First Search (BFS): visits level by level (uses a queue).

  • Visit order: CEO β†’ CTO β†’ CFO β†’ Eng β†’ IT β†’ Finance β†’ DevOps β†’ Security. Found after 8 visits.

(b) Selected method and sequence

  • Selected: DFS. It reaches the target (a deep node in the CTO branch) in fewer steps here and uses less memory.

Step Stack (top on right) Node visited
1 [CEO] CEO
2 [CFO, CTO] CTO
3 [CFO, IT, Eng] Eng
4 [CFO, IT, DevOps] DevOps (not target, no children)
5 [CFO, IT] IT
6 [CFO, Security] Security – found
  • (BFS is preferred when the target is expected to be near the root, or for finding the shortest path.)

Q2. Explain the following tree traversal methods: Pre-order and Post-order. Describe their order of operations with one example each. [Annual 2026 – Paper B] (2.5+2.5)

Answer:

Pre-order traversal (Root β†’ Left β†’ Right)

  • Visit the root first, then traverse the left subtree in pre-order, then the right subtree in pre-order.

  • Used for copying a tree and for prefix expressions.

Post-order traversal (Left β†’ Right β†’ Root)

  • Traverse the left subtree in post-order, then the right subtree in post-order, then visit the root last.

  • Used for deleting a tree and evaluating postfix expressions.

Example (tree: A root; B, C children of A; D, E children of B; F right child of C)

Diagram: Explain the following tree traversal methods: Pre-order and Post-order. Describe their order of operations wit

Example binary tree

  • Pre-order: A, B, D, E, C, F

  • Post-order: D, E, B, F, C, A

Q3. Explain the following tree traversal methods: In-order and Pre-order. Describe their order of operations with one example for each. [Annual 2026 – Paper D] (2.5+2.5)

Answer:

In-order traversal (Left β†’ Root β†’ Right)

  • Traverse the left subtree in in-order, then visit the root, then traverse the right subtree in in-order.

  • For a binary search tree it gives values in ascending (sorted) order.

Pre-order traversal (Root β†’ Left β†’ Right)

  • Visit the root first, then the left subtree, then the right subtree.

Example

  • Binary search tree with 50 (root); 30 and 70 its children; 20 and 40 children of 30; 60 and 80 children of 70.

  • In-order: 20, 30, 40, 50, 60, 70, 80 (sorted)

  • Pre-order: 50, 30, 20, 40, 70, 60, 80

  • For the tree in the figure: In-order = D, B, E, A, C, F; Pre-order = A, B, D, E, C, F.

Diagram: Explain the following tree traversal methods: In-order and Pre-order. Describe their order of operations with

Example tree

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

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

Need help with 2nd 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 *