Algorithms and Programming Flashcards

1
Q

What percentage of times will it Display True

Display (1,5) = 6 AND Random (1,5) <=5

A

0%

False True = False (The first condition will be executed)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

a = Random (1,4)
Display a=3
What is the chance 3 will be selected? Not being selected?

A
1/4 = 25%
3/4 = 75%
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

False AND True or False

A

False (if at least one condition is false)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

True OR True or False

A

True (if one condition is at least true)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

False OR True

A

True (One argument is true)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

True AND True

False AND False

A

Both arguments are Ture

Both Arguments are False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is Binary Search a what is the most important thing when finding a number?

A

The list must be sorted. Start with the middle element. and compare it to to the sides. Must equal to the target number

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How many numbers would comparisons would it take to find the number 11? (11, 32, 34, 43, 45,) How about 45?

A

1 comparison because it is the first element in the list.

10 comparisons because it is at the end and is the worst case.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is Linear Search?

A

Algorithm to find an element in a list. Can be unsorted or sorted

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the percentage it would display True?
a = Random (1, 10)
Display a<= 3

A

a<=3 includes 1, 2, 3, so out of 10 it would be;

3/10= 30%

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

x=10
Repeat Until x>=10
x=x+3
Display x

What value is displayed?

A

10 because x=10 it flows the condition x>=10

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

x=10
Repeat until x>=10
x = x+3
Display x

What value is displayed?

A

10, >=10

10 is displayed

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

If the Display statement is out of the loop what happens?

A

Only one number will be displayed

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

If the Display statement is in the loop what happens

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

x=0
repeat 3 times
Repeat 4 times
x= x+1

Display x

A

x=12 4*3

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Does 0 or the staring variable count in a loop?

A

No

17
Q
x=0
y=0
repeat 3 times
repeat until y=3
y=y+3
x=x+3

y=0

Display x

A

x= 23

18
Q
x=0
y=0
repeat 3 times
repeat until y=3
y=y+1
x=x+1

Display x

A

3

19
Q
x=0
y=0
repeat 3 times
repeat until y=3
y=y+1
x=x+1

y=0

Display y

A

0

20
Q

How many times will fish be displayed?

a= 1
Repeat 5 times
If (a>3)
Display “fish”

a= a+1

A

1, 2, 3, 4, 5
2 times
4 > 3
5 > 3

21
Q

What are all accurate ways to display an algorithm?

a) pseudocode
b) flowchart
c) block statements
d) all of the above

A

d) all of the above

22
Q

What can computers only read?

A

Machine Code– Low-level language!

23
Q

If an algorithm is translated exactly into a higher-level language, like Python, will the solution utilize work?

A

Yes because an exact translation of an algorithm affects only the way that it is read.

24
Q

What is a heuristic solution and which would be considered as one below?

a) A file organizing files based on certain data
b) A bubble search algorithm
c) An anti-virus program to scare the entire file
d) A searching algorithm to detect text strings in a document.

A

a)
Heuristics methods are intended to be flexible and are used for approximate solutions and run under unreasonable time.
When finding an optimal solution, it is impossible or impractical and when working with complex and large sets of data.
Leads to poor decisions, with limited data.

25
Q

What is a simulation?

A

can take out some variables that are unnecessary and use specific pieces to simulate a situation
to help us make decisions and figure out the best course of action.

26
Q

How do I change a-b to b-a

A
temp = a
a = b
b = temp
27
Q

What is a library and what are the benefits?

A

Libraries contain Procedures that

28
Q

What is a string concatenation?

A

Two or more strings attached together end to end to make a new string : “Ap”+ “CS” = APCS

29
Q

What are Procedures Parameters and Arguments?

A
Procedures basically function in Python. For example, 
Procedure mystery (x,y) (3,4)
(x,y)= parameter 
x=4, y=3 are arguments when a procedure is called
30
Q

Reasonal and Unreasoal Time

A

Reasonable time to execute algorithm: Polynomial(3n^2+4N^2)(n)(100n^4)
Unreasonal time: Exponential:(3^n)