MG - Software Development L4 - Algorithm Fundamentals

Download as pdf or txt
Download as pdf or txt
You are on page 1of 21

TVET TERM III COMPREHENSIVE ASSESSMENT,

SCHOOL YEAR 2021/2022

MARKING GUIDES
SECTOR: ICT

TRADE: SOFTWARE DEVELOPMENT

RTQF LEVEL: 4

MODULE CODE AND TITLE: SFDAF401: APPLY ALGORITHM


FUNDAMENTALS

DURATION: 3 HOURS

DATE: TIME:

INSTRUCTIONS TO CANDIDATES:

THIS EXAM PAPER IS COMPOSED OF THREE SECTIONS OF COMPULSORY


QUESTIONS:

(15) questions in section A 50 marks


(9) questions in section B 30 marks
(6) questions in section C 20 marks

Materials allowed:

(APPLY ALGORITHM FUNDAMENTALS) Page 1 of 21 – Marking Guides


SECTION A: ATTEMPT ALL QUESTIONS /50 MARKS

Qn1. a) Convert 111 110 000 from base 2 to base 8 3marks

b) Convert 193 from base 10 to binary

c) Convert 1011 1110 0000 1001 from base 2 to base 16

Solution

a. 111 110 0002=7608

b. 19310 =11000001 2

c. 1011 1110 0000 1001 2 = BE09 16

References:LU1 Describe basic concept of algorithm, LO1.1 convert


number system from one base to another Curriculum version (level): RTQF
LEVEL: 4, page 275, year 2017

Qn2. Answer by true(T) or False(F) (5marks)

Characteristics of an Algorithm:
Not all procedures can be called an algorithm. An algorithm should have the
following characteristics
a) ambiguous: Algorithm should not be clear and ambiguous. Each of its steps
(or phases), and their inputs/outputs should not be clear and must lead to only
one meaning.

b) Input: An algorithm should have 0 or more well-defined inputs.

c) Output: An algorithm should have 1 or more well-defined outputs, and


should match the desired output.

d) Finiteness: Algorithms must terminate after a finite number of steps.

(APPLY ALGORITHM FUNDAMENTALS) Page 2 of 21 – Marking Guides


e) Dependent: An algorithm should not have step-by-step directions, which
should be dependent of any programming code.
Solution:
a) False

b) True

c) True

d) True

e) False

References:LU1 Describe basic concept of algorithm, LO1.2 Describe the


key concepts of algorithm in programming Curriculum version (level):
RTQF LEVEL: 4, page 277, year 2017

Question3. Give four (4) examples of non-primitive data types. (4marks)

Solution:

Four examples of non-primitive data types:

1. Class,

2. object,

3. array,

4. string, and

5. interface

References

LU1 Describe basic concept of algorithm, LO1.3: Review relevant basic data
types and operators in programming Curriculum version (level): RTQF LEVEL:
4, page 278, year 2017

(APPLY ALGORITHM FUNDAMENTALS) Page 3 of 21 – Marking Guides


Question4. What is read in algorithm? (3marks)

Solution:

The data retrieved/result by reading is part of the algorithm, the reading itself
not. As I said: the source doesn't matter. Though the reading is part of your
program's logic. Take for example a sorting algorithm. A sorting algorithm is a
well-defined number of steps on a set to be sorted.
References LU1 Describe basic concept of algorithm, LO1. 4: Describe
basic input-output of algorithm pseudo-codes in programming Curriculum
version (level): RTQF LEVEL: 4, page 278, year 2017

Question5. In a switch statement, what must come after every case? (3marks)
a) Curly braces
b) Read
c) Break

Solution:

c) Break

References:LU2 Apply programming structures, iterative constructs and


structured programming, LO 2.2: Use sequential statements in
programming Curriculum version (level): RTQF LEVEL: 4, page 285, year
2017

Question6. Explain the following concept While loop and For loop in
algorithm. (3marks)

Solution:

(APPLY ALGORITHM FUNDAMENTALS) Page 4 of 21 – Marking Guides


A For loop will run a preset number of times whereas a While loop will run a
variable number of times. For loops are used when you know how many times
you want to run an algorithm before stopping.

References:LU2 Apply programming structures, iterative constructs and


structured programming, LO2.3 Use iterative statements in programming
Curriculum version (level): RTQF LEVEL: 4, page 286, year 2017

Question8. What is a switch statement? (3marks)

Solution: What is a Switch Statement?


A sequential statement or switch case statement or simply switch
statement tests the value of a variable and compares it with multiple cases.
Once the case match is found, a block of statements associated with that
particular case is executed

References:LU2 Apply programming structures, iterative constructs and


structured programming, LO 2.2: Use sequential statements in
programming Curriculum version (level): RTQF LEVEL: 4, page 285, year
2017

Question7. What do you understand by array? (3marks)

Solution:
An array is a variable that can store multiple values of the same data type.
Array is used to store data of similar data type. Arrays are used when we want
to store data in large
quantities.

References:LU3 Describe data structure, LO 3.2: Describe array in line


with programming Curriculum version (level): RTQF LEVEL: 4, page 289,
year 2017

Questionn8.Give two (2) examples where arrays are used. (3marks)

(APPLY ALGORITHM FUNDAMENTALS) Page 5 of 21 – Marking Guides


Solution:

Arrays can be used:

 To store list of Employee or Student names.


 To store marks of students,
 To store list of numbers or characters etc.

References:LU3 Describe data structure, LO3.2: Describe array in line with


programming Curriculum version (level): RTQF LEVEL: 4, page 289, year
2017

Question9. Define the concept ‘linked list’. (3marks)

Solution:

A linked list is a sequence of data structures, which are connected together via
links.

References:LU3 Describe basic concept of algorithm, LO3.1 Describe lists


in data structure in line with programming Curriculum version (level):
RTQF LEVEL: 4, page 288, year 2017

Question10. Outline three (3) main types of Algorithm. (3marks)

Solution:

The algorithm and flowchart are classified into three types of control
structures.

1. Sequence

2. Branching(Selection)

3. Loop(Repetition)

(APPLY ALGORITHM FUNDAMENTALS) Page 6 of 21 – Marking Guides


References:LU2. Apply programming structures, iterative constructs and
structured programming, LO2.3: Use iterative statements in programming
Curriculum version (level): RTQF LEVEL: 4, page 286, year 2017

Question11. List three (3) main types of loop statements found in programming
languages. (3marks)

Solution:

In all programming languages we have 3 main types of loops statements as


follows:

a) FOR loop statement


b) WHILE loop statement

c) DO WHILE statement

Reference:LU2. Apply programming structures, iterative


constructs and structured programming, LO2.3: Use iterative
statements in programming Curriculum version (level): RTQF
LEVEL: 4, page 285, year 2017rib

Question12. List the steps to follow when performing a push operation.

(2marks)

Solution:

Push Operation:

Step 1 − Checks if the stack is full.

Step 2 − If the stack is full, produces an error and exit.

Step 3 − If the stack is not full, increments top to point next empty space.

Step 4 − Adds data element to the stack location, where top is pointing.

Step 5 − Returns success.

(APPLY ALGORITHM FUNDAMENTALS) Page 7 of 21 – Marking Guides


References:LU3 Describe data structure, LO 3.3: Describe data structure
searching and sorting techniques in line with programming Curriculum
version (level): RTQF LEVEL: 4, page 290, year 2017

Question13. Explain sorting techniques. (4marks)

Solution:

Bubble sort is a simple sorting algorithm. This sorting algorithm is


comparison-based algorithm in which each pair of adjacent elements is
compared and the elements are swapped if they are not in order. This algorithm
is not suitable for large data sets as its average and worst case complexity are
of Ο(n2) where n is the number of items

Insertion sort: this is an in-place comparison-based sorting algorithm. Here, a


sub-list is maintained which is always sorted. For example, the lower part of an
array is maintained to be sorted. An element which is to be inserted in this
sorted sub-list, has to find its appropriate place and then it has to be inserted
there.

Selection sort is a simple sorting algorithm. This sorting algorithm is an in-


place comparison-based algorithm in which the list is divided into two parts,
the sorted part at the left end and the unsorted part at the right end. Initially,
the sorted part is empty and the unsorted part is the entire list.

Merge sort is a sorting technique based on divide and conquer technique.


With worst-case time complexity being Ο (n log n), it is one of the most
respected algorithms.

Shell sort is a highly efficient sorting algorithm and is based on insertion sort
algorithm. This algorithm avoids large shifts as in case of insertion sort, if the
smaller value is to the far right and has to be moved to the far left.

(APPLY ALGORITHM FUNDAMENTALS) Page 8 of 21 – Marking Guides


Quick sort is a highly efficient sorting algorithm and is based on partitioning of
array of data into smaller arrays. A large array is partitioned into two arrays
one of which holds values smaller than the specified value, say pivot, based on
which the partition is made and another array holds values greater than the
pivot value.

References:LU3 Describe data structure, LO 3.3: Describe data structure


searching and sorting techniques in line with programming Curriculum
version (level): RTQF LEVEL: 4, page 290, year 2017

Qn14. Write an algorithm that solves the first order equation of the form
ax+b=0.

Note: Analyze all cases. (3marks)

Solution:
Variables A,B,X as integer
Start
Write(“enter the coefficient:”)
Read(A,B)
If(A<>0) then
X=-B/A
Write(“the solution is: ”,X)
Else If (B<>0)then
Write(“Impossible solution”)
Else
Write(“Undetermined(all values are solution)”)
End If
End

(APPLY ALGORITHM FUNDAMENTALS) Page 9 of 21 – Marking Guides


Reference:LU2 Apply programming structures, iterative constructs
and structured programming, LO2.1: Use conditional statements in
programming Curriculum version (level): RTQF LEVEL: 4, page 284,
year 2017

Question15. Define the following terms: (2marks)


a. Algorithm
b. Flowchart
c. Variable
d. Loop

Solution:

a) Algorithm refers to a set of rules/instructions that step-by-step define how a


work is to be executed upon in order to get the expected results.

b) Flowchart: is the graphical or pictorial representation of an algorithm with


the help of different symbols, shapes and arrows in order to demonstrate a
process or a program.

c) Variable: A variable is a name assign to a storage area that the program can
manipulate. A variable type determines the size and layout of the variable's
memory.
d) Loop: is a sequence of instructions that is continually repeated until a
certain condition is reached.

References:LU1 Describe basic concept of algorithm, LO1.2 Describe the


key concepts of algorithm in programming Curriculum version (level):
RTQF LEVEL: 4, page 277, year 2017

(APPLY ALGORITHM FUNDAMENTALS) Page 10 of 21 – Marking Guides


SECTION B: ATTEMPT ALL QUESTIONS /30 MARKS
Question16. Write short note on switch statement. (3marks)

Solution: is a Switch Statement?


A sequential statement or switch case statement or simply switch
statement tests the value of a variable and compares it with multiple cases.
Once the case match is found, a block of statements associated with that
particular case is executed

References:LU2 Apply programming structures, iterative constructs and


structured programming, LO 2.2: Use sequential statements in
programming Curriculum version (level): RTQF LEVEL: 4, page 285, year
2017

Questionn17. Outline three (3) types of linked list. (3marks)

Solution:
Simple Linked List
Doubly Linked List
Circular Linked List

Reference:LU3. Describe data structure, LO3.1: Describe lists in data


structure in line with programming Curriculum version (level): RTQF
LEVEL: 4, page 288, year 2017ribe

Question18. List any three (3) basic operations from Linked List. (3marks)

Solution:

Following are the basic operations supported by a list.

• Insertion

• Deletion

• Displaying

(APPLY ALGORITHM FUNDAMENTALS) Page 11 of 21 – Marking Guides


• Updating

• searching

Reference:LU3. Describe data structure, LO3.1: Describe lists in


data structure in line with programming Curriculum version
(level): RTQF LEVEL: 4, page 288, year 2017ribe

Question19. Distinguish between primitive and non-primitive data types.

(4marks)

Solution:

Primitive Data Types: A primitive data type is pre-defined by the programming


language. The size and type of variable values are specified, and it has no
additional methods. Non-Primitive Data Types: These data types are not
actually defined by the programming language but are created by the
programmer.

References:LU1 Describe basic concept of algorithm, LO1.3: Review


relevant basic data types and operators in programming Curriculum
version (level): RTQF LEVEL: 4, page 278, year 2017

Question20. Using flowcharts, give the syntaxes of For, Do while and while
loops. (3marks)

Solution:

The syntax of for

(APPLY ALGORITHM FUNDAMENTALS) Page 12 of 21 – Marking Guides


The syntax of do while

The syntax of while

(APPLY ALGORITHM FUNDAMENTALS) Page 13 of 21 – Marking Guides


References: LU2.Apply programming structures, iterative constructs and

structured programming, LO 2.3: Use iterative statements in programming

Curriculum version (level): RTQF LEVEL: 4, page 286, year 2017

Qn21. 2. Why do we need to use arrays? (3marks)

Solution:
We can use normal variables (v1, v2, v3...) when we have a small number of
objects, but if we want to store a large number of instances, it becomes difficult
to manage them with normal variables. The idea of an array is to represent
many instances in one variable.

(APPLY ALGORITHM FUNDAMENTALS) Page 14 of 21 – Marking Guides


References:LU3 Describe data structure, LO 3.2: Describe array in line
with programming Curriculum version (level): RTQF LEVEL: 4, page 289,
year 2017

Question22. Give the syntax of switch statement. (4marks)

Solution:
A general syntax of how switch-case is implemented is as follows:

switch( expression )
{
case value-1:
Block-1;
Break;
case value-2:
Block-2;
Break;
case value-n:
Block-n;
Break;
default:
Block-1;
Break;
}
Statement-x;

References:LU2 Apply programming structures, iterative constructs and


structured programming, LO 2.2: Use sequential statements in
programming Curriculum version (level): RTQF LEVEL: 4, page 285, year
2017

Question23.Write an algorithm that allows the user to input the positive


number and displays the sum of positive numbers up to that number.

(APPLY ALGORITHM FUNDAMENTALS) Page 15 of 21 – Marking Guides


(3marks)

Solution:

Variable NUM, I, SUM as Integer


Start
Write (“enter the positive number: ”)
Read(NUM)
SUM←0
For i←1 to NUM
SUM←SUM+i
Next I
Write (“The sum of those numbers is ”, SUM)
End

References:LU2.Apply programming structures, iterative constructs and

structured programming, LO 2.3: Use iterative statements in programming

Curriculum version (level): RTQF LEVEL: 4, page 286, year 2017

Question24. Write an algorithm and a flowchart that displays the message if


the number given by a user is between 1 and 37. (4marks)

Solution:
Variable X as Integer
Start
Write(“Enter the number: ”)
If(X>=1 AND X<=37) then
Write(“The number is in the range of 1 and 37”)
Else
Write(“The number is not in the range of 1 and 37”)

(APPLY ALGORITHM FUNDAMENTALS) Page 16 of 21 – Marking Guides


End If
End

Reference:LU2 Apply programming structures, iterative constructs and


structured programming, LO2.1: Use conditional statements in
programming Curriculum version (level): RTQF LEVEL: 4, page 284, year
2019

SECTION C. ATTEMPT ALL QUESTIONS /20 MARKS

Question 25. Distinguish stack from queue data structures in algorithm.

(3marks)

Solution:

Difference Between Stack and Queue

The major difference between a Stack and a Queue is that stack is a LIFO type
while Queue is a FIFO type data structure. LIFO stands for Last in First
Out i.e. if we put data in a stack then the last entry will be processed first.
While FIFO stands for First in First Out it means the first entry in a queue will
be processed first.

References:LU3 Describe basic concept of algorithm, LO3.1 Describe lists


in data structure in line with programming Curriculum version (level):
RTQF LEVEL: 4, page 288, year 2017

Question26. Distinguish linear search from binary search. (2marks)

Solution:

Linear search is a very simple search algorithm. In this type of search, a


sequential search is made over all items one by one. Every item is checked and
if a match is found then that particular item is returned, otherwise the search
continues till the end of the data collection.
(APPLY ALGORITHM FUNDAMENTALS) Page 17 of 21 – Marking Guides
Binary search is a fast search algorithm with run-time complexity of 0(log n).
This search algorithm works on the principle of divide and conquers. For this
algorithm to work properly, the data collection should be in the sorted form.

References:LU3 Describe data structure, LO 3.3: Describe data structure


searching and sorting techniques in line with programming Curriculum
version (level): RTQF LEVEL: 4, page 290, year 2017

Question27.Write an algorithm that allows the user to input 2 numbers,


compare them and displays the maximum number. (4marks)

Solution:

Variable NUM1, NUM2 as Integer


Variable MAX as Float
Start
Write(“enter two numbers:”)
Read(NUM1,NUM2)
If(NUM1>NUM2) then
MAX←NUM1
else
MAX←NUM2
Write(”the maximum number is ”, MAX)
End If
End

Reference:LU2 Apply programming structures, iterative constructs and


structured programming, LO2.1: Use conditional statements in
programming Curriculum version (level): RTQF LEVEL: 4, page 284, year
2017

Question28. Demonstrate by the truth table the following De Morgan


theorems. (4marks)

(APPLY ALGORITHM FUNDAMENTALS) Page 18 of 21 – Marking Guides


a.
b.

Solution:
A.
A b a+b

0 0 1 1 0 1 1

0 1 1 0 1 0 0

1 0 0 1 1 0 0

1 1 0 0 1 0 0

B.

A b a.b

0 0 1 1 0 1 1

0 1 1 0 0 1 1

1 0 0 1 0 1 1

1 1 0 0 1 0 0

References:LU1 Describe basic concept of algorithm, LO1.1 convert


number system from one base to another Curriculum version (level): RTQF
LEVEL: 4, page 275, year 2017

(APPLY ALGORITHM FUNDAMENTALS) Page 19 of 21 – Marking Guides


Question29.Write an algorithm that allows the user to input a number and
display the cube of that number till the user input the negative value.
(4marks)

Solution:

Variable X as Integer

Start

Repeat
Write(“Input the number: ”)
Read(X)
If (X>0) then
Cube=X^3
Write(“The cube of ”,X, “is”, Cube)
End If
Until(X<0)
End

Reference:LU2 Apply programming structures, iterative constructs and


structured programming, LO2.2: Use conditional statements in
programming Curriculum version (level): RTQF LEVEL: 4, page 285, year
2017

Question30. Give at least three (3) rules for declaring one dimensional
array. (3marks)

Solution

Some Rules for declaring one dimensional array:


1. An array variable must be declared before being used in a program.

(APPLY ALGORITHM FUNDAMENTALS) Page 20 of 21 – Marking Guides


2. The declaration must have a data type (int, float, char, double, etc.), variable
name, and subscript.
3.The subscript represents the size of the array. If the size is declared as 10,
programmers can store 10
elements.
4. An array index always starts from 0. For example, if an array variable is
declared as s[10], then it ranges
from 0 to 9.
5. Each array element stored in a separate memory location

References:LU3 Describe data structure, LO 3.2: Describe array in line


with programming Curriculum version (level): RTQF LEVEL: 4, page 289,
year 2017

END OF MARKING GUIDES!

(APPLY ALGORITHM FUNDAMENTALS) Page 21 of 21 – Marking Guides

You might also like