Algorithms and Programming Flashcards
What percentage of times will it Display True
Display (1,5) = 6 AND Random (1,5) <=5
0%
False True = False (The first condition will be executed)
a = Random (1,4)
Display a=3
What is the chance 3 will be selected? Not being selected?
1/4 = 25% 3/4 = 75%
False AND True or False
False (if at least one condition is false)
True OR True or False
True (if one condition is at least true)
False OR True
True (One argument is true)
True AND True
False AND False
Both arguments are Ture
Both Arguments are False
What is Binary Search a what is the most important thing when finding a number?
The list must be sorted. Start with the middle element. and compare it to to the sides. Must equal to the target number
How many numbers would comparisons would it take to find the number 11? (11, 32, 34, 43, 45,) How about 45?
1 comparison because it is the first element in the list.
10 comparisons because it is at the end and is the worst case.
What is Linear Search?
Algorithm to find an element in a list. Can be unsorted or sorted
What is the percentage it would display True?
a = Random (1, 10)
Display a<= 3
a<=3 includes 1, 2, 3, so out of 10 it would be;
3/10= 30%
x=10
Repeat Until x>=10
x=x+3
Display x
What value is displayed?
10 because x=10 it flows the condition x>=10
x=10
Repeat until x>=10
x = x+3
Display x
What value is displayed?
10, >=10
10 is displayed
If the Display statement is out of the loop what happens?
Only one number will be displayed
If the Display statement is in the loop what happens
It will display the number of times the condition is said to repeat For example; repeat 3 times, the display statement will display 3 numbers.
x=0
repeat 3 times
Repeat 4 times
x= x+1
Display x
x=12 4*3