Chapter 2: Algorithm Flashcards

1
Q

What is a pseudocode?

A

It is a detailed yet readable description of what a computer program or algorithm must do.

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

What is an algorithm?

A

1) A rule-based solution that can be used to take inputs, process inputs, and produce expected outputs.
2) A method for solving a problem.
3) A set of pre-defined steps for solving a specific problem.
4) A list of instructions to follow in order to solve a problem.

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

In mathematic notation, which is equivalent to the following statement when writing a pseudocode?
x = 4y

A

x := 4y

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

___ complexity cares more about the space taken by an algorithm, A, on problems with input size n.

A

Space

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

Given the following pseudocode, the final value of x is __.

Start
int x = 5;
for i in 1 to 3 do
x = x + i
End

A

11

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

Given the following pseudocode, what will be the final output if m=24 and n=3?

r←m%n

while r !=0 do
m←n
n←r
r←m%n
return n

A

3

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

Given the following code segment, what is the total number of executions?

for (i=1; i<17; i++)
{
cout &laquo_space;(5 / i) * 3;
}

A

16

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

The following is an example of __ time complexity.

int findRemainder(int x, int y)
{
int r = x % y;
return r;
}

A

Constant

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

If an algorithm runs in quadratic time, what is its time complexity using Big-O?

A

O(n^2)

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

Given the following code segment, the total number of executions is __.

int x = 3;
int y = 4;

for i = 1 to n do
x = x + i
y = y - i

print x
print y

A

4n + 4

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

What is the time complexity of accessing an element in an array by its index?

A

O(1)

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

Given the following codes, what is the number of total executions?

int count = 0;

for (int i = 0; i < 5; i++)
{
count++;
}

A

11

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

Given the following generic for loop, what is the time complexity?

for (int i = 0; i < n; i++)
{
// Code to be executed
}

A

O(n)

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

What is “time complexity” in algorithm analysis?

A

A measure of how long an algorithm takes to execute as a function of input size.

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

Given the following pseudo code, which Big O complexity should it be labeled?

function(x):
return x*x + 3

A

O(1)

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

A(n) __ is essentially a step-by-step procedure or set of rules designed to solve a specific problem.

17
Q

Which characteristic is NOT generally associated with a good algorithm?

18
Q

A __ provides ways of organizing and storing data.

A

Data structure

19
Q

Which is NOT an example of common computer algorithms?

A

Unforeseen events

20
Q

What is “space complexity” in algorithm analysis?

A

A measure of how much memory an algorithm uses as a function of input size.