Anonymous

Register for more FREE stuff!

my subscriptions

Computational Thinking

Question 1

[Maximum mark: 5]



Determine the output from the following algorithm given the input values:

Input Values: 3, 7, 9, 10, 14, 18, 21, 24


Algorithm:

        
        loop for Count from 0 to 7
            input NUMBER
            if NUMBER mod 2 = 0 then
                if NUMBER mod 4 = 0 then
                    output NUMBER
                end if
            end if
        end loop
        
                

Answers and Explanations

Question 2

[Maximum mark: 10]



A library manager is looking to implement a simple system to organize book information, including titles, authors, and status (Available or Checked Out) in a set of three parallel one-dimensional arrays called TITLES[], AUTHORS[], and STATUS[]. The status of the books changes based on library activities.


The library catalog contains 100 books.


Title Author Status
The Great Gatsby F. Scott Fitzgerald Available
To Kill a Mockingbird Harper Lee Checked Out
1984 George Orwell Available

(a) Construct an algorithm using pseudocode to update the STATUS[] array based on the book titles that have been checked out or returned. Assume you are given the book title and the new status (either "Available" or "Checked Out").


(b) Construct an algorithm using pseudocode to list all book titles and authors that are currently available for borrowing.


(c) Modify your algorithm in part (b) to allow a user to input an author's name and output all book titles by that author along with their current status.

Answers and Explanations

Question 3

[Maximum mark: 2]



Outline the need for a translation process from high level language to machine code.

Answers and Explanations

Question 4

[Maximum mark: 2]



Explain why abstraction is required in the design of algorithms.

Answers and Explanations

Question 5

[Maximum mark: 12]



A company wants to manage its employee information using arrays. Each employee has a name, age, and salary. The company has 50 employees.


The sample observations from those three arrays look as follows:

Names
John Smith
Jane Doe
Emily Johnson
Ages
28
34
25
Salaries
55,000
48,000
60,000

(a) Develop an algorithm in pseudocode to calculate the bonus for each employee based on their salary. If the salary is greater than or equal to $50,000, the bonus is 10% of their salary. If the salary is less than $50,000, the bonus is 5% of their salary. Store the calculated bonuses in a separate array named BONUS[].


(b) Explain how the name, age, salary, and bonus in the arrays correspond to the same employee.


(c) Create an algorithm in pseudocode to list the names and ages of employees who are younger than 30 years old and have a salary greater than $40,000.


(d) Describe how you would modify your algorithm in part (c) to allow the user to input a maximum age and a minimum salary and output the names and salaries of employees meeting those criteria.

Answers and Explanations

Question 6

[Maximum mark: 6]



Construct a trace table for the following algorithm:


        
        X = 2
        Y = 10
        loop while Y > X
            X = X + 2
            output(Y - X)
            Y = Y - 2
        end loop
        
        

Answers and Explanations

Question 7

[Maximum mark: 11]



There is an array containing 100 cities in the USA. Each city has a population count assigned to it, as well as the total CO2 emissions for the city, in two separate arrays.


The sample rows form the dataset look as follows:

City Population Total CO2 Emissions (metric kg)
New York 8,336,817 60,000,000
Los Angeles 3,979,576 40,000,000
Chicago 2,693,976 30,000,000

(a) Write an algorithm in pseudocode to find the city with the highest population.


The government is looking to find all cities with per capita emissions greater than 1000 to add fines to them.


(b) Write an algorithm in pseudocode to make a list of all such cities.


Each city with per capita emissions above 999 and below 2000 has to pay a fine of $100 for each citizen in this city. Each city with per capita emissions above 1999 and below 3000 has to pay $125 for each citizen. Everything above 3000 results in a fine of $150 per citizen.


(c) Write an algorithm in pseudocode to calculate the total sum of fines paid by the cities.

Answers and Explanations

Question 8

[Maximum mark: 5]



Consider the function below:

            
            func(X)
                if X > 1
                    then
                        return func(X - 1) + func(X - 2)
                    else
                        return X
                end if
            end func
            
        


Determine the value of func(5) (show all your working).

Answers and Explanations

Question 9

[Maximum mark: 6]



List the output from the given algorithm for the following input:

Input: 4, 7, 10, 13, 16, 19, 20, 25


Algorithm:

        
        loop for Index from 0 to 7
            input NUMBER
            if NUMBER mod 2 = 0 then
                if NUMBER mod 5 = 0 then
                    output NUMBER
                end if
            end if
        end loop
        
        

Answers and Explanations

Question 10

[Maximum mark: 2]



Identify two operations performed by a compiler.

Answers and Explanations

Question 11

[Maximum mark: 8]



Construct a trace table for the following algorithm:


        
        A = 1
        B = 10
        C = 5
        loop while B > C
            A = A + 3
            B = B - 2
            if B mod 4 = 0 then
                C = C + 1
            end if
            output(A + B - C)
        end loop
        
        

Answers and Explanations

Question 12

[Maximum mark: 7]



A team manager is working on organising player data for a basketball team. The data includes player names, positions, and scores made in the current season. This information is stored in three parallel one-dimensional arrays called NAMES[], POSITIONS[], and SCORES[]. Each player's score changes as the season progresses.


The team consists of 15 players.


(a) Construct an algorithm using pseudocode to update the SCORES[] array when a player scores some points in a new game. Assume you are given the player's name and the points they scored in a game. Add these points to their current season score.


(b) Construct an algorithm using pseudocode to list all players who play as "Guard" and have scored more than 100 points in the current season.

Answers and Explanations

Question 13

[Maximum mark: 4]



Write a function in pseudocode that calculates the square of an integer. The square of a number is the result of multiplying the number by itself.

Answers and Explanations

Question 14

[Maximum mark: 5]



Consider the function below, which allows to calculate a given Fibonacci number:

            
            fibonacci(n)
                if n <= 1
                    then
                        return n
                    else
                        return fibonacci(n - 1) + fibonacci(n - 2)
                    end if
            end fibonacci
            
            
                    


a) Define the term recursive function.


b) Determine the value of fibonacci(4) (show all your working).

Answers and Explanations