Algorithms & Computation Flashcards

1
Q

What is peak finding?

A

Finding a number in a sequence that is greater in value than all its neighbors.

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

How efficient are selection sort and bubble sort in the worst case scenario?

A

O(n^2).

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

How does bubble sort work? What about selection sort?

A

Bubble sort compares a pair and switches their place f the first is larger. Selection sort finds the smallest in the set, moves it to the front, and then recursively repeats after the sorted element.

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

For an ordered list, binary search is of the complexity

A

log(n); divide and conquer algorithms tend to be of logarithmic time complexity.

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

What is merge sort and how efficient is it?

A

nlog(n) — the set is divided into singleton lists by halving (log(n) component) and then individual sorted by direct comparison (n component).

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

Describe a stochastic process.

A

In a stochastic process there is an element of randomness and unpredictability. A random walk is an example of a stochastic process and models many physical systems, for example molecule diffusion. Stochastic processes are in contrast to deterministic processes.

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

What is memoization?

A

Storing the solutions to subroutines in memory to avoid having to recompute them later, as part of dynamic programming.

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

A technique for reducing exponential time problems to polynomial time by reducing them to subroutines whose solutions are stored and later retrieved from memory is:

A

dynamic programming.

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

RAM is basically a huge array of memory, maybe 4GB these days. What is the time complexity of data access in RAM if you know the address?

A

Constant time.

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

What is document distance?

A

An algorithmic approach to comparing two text documents to determine how similar they are. One way to solve document distance is to create a vector for each document representing the frequency of all the words.

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

What is a method of optimizing a data structure which tracks if items are connected?

A

Creating a weighted tree, which could be modeled as an array with each entry representing the parent node. In the weighted tree, a union of nodes always attaches the smaller of the two to the larger, producing a flatter tree structure overall. The proven most optimized solution is weighted quick union with path compression, which reduces the problem from 30 years to 6 seconds. This is why algorithm design is critical, having a supercomputer would not help you much here.

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

Modeling percolation experiences a phase transition at a point that cannot be calculated mathematically, but determined computationally by

A

a weighted quick union with path compression algorithm which models the connections.

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

Describe how the scientific method can be applied to algorithmic design.

A

Mathematical or conceptual theory can form a basis for design which can then be tested and evaluated empirically to determine performance and then iteratively improved.

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

Algorithms that divide the input in half progressively are typically characterized by what order of growth?

A

logarithmic; log(n)

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

A simple looping algorithm has what time complexity?

A

Linear, O(n)

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

Executing statements without any looping constructs takes place in

A

constant time, O(1)

17
Q

Divide and conquer merge sort has what time complexity?

A

Linearithmic, O(nlog(n)); log(n) for the recursive binary division of the data, n for the merge operation between all elements.

18
Q

A double for loop has what order of growth? What about a triple for loop?

A

double for loop: O(n^2)

triple for loop: O(n^3)

19
Q

What is the worst time complexity? What is the best? What is practically the ideal complexity achieved in algorithm design?

A

Exponential is the worst, constant time is the best, linear or linearithmic is typically the best achieved in a practical setting.

20
Q

Using a variable name in an inner scope that is the same as the name of a variable in an outer scope is referred to as

A

variable shadowing.

21
Q

Which sorting algorithm requires more memory in order to execute, merge sort or insertion sort?

A

Merge sort, which requires n auxiliary memory. Insertion sort functions in place.

22
Q

What is a max heap?

A

A complete binary tree in which the value of every internal node is greater than its children.

23
Q

What is an AVL tree?

A

An AVL tree is a self-balancing binary search tree. An unbalanced search tree could exist such that the height is on the order of N, rather than log(n). This is obviously a disadvantage. AVL trees are balanced using tree rotations which change the tree structure without changing its order.

24
Q

How does one-way cryptographic hashing work?

A

A password (x) is hashed to a value h(x) = Q which is stored, future authentication attempts are hashed and compared to this value ( h(x’) == h(x) ; Q’ == Q ). It is basically prohibitive to reverse the hash function to determine the original password value.

25
Q

What is the Rabin–Karp algorithm?

A

It is a string search matching algorithm using a rolling hash technique to achieve a linear running time. For string s in string t, O(n) = O(s + t).

26
Q

What is open addressing?

A

A technique for dealing with collisions in hash tables. Collisions result in probing in which alternate destinations in the array are searched (probed) until an empty slot is discovered. Subsequently, searching will invoke probing in a deterministic manner until the key or an empty slot is ofund.

27
Q

What is hash chaining?

A

A method of dealing with hash collisions in which multiple keys map to a specific hash value and all are stored there, for example a hash table implemented as an array could store linked lists in each array index containing all hash keys for that index. Or, a Python array of dicts.

28
Q

Name two methods of dealing with collisions produced from hash functions?

A

Chaining and open addressing.

29
Q

What is the Karatsuba Algorithm? What is an even better improvement than this?

A

The Karatsuba Algorithm is a multiplication algorithm for a number of length n which improves the classical n^2 time complexity of multiplication to n^1.585. The Toom-Cook Algorithm runs in n^1.465 time and works by breaking multiplication into smaller subroutines which allow 9 multiplications to be achieved by 5. The Schönhage–Strassen Algorithm and Furer’s Algorithm are even better than this.

30
Q

What is dynamic programming?

A

Dynamic programming is an approach to algorithm design which utilizes memoization and guessing and is often applied to optimization problems.

31
Q

What is Dijkstra’s algorithm?

A

A method for finding the shortest path between nodes in a graph.