Algorithms Flashcards

1
Q

What cannot be divided?

A

Simple Variables

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

What is a top level (main) module do?

A

Expresses the task

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

What way do you get to the next “if’ statement?

A

If the first expression is not true.

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

What are the two basic loops?

A

Count Controlled and Event controlled

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

What is a count-controlled loop?

A

A loop that repeats itself a specific number of times.

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

what are the three distinct parts to the count-Controlled loop?

A

Initialization. Testing. Incrimination.

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

What is called a pretest loop?

A

While Loop

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

What is a loop that never terminates?

A

An infinity loop

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

What is an event-controlled loop?

A

Loops where the number of repetitions is controlled by an event that occurs with the body of the loop itself

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

When implementing an event-controlled loop using the While statement, what are the three parts to this?

A

Initialized. Tested. Updated

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

What is an algorithm with selections?

A

A pseudocode with selections to choose from

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

Read this pseudocode
If (temperature > 90)
Write “Texas weather: Wear shorts”
ELSE IF (temperature > 70)
Write “ideal weather: short sleeves are fine”
ELSE IF (temperature > 50)
Write “A little chilly: wear a light jacket”
ELSE IF (temperature > 32)
Write “Philadelphia weather: wear a heavy coat”
ELSE
Write “Stay inside”

A

If the temperature is above 90, it will tell you that it is Texas weather to wear shorts.
If the temperature is above 70 but below 90, it will tell you that it is ideal weather and it is ok to wear short sleeves.
If the temperature is above 50 but below 70, it will tell you that it is chilly and to wear a light jacket.
If the temperature is above 32 but less than 50, it will tell you that it is Philadelphia weather and to wear a heavy coat.
If none of these are true, it will tell you to stay inside.

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

What is the result of this code?

IF (myNum MOD 2 == 0)
Print “Even”
ELSE
Print “Odd”

A

Checks if a number (myNum) is even or odd, by using the modulo or odd. If the remainder when dividing by 2 is zero, the number is even, otherwise its odd

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

What is the result of this code?

IF (num1 > num2)
Print “num1 is greater”
ELSE
Print “num2 is greater”

A

Compares two numbers (num1 and num2) and prints which one is greater

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

What is the result of this code?

Set factorial to 1
Set counter to 1
WHILE (counter <= n)
Set factorial to factorial * counter
Set counter to counter + 1
Print “The factorial is “, factorial

A

Calculates the factorial of a number (n) by multiplying all integers from 1 to n

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

What is the result of this code?

Set sum to 0
FOR each element in array
Set sum to sum + element
Print “The sum of the array is “, sum

A

sums all the elements in an array and prints the results

17
Q

What is the result of this code?

Set max to array[0]
FOR each element in array
IF (element > max)
Set max to element
Print “The largest number is “, max

A

Finds the largest number in the array by iterating through each element and updating the max variable if a larger number is found.