[go: up one dir, main page]

0% found this document useful (0 votes)
386 views2 pages

Section 1 - Questions - Bubble Sort - Examples

The document provides pseudocode for bubble sort algorithms to sort data in a 2D array and 1D array in ascending and descending order, respectively. It asks the student to write code for main programs that initialize the arrays, implement the bubble sort algorithms without built-in functions, and output the sorted arrays. The student is to save their programs and provide code snippets and output screenshots as evidence.

Uploaded by

oazzazyschool
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)
386 views2 pages

Section 1 - Questions - Bubble Sort - Examples

The document provides pseudocode for bubble sort algorithms to sort data in a 2D array and 1D array in ascending and descending order, respectively. It asks the student to write code for main programs that initialize the arrays, implement the bubble sort algorithms without built-in functions, and output the sorted arrays. The student is to save their programs and provide code snippets and output screenshots as evidence.

Uploaded by

oazzazyschool
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/ 2

Computer Science A2

Section 1 – Bubble Sort


CS - A2 – CLASSIFIED
9618/42
Paper 4 Further Problem-solving and Programming Skills May / June 2022
2. A 2D array stores data entered by a user.
(a) The main program declares a 2D array of 10 by 10 integer elements.
The array is initialised with a random number between 1 and 100 in each element.
Write program code for the main program.
Save your program as Question2_J22.
Copy and paste the program code into part 2(a) in the evidence document. [4]
(b) The following bubble sort pseudocode algorithm sorts the data in the first dimension of the 2D
array into ascending numerical order.
ArrayLength 10
FOR X 0 TO ArrayLength - 1
FOR Y 0 TO ArrayLength - 2
FOR Z 0 TO ArrayLength - Y - 2
IF ArrayData[X, Z] > ArrayData[X, Z + 1] THEN
TempValue ArrayData[X, Z]
ArrayData[X, Z] ArrayData[X, Z+1]
ArrayData[X, Z + 1] TempValue
ENDIF
NEXT Z
NEXT Y
NEXT X
(i) Amend your main program by writing program code to implement the bubble sort algorithm
after the initialisation of the array elements.
You must not use any built-in sorting functions for your programming language. S
ave your program.
Copy and paste the program code into part 2(b)(i) in the evidence document. [5]
(ii) Write program code for a procedure to output all the values in the 2D array. The values
should be output as a 2D grid, with values in rows and columns.
Call the procedure before and after your bubble sort code.
Save your program.
Copy and paste the program code into part 2(b)(ii) in the evidence document. [3]
(iii)Test your program. Take a screenshot to show the output. Copy and paste the screenshot
into part 2(b)(iii) in the evidence document. [1]

e-mail: sherrost@yahoo.com Tel: 01501827070 - 01017776756


Computer Science A2
Section 1 – Bubble Sort
9618/41
Paper 4 Further Problem-solving and Programming Skills May / June 2021
2. A program stores the following ten integers in a 1D array with the identifier arrayData.
10 5 6 7 1 12 13 15 21 8
(c) The following bubble sort pseudocode algorithm sorts the data in theArray into descending
numerical order. There are five incomplete statements.
PROCEDURE bubbleSort()
DECLARE temp : INTEGER
FOR x 0 to …………………………………
FOR y 0 to …………………………………
IF theArray[y] ………………………………… theArray[y + 1] THEN
temp theArray[y]
theArray[y] …………………………………
theArray[y + 1] …………………………………
ENDIF
NEXT y
NEXT x
ENDPROCEDURE
Write program code for the procedure bubbleSort() to sort the data in arrayData into descending
order.
Save your program.
Copy and paste the program code into part 2(c) in the evidence document. [6]

e-mail: sherrost@yahoo.com Tel: 01501827070 - 01017776756

You might also like