Algorithms Flashcards

1
Q

Is there a difference between a Problem and an Algorithm?

A

Yes

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

Problem

A

description which associates inputs to output states

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

Problems include 2 things

A

precondition + postcondition

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

Does a problem statement itself indicate how to solve the problem?

A

No; just pre and post

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

Algorithm

A

describes a possible sequence of steps which when carried out solves a problem by meeting post conditions upon completion.

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

Do algorithms have to meet a problems’ post conditions upon completion?

A

yes

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

Function details can be hidden T or F?

A

True

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

Pseudocode

A

english-like representation of algorithm logic

and is independent of implementation language

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

in pseudocode, do we explicitly declare primitive data items? (eg. int number)

A

no.

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

Conventions for variable names:

A
  1. meaningful names
  2. no single-char names except for loops
  3. Do not use generic names : count sum row
  4. use descriptive names
  5. use abbreviations
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Is this a valid Psuedocode variable name?

count

A

NO

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

Is this a valid Psuedocode variable name?

add

A

NO

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

Is this a valid Psuedocode variable name?

thisPointer

A

Yes

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

Is this a valid Psuedocode variable name?

a :: character

A

NO

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

Is this a valid Psuedocode variable name?

pow

A

NO

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

Psuedocode algorithm headers include:

A
Name
Description
Preconditions
Postconditions
return
17
Q

Psuedocode has 3 kinds of statements:

A

sequence of statements [blocks]
loop statement
conditional statement [if/else]

18
Q

Psuedocode: sequences

A

dont alter execution path within the algorithm

  1. assignment
  2. input
  3. output
  4. Arithmetic expressions
  5. higher-level english descriptions
19
Q

another name for guarded loop?

A

while loop

20
Q

How do we measure running time?

A

in steps

21
Q

Implementation-independent Method

A

running time as a relationship between size of the input n, and the number of time units t needed to execute the algorithm

22
Q

primitive operations

A
all take the same amount of time;
assigning a value to variable
calling another algorithm
performing an arithmetic operation
indexing into an array
comparing two values
following an object reference
returning from a method
23
Q

asymptotic complexity or time complexity

A

only consider the term that grows the fastest to characterize algorithms

24
Q

what is the lowest big Oh?

A

log log n

25
Q

what is the biggest big Oh?

A

n!

26
Q

which is a bigger oh? n^k or a^n ?

A

a^n cannot expect to solve tho

27
Q

algorithms with polynomial or better time complexity are considered:

A

tractable

28
Q

algorithms with exponential (or worse) complexity are considered:

A

intractable

29
Q

T or F : problems with simple descriptions cannot be intractable.

A

False

30
Q

what is the worst case tractable Big OH?

A

n^k polynomial

31
Q

what is the best case intractable BIG OH?

A

k^n exponential

32
Q

The travelling salesman problem is:

A

a bunch of cities and find the cheapest route between them all; grows exponentially if you try them all.

33
Q

Knapsack problem is:

A

what is the most valuable subset of items whose weight does not exceed some threshold ?
grows exponentially

34
Q

what type of problem is worse than intractable/

A

undecidability

35
Q

an example of an undecided problem?

A

post’s correspondence problem

36
Q

undecided problem:

A

can’t find a solution