These are the solved end-of-unit exercises for Unit 4, Computational Structures, 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 explains the basic data structures used in programming: lists, stacks (LIFO), queues (FIFO), trees and graphs, with their properties, operations, Python code and real-life uses.
| Unit | 4: Computational Structures |
|---|---|
| Class | 1st Year (HSSC Part I), Punjab boards |
| MCQs answered | 6 |
| Questions solved | 11 |
Exercise questions deleted in the ALP Smart Syllabus 2027
Nothing is deleted from Unit 4. The complete unit and every exercise question are part of the 2027 annual exam.
Multiple Choice Questions
| Q. | Correct option | Reason from the textbook |
|---|---|---|
| 1 | (b) append() | append() adds an item at the end of a list. |
| 2 | (c) Checks if an item exists in the list | The in keyword searches a list and gives True or False. |
| 3 | (b) Pop | Pop removes the item at the top of a stack. |
| 4 | (c) Enqueue | Enqueue adds an item at the back of a queue. |
| 5 | (a) Number of edges from the root to the deepest node | Height is the longest path from the root down to the farthest leaf. |
| 6 | (c) Representing connections in a social network | In a graph, people are vertices and friendships are edges. A to-do list suits a list, and a line of customers suits a queue. |
Short Questions
Q.1 Explain how the insert() function works in Python lists. Provide an example.
insert()adds a new item at any position in a list, not only at the end.- Syntax:
list_name.insert(index, item). The item is placed at the given index, and the items already there move one place to the right.
party_list = ["Buy drinks", "Buy decorations", "Buy snacks"]
party_list.insert(0, "Invite friends") # add at the start
print(party_list)
# Output: ['Invite friends', 'Buy drinks', 'Buy decorations', 'Buy snacks']
Q.2 Explain the potential issues which could arise when two variables reference the same list in a program? Provide an example.
The chapter does not discuss this directly, so this answer builds on the list operations taught in the unit.
- When we write
b = afor a list, Python does not make a new copy. Both names point to the same list in memory. - A change made through one variable, such as append(), remove() or pop(), also appears through the other variable.
- This can cause unexpected results and bugs, because one part of the program changes data that another part was still using.
marks = [70, 80, 90]
backup = marks # both names refer to the same list
backup.append(100)
print(marks) # Output: [70, 80, 90, 100] (marks also changed!)
safe_copy = marks.copy() # a separate list avoids the problem
Q.3 Define a stack and explain the Last-In, First-Out (LIFO) principle.
- A stack is a data structure in which items are added and removed at only one end, called the top.
- LIFO (Last-In, First-Out) means the item added last is the first one removed.
- Example: in a stack of books, the book placed on top last is the first one you pick up. To reach the bottom book, the books above it must be removed first.
Q.4 Differentiate between the Enqueue and Dequeue operations of queue.
| Enqueue | Dequeue |
|---|---|
| Adds an item to the queue. | Removes an item from the queue. |
| Works at the back (rear) of the queue. | Works at the front of the queue. |
| Like a new person joining the end of a bank line. | Like the person at the front of the line being served. |
In Python’s Queue module: q.put(item) |
In Python’s Queue module: q.get() |
Both operations follow the FIFO (First-In, First-Out) principle.
Q.5 Name two basic operations performed on stack.
- Push: adds an item to the top of the stack. In Python:
stack.append(item) - Pop: removes the item from the top of the stack. In Python:
stack.pop()
Q.6 What is difference between enqueue() and dequeue()?
- enqueue() inserts a new element at the rear of the queue.
- dequeue() deletes and returns the element at the front of the queue.
- So the element enqueued first is the first one dequeued (FIFO). For example, if Ahmed and then Fatima join the queue, dequeue() removes Ahmed first.
Long Questions
Q.1 Discuss the dynamic size property of lists in Python. How does this property make lists more flexible?
Dynamic size means a Python list can grow or shrink while the program runs. We do not fix its size when we create it. When items are added or removed, the list adjusts itself automatically.
items = ["Decorations", "Snacks"]
items.append("Balloons") # list grows to 3 items
items.insert(0, "Plates") # grows to 4 items
items.remove("Snacks") # shrinks to 3 items
print(items, len(items))
# Output: ['Plates', 'Decorations', 'Balloons'] 3
How it makes lists flexible:
- We do not need to know in advance how many items there will be, for example a to-do list that keeps changing.
- Items can be inserted at any position or deleted by value (remove()) or by index (pop()) without creating a new list.
- Because the size can change, lists can be used to build other structures such as stacks (LIFO) and queues (FIFO).
- Together with its other properties (index-based access and ordered collection), it makes the list a convenient way to store and manage records and values.
Q.2 Explain the operations on stack with real-life example and Python code.
A stack allows insertion and deletion only at the top and follows LIFO. Real-life example: a pile of books or plates. A new book is placed on top, and the top book is taken off first.
- Push: add an item to the top.
- Pop: remove the item from the top.
stack_of_books = [] # empty stack
stack_of_books.append("Book A") # push
stack_of_books.append("Book B") # push
print("Stack:", stack_of_books)
top_book = stack_of_books.pop() # pop
print("Removed:", top_book)
print("Stack now:", stack_of_books)
Output:
Stack: ['Book A', 'Book B']
Removed: Book B
Stack now: ['Book A']
“Book B” was pushed last, so it was popped first. This shows the LIFO principle.
Q.3 Write a simple program to implement a queue (insertion and deletion).
from queue import Queue # built-in module for queues
q = Queue()
# Insertion (enqueue) at the back
q.put("Ahmed")
q.put("Fatima")
q.put("Sara")
print("Queue:", list(q.queue))
# Deletion (dequeue) from the front
served = q.get()
print("Served:", served)
print("Queue now:", list(q.queue))
Output:
Queue: ['Ahmed', 'Fatima', 'Sara']
Served: Ahmed
Queue now: ['Fatima', 'Sara']
Ahmed joined first, so he is served first. This shows FIFO (First-In, First-Out), like a line at a bank counter.
Q.4 Define Tree and explain its properties.
A tree is a data structure that organises data in a branching hierarchy that starts from one main node, the root. Each piece of data is a node, and nodes connect to other nodes in parent-child relationships. Unlike a list, the data is not in a straight line. Example: a family tree, where the oldest ancestor is the root.
Properties of trees:
- Root node: the first or top node. Every other node branches out from it, like the main folder on a computer.
- Nodes and edges: nodes are the elements, and the lines joining them are edges. A node with no children is called a leaf, like a file that holds no other files.
- Height: the longest path from the root down to the farthest leaf. It shows how deep the tree is.
- Balanced tree: a tree whose left and right branches are nearly the same height.
Uses: file systems (backups by pre-order traversal, deletion by post-order traversal), organisation charts and family trees, and decision trees.
Q.5 What is a graph? Explain differences between directed and undirected graphs.
A graph is a data structure made of vertices (nodes) joined by edges. It represents a network of connections, for example cities joined by roads, or people joined by friendships. A graph has no single root and no fixed hierarchy, and it can have several paths between nodes and cycles. Its properties include degree (the number of edges at a vertex), weight (a cost or distance on an edge) and direction.
| Directed graph | Undirected graph |
|---|---|
| Each edge has a direction and goes from one vertex to another. | Edges have no direction. |
| A connection is one-way: an edge from A to B does not mean you can go from B to A. | A connection is two-way: you can travel in both directions. |
| Drawn with arrows. | Drawn with plain lines. |
| Example: one-way streets between cities. | Example: friendship. If A is a friend of B, then B is a friend of A. |
Either type can also be weighted, where each edge carries a value such as distance, time or cost.
More for 1st Year Computer Science
- All units: 1st Year Computer Science exercise solutions 2027
- 11th Class pairing scheme, model papers and ALP deleted topics
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.

Ask a question about this topic