A1 Computer Fundamentals
B2.1 Programming fundamentals
B2.2 Data structures
B2.4 Programming algorithms
B2.5 File processing
100

State two components found within the CPU.

Main CPU components

  • Arithmetic Logic Unit (ALU)

  • Control Unit (CU) 

Registers (inside the CPU)

  • Registers – very small, fast memory locations inside the CPU

  • Accumulator (ACC) 

  • Program Counter (PC) 

  • Instruction Register (IR) 

  • Memory Address Register (MAR)

  • Memory Data Register (MDR / MBR) 


100

Consider the program below. What will be printed and why ?

x = 10
def change():
    x = 5
    x = x + 2
    return x

print(change())
print(x)


7

10


100

State one difference between a static data structure and a dynamic data structure.

  • A static data structure has a fixed size that cannot change during program execution.

  • A dynamic data structure can change its size while the program is running.

100
State time complexity for binary search.

O(log n)

100

State three file opening modes used when working with sequential files in Python.


  1. "r" (read mode) – opens a file for reading only.

  2. "w" (write mode) – opens a file for writing; existing content is overwritten or a new file is created.

  3. "a" (append mode) – opens a file for writing and adds new data to the end of the file without deleting existing content.



200

Describe the fetch phase of the fetch-decode-execute cycle.

During the fetch phase, the CPU retrieves the next instruction from main memory. The address of the next instruction is held in the Program Counter (PC) and is copied to the Memory Address Register (MAR). The instruction stored at that memory address is then fetched from memory and placed into the Memory Data Register (MDR), after which it is copied into the Instruction Register (IR). The Program Counter is then incremented so that it points to the next instruction to be executed.

200

State the output 

String name = "MacKenty"; String sub = name.substring(0, 3);

"Mac"

200
Identify the term queue in CS.

queue is a data structure that follows the First In, First Out (FIFO) principle, where the first element added to the queue is the first one removed.

200

Construct code for sequential search

def linear_search(arr, target):    

for index in range(len(arr)):      

  if arr[index] == target:          

      return index   

 return -1

200

State what the function read() returns when it reaches end-of-file (EOF).

When the read() function reaches end-of-file (EOF), it returns an empty string ("").

300

State the decimal equivalent of the binary number 1100101.

101

300

State 4  common debugging techniques

Trace Tables

Print Statements

Breakpoint Debugging

Step-by-Step Execution (Stepping)

300

The following operations are performed on an empty stack:

push("A")
push("B")
push("C")
pop()
push("D")

State the final contents of the stack .

D

B

A

300

Construct code for bubble sort

for i from 0 to n - 1:
    for j from 0 to n - i - 2:
        if array[j] > array[j + 1]:
            swap array[j] and array[j + 1]

300

A text file called words.txt already exists.

Question:

Construct a Python program that:

  1. Opens the file words.txt in append mode.

  2. Writes the word Hello into the file on a new line.

  3. Closes the file after writing.

with open("words.txt", "a") as file:

    file.write("Hello\n")


400

Construct a truth table for the logic expression (A NAND B) NOR C.


0

0

0

0

0

0

1

0


400

Explain how exception handling improves both program reliability and user experience. Use one example to support your answer.

Exception handling improves reliability by preventing a program from crashing when an error occurs. It also improves user experience by providing meaningful error messages instead of abrupt termination. For example, handling a ValueError when converting user input to an integer allows the program to prompt the user to re-enter valid data instead of stopping execution.

400

Given the following list of numbers:

numbers = [12, 7, 9, 20, 5, 14]

Question: Find the maximum and minimum values in the list.

max_value = numbers[0]

min_value = numbers[0]

for num in numbers:

    if num > max_value:

        max_value = num

    if num < min_value:

        min_value = num

print("Maximum value:", max_value)

print("Minimum value:", min_value)

400

Construct code for binary search

def binary_search(arr, target):   

 low = 0    

high = len(arr) - 1   

 while low <= high:        

     mid = (low + high) // 2        

      if arr[mid] == target:              

            return mid        

    elif arr[mid] < target:            

           low = mid + 1       

     else:           

           high = mid - 1   

 return -1

400

Explain what is meant by bytes and buffer size when reading and writing files, and state one advantage of reading a file in chunks instead of reading it all at once.


  • A byte is the smallest unit of data storage used when reading from or writing to a file.

  • Different characters may use different numbers of bytes depending on the encoding (for example, "A" uses 1 byte in ASCII, while some UTF-8 characters use multiple bytes).

  • The buffer size determines how much data is transferred between the file and memory at one time.

  • Reading a file in chunks (for example using read(n)) is more efficient because it reduces memory usage, especially when working with very large files.



500

Deduce a simplification of the Boolean expression using the

idempotent law: A AND A AND B AND B

A AND B

500

Construct a Python statement that extracts the domain name from the email
student2025@nis.edu.kz

email = "student2025@nis.edu.kz"

domain = email[email.index("@")+1:]

print(domain)

500

A two-dimensional list stores students’ scores, where:

  • each row represents a student

  • each column represents a subject

scores = [
    [85, 90, 78],
    [72, 88, 91],
    [80, 75, 84]
]


Question:Calculate the average score for each student.

student_averages = []

for student in scores:

    average = sum(student) / len(student)

    student_averages.append(average)

print("Average score for each student:")

for i in range(len(student_averages)):

    print(student_averages[i])

500

Construct code for selection sort

for i from 0 to n - 1:    

    min_index = i   

     for j from i + 1 to n - 1:       

          if array[j] < array[min_index]:                                          min_index = j    

        swap array[i] and array[min_index]

500

A text file called students.txt already exists.

Each line in the file contains information about one student in the following format:

Name Subject

Example:

Amina ComputerScience
Dias Mathematics
Alina ComputerScience
Timur Physics
Arman ComputerScience

Question:

Construct a Python program that:

  1. Opens the file students.txt in read mode.

  2. Reads the file line by line.

  3. Counts how many students study Computer Science.

count = 0


with open("students.txt", "r") as file:

    for line in file:

        parts = line.split()

        subject = parts[1]


        if subject == "ComputerScience":

            count += 1


print("Number of students studying Computer Science:", count)