0% found this document useful (0 votes)
6 views3 pages

Worksheet 01 Q

The document outlines a series of tasks for a programming assignment, including converting algorithms to code, testing the programs, and documenting results. It specifically covers bubble sort and binary search algorithms, requiring students to implement them in code and analyze their efficiency. Additionally, students must provide screenshots of their test results in an evidence document.

Uploaded by

Abdullah Zakaria
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views3 pages

Worksheet 01 Q

The document outlines a series of tasks for a programming assignment, including converting algorithms to code, testing the programs, and documenting results. It specifically covers bubble sort and binary search algorithms, requiring students to implement them in code and analyze their efficiency. Additionally, students must provide screenshots of their test results in an evidence document.

Uploaded by

Abdullah Zakaria
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Mr.

Mahmoud Moussa A2 CS 9618

Worksheet #01 Questions


Open the document Evidence.doc.
Make sure that your name, centre number and candidate number will appear on every page of this
document.
This document will contain your answers to each Task.
Save this evidence document in your work area as: Evidence_ followed by your centre
number_candidate number, for example: Evidence_zz999_9999
Task – 01 a

Convert the following algorithm to program Code

[0] [1] [2]

10 9 8

n ← 2 // n is The number of elements to compare in each pass


FOR i ← 0 TO n - 1
FOR j ← 0 TO n - 1
IF (MyList[j] > MyList[j + 1])THEN
Temp ← MyList[j]
MyList[j] ← MyList[j + l]
MyList[j + 1] ← Temp
ENDIF
NEXT j
NEXT i

Copy and paste the program code into the evidence document.
Task – 01 b

Test your program.


Take a screenshot to show the result of the test
Copy and paste the screenshot into the evidence document.

www.mahmoudmoussa.com 1
Mr. Mahmoud Moussa A2 CS 9618

Task – 01 c

Study the following pseudocode. Then convert it to a program code


NumberOfItems ← 3
REPEAT
NoMoreSwaps ← TRUE
FOR J ← 0 TO (NumberOfItems - 2)
IF(MyList[J] > MyList[J + 1])THEN
Temp ← MyList[J]
MyList[J] ← MyList[J + 1]
MyList[J + 1] ← Temp
NoMoreSwaps ← FALSE
ENDIF
NEXT J
NumberOfItems ← NumberOfItems - 1
UNTIL NoMoreSwaps = True

Copy and paste the program code into the evidence document.
Task – 01 d

Test your program.


Take a screenshot to show the result of the test
Copy and paste the screenshots into the evidence document.

Which algorithm is more efficient?


The second algorithm is more efficient

www.mahmoudmoussa.com 2
Mr. Mahmoud Moussa A2 CS 9618

Task – 02 a

Study the algorithm, written in pseudocode, for a binary search. The data being searched is stored in
the array SearchData[63]. The item of data being searched is stored in the variable
SearchItem.

X ← 0
Low ← 1
High ← 63
WHILE (High >= Low) AND X = 0
Middle ← INT((High + Low)/2)
IF SearchData[Middle] = SearchItem THEN
X ← Middle
ELSE
IF SearchData[Middle] < SearchItem THEN
Low ← Middle + 1
ELSE
IF SearchData[Middle] > SearchItem THEN
High ← Middle - 1
ENDIF
ENDIF
ENDIF
ENDWHILE

The binary search only works if the data in the array being searched is:
ordered / in order
The maximum number of comparisons that are required to find an item which is present in the array
SearchData is:
6 According to the pseudocode given
At the end of the algorithm, the variable X contains:

either the value 0 which indicate item not present in array


or the value none zero which indicates position of the item in the array
Convert the above pseudocode to a Python program
Task – 02 b

Test your program with one value that is in the array and one value that is not in the array.
Assume the array contains [100,200,300,400]

Take a screenshot to show the result of each test


Copy and paste the screenshots into the evidence document.

www.mahmoudmoussa.com 3

You might also like