Pseudo code Flashcards
1
Q
How do you make a program loop a set number of times?
A
for i = 0 to 4 #contents next i or for i = 0 to len(list) #contents next i
2
Q
What do you do at the top of a pseudo code program?
A
Define all the variable data types e.g. maxNum is integer Mean is real name is string check is boolean
3
Q
How do you define an if statement?
A
if #code such as list(i) > MaxNum:
#task
endif
4
Q
How do you define a while statement?
A
while
end while
5
Q
What is better merge sort or bubble sort?
A
Merge sort as it is more efficient.
6
Q
What is the pseudo code for bubble sorts?
A
Declare BubbleSort(bubbleList): exchanges = True passnum = len(bubbleList)-1 while passnum > 0 and exchanges = True exchanges = False for i = 1 to n if bubbleList[i]>bubbleList[i+1]: exchanges = True temp = bubbleList[i] bubbleList[i] = bubbleList[i+1] bubbleList[i+1] = temp end if next i passnum = passnum-1 end while end Subroutine
bubbleList=[20,30,40,90,50,60,70,80,100,110]
BubbleSort(bubbleList)
print(bubbleList)