1/24
paper 2 computational thinking
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Ask user for an integer input
int(input()
When would you use a while loop?
When it is not known how many times iteration will occur.
while loop which will add 1 onto 0 until it reaches 8
number = 0
while number != 8:
number = number + 1
print ("The number is",number)
while loop
condition controlled
for loop
count controlled
count controlled meaning
you specify the number of times that you wish the iteration to be repeated
for loop, repeat 10 times until it reaches 5
for i in range(10):
if i == 5:
break
print(i)
MOD definition (%)
calculates the remainder of a division
iteration
The repetition of a block of statements within a computer program.
selection
the process of making a decision which result will decide which path it takes next
sequence
a set of instructions that follow on one from another
nesting
one programming construct within another
start/end
process
input/output
if
flow
sub program
Abstraction
Removing the unnecessary parts of a problem so that you only focus on the important parts
Decomposition
Breaking a complex problem down into smaller problems so that it is more manageable/easier to solve
Binary Search: Process
1) Find the middle item in the ordered list.
2) If this is the item you’re looking for, stop the search.
3) If not, compare the item your looking for to the middle item. If it comes before the middle item, get rid of the second half of the list. If it comes after the middle item, get rid of the first half of the list.
4) Repeat steps 1-3 until the item is found.
Linear Search
1) Look at the first item in the unordered list.
2) If this is the item you’re looking for, stop the search.
3) If not, look at the next item in the list
4) Repeat steps 2/3 until you find the item.
Is a linear search as efficient as a binary search?
No
Should you use a linear search for smaller lists?
Yes
What is a benefit to a linear search?
It is simple and can be done on an unordered list.