Algorithms Flashcards

1
Q

Properties of a Recursive Algorithm

A
  • A recursive algorithm must have a termination condition.
  • A recursive algorithm must change its state, and shift the state toward the termination condition.
  • A recursive algorithm must be capable of calling itself.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Define:

Euclidean algorithm

A

Euclidian algorithm is based on the principle that the greatest common divisor of two numbers does not change if the largest number is replaced by its difference with the smaller number.
Since this replacement reduces the largest of the two numbers, repeating this process gives successively smaller pairs of numbers until two numbers become equal. When that occurs, they are GCD (Greatest Common Divisor) of the original numbers.

Let d be GCD for m and n. Then m = d * a and n = d * b. So m - n ~ a--

The version of the Euclidian algorithm described above can take many substractions steps to find the GCD when one of the given numbers musch bigger than the other. A more efficient version of the algorithm shortcuts these steps, instead replacing the larger of the two numbers by its reminder when divided by the smaller of the two.

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

Basic guidelines for the constraints for an array of numbers

A
  • What is the maximum number of elements in an array?
  • What is the spectrum of each element?
  • What are the minimum and maximum values?
  • What type of information is contained in each element? Is it floating-point or integer?
  • Does the array contain unique data or not?
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Basic guidelines for the constraints for an array of string

A
  • What is the total number of elements in the array?
  • How long are each of the strings? What is the shortest and longest length?
  • Does the array contain any data that is unique?
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Basic guidelines for the constraints for a graph

A
  • In the graph, how many nodes are there?
  • How many edges does the graph have?
  • Is the graph weighted? What is the weight range?
  • Does the graph have directed edges or undirected edges?
  • Does the graph have a loop?
  • Does the graph have a negative sum loop?
  • Are there any self-loops in the graph?
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Strategy to solve problems

A
  • Constraints analysis
  • Ideas generation
  • Complexity analysis
  • Coding
  • Testing
How well did you know this?
1
Not at all
2
3
4
5
Perfectly