XxRammiyaJxX
Badges: 7
Rep:
?
#1
Report Thread starter 4 months ago
#1
The algorithm below is a sorting algorithm.

•   Array indexing starts at 0.

•   Line numbers are included but are not part of the algorithm.

1  arr ← [4, 1, 6]

2  swapsMade ← false

3  WHILE swapsMade = false

4    swapsMade ← true

5    i ← 0

6    WHILE i < 2

7      IF arr[i+1] < arr[i] THEN

8        t ← arr[i]

9        arr[i] ← arr[i+1]

10        arr[i+1] ← t

11        swapsMade ← false

12      ENDIF

13      i ← i + 1

14    ENDWHILE

15  ENDWHILE

Question 1: List all the values that variable ‘i’ will be if the algorithm above is run
Question 2: Perform a bubble sort on the list of numbers you created above. Show each time you make a swap on a new line.

PLEASE HELP ME I AM SOO CLUELESS RN (T.T)
0
reply
Liflesshype
Badges: 3
Rep:
?
#2
Report 4 months ago
#2
First of all don't panic and hey this is a test so no cheating Rammiya. Jk
Basically the list for i is 0,1,2,0,1,2(Some long working out)Since you have to do a bubble sort the working out is 0,1,2,0,1,20,1,0,2,1,20,1,0,1,2,2 1st pass0,0,1,1,2,2 2nd pass0,0,1,1,2,2 3rd pass
From liflesshype
Last edited by Liflesshype; 4 months ago
0
reply
bigman23332
Badges: 1
Rep:
?
#3
Report 4 months ago
#3
(Original post by Liflesshype)
First of all don't panic and hey this is a test so no cheating Rammiya. Jk
Basically the list for i is 0,1,2,0,1,2(Some long working out)Since you have to do a bubble sort the working out is 0,1,2,0,1,20,1,0,2,1,20,1,0,1,2,2 1st pass0,0,1,1,2,2 2nd pass0,0,1,1,2,2 3rd pass
From Andrea
y r u lying ADHIRAN
0
reply
Iamdehunte
Badges: 1
Rep:
?
#4
Report 4 months ago
#4
you lot should shush imho
0
reply
lifelesshype
Badges: 1
Rep:
?
#5
Report 4 months ago
#5
ayo these kids lying that other guy adhiran, so u prob know who I am and this is a test so don't cheat, red yellow green
Last edited by lifelesshype; 4 months ago
0
reply
X

Quick Reply

Attached files
Write a reply...
Reply
new posts
Back
to top
Latest
My Feed

See more of what you like on
The Student Room

You can personalise what you see on TSR. Tell us a little about yourself to get started.

Personalise

Should the school day be extended to help students catch up?

Yes (97)
27.71%
No (253)
72.29%

Watched Threads

View All