MG - Software Development L4 - Algorithm Fundamentals
MG - Software Development L4 - Algorithm Fundamentals
MG - Software Development L4 - Algorithm Fundamentals
MARKING GUIDES
SECTOR: ICT
RTQF LEVEL: 4
DURATION: 3 HOURS
DATE: TIME:
INSTRUCTIONS TO CANDIDATES:
Materials allowed:
Solution
b. 19310 =11000001 2
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) True
c) True
d) True
e) False
Solution:
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
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
Question6. Explain the following concept While loop and For loop in
algorithm. (3marks)
Solution:
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.
Solution:
A linked list is a sequence of data structures, which are connected together via
links.
Solution:
The algorithm and flowchart are classified into three types of control
structures.
1. Sequence
2. Branching(Selection)
3. Loop(Repetition)
Question11. List three (3) main types of loop statements found in programming
languages. (3marks)
Solution:
c) DO WHILE statement
(2marks)
Solution:
Push Operation:
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.
Solution:
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.
Qn14. Write an algorithm that solves the first order equation of the form
ax+b=0.
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
Solution:
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.
Solution:
Simple Linked List
Doubly Linked List
Circular Linked List
Question18. List any three (3) basic operations from Linked List. (3marks)
Solution:
• Insertion
• Deletion
• Displaying
• searching
(4marks)
Solution:
Question20. Using flowcharts, give the syntaxes of For, Do while and while
loops. (3marks)
Solution:
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.
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;
Solution:
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”)
(3marks)
Solution:
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.
Solution:
Solution:
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
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
Question30. Give at least three (3) rules for declaring one dimensional
array. (3marks)
Solution