7. Algorithms Flashcards

(17 cards)

1
Q

Algorithm

A
  • Sequence of steps that solves a problem
  • Sequence of steps for accomplishing a task
  • Generating correct output for any valid input values
  • Sequence of steps to solve a computational problem or perform a calculation
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Algorithm Time Efficiency

A
  • The number of calculations required to solve a problem
  • Typically measured by the algorithm’s computational complexity
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Computational Problem

A
  • Specifies an input
  • A question about the input that can be answered using a computer
  • The desired output
  • (Input/Question/Output)
  • Describes concept of an algorithm can be written in plain English
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

NP-complete Problems

A
  • A set of problems for which no known efficient algorithm exists
  • No efficient algorithm has been found to solve an NP-complete problem.
  • No one has proven that an efficient algorithm to solve an NP-complete problem is impossible.
  • If an efficient algorithm exists for one NP-complete problem, then all NP-complete problems can be solved efficiently.
  • By knowing a problem is NP-complete, instead of trying to find an efficient algorithm to solve the problem, a programmer can focus on finding an algorithm to efficiently find a good, but non-optimal, solution.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

An algorithm with a polynomial runtime is considered efficient.

A

An efficient algorithm is generally one whose runtime increases no more than polynomially with respective to the input size. In contrast, an algorithm with an exponential runtime is not efficient.

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

Computational Complexity

A
  • The amount of resources used by the algorithm.
  • Allows different algorithms to be compared.
  • Complexity analysis is used to identify and avoid using algorithms with long runtimes or high memory usage.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Runtime Complexity

A
  • A function, T(N), that represents the number of constant time operations performed by the algorithm on an input of size N.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Best Case

A

The scenario where the algorithm does the minimum possible number of operations

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

Worst Case

A

The scenario where the algorithm does the maximum possible number of operations.

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

A best case or worst case scenario describes contents of the algorithm’s input data only. The input data size must remain a variable, N. Otherwise, the overwhelming majority of algorithms would have a best case of N=0, since no input data would be processed. In both theory and practice, saying “the best case is when the algorithm doesn’t process any data” is not useful. Complexity analysis always treats the input data size as a variable.

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

Space Complexity

A
  • Function, S(N), that represents the number of fixed-size memory units used by the algorithm for an input of size N.
  • Ex: The space complexity of an algorithm that duplicates a list of numbers is S(N) = 2N + k, where k is a constant representing memory used for things like the loop counter and list pointers.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Linear Search

A
  • Search algorithm that starts from the beginning of a list, and checks each element until the search key is found or the end of the list is reached.
  • May require searching all list elements, which can lead to long runtimes
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Runtime

A
  • The time the algorithm takes to execute.
  • If each comparison takes 1 µs (1 microsecond), a linear search algorithm’s runtime is up to 1 s to search a list with 1,000,000 elements, 10 s for 10,000,000 elements, and so on.
  • Ex: Searching Amazon’s online store, which has more than 200 million items, could require more than 3 minutes.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Binary Search

A
  • Faster algorithm for searching a list if the list’s elements are sorted and directly accessible
  • Binary search first checks the middle element of the list.
  • If the search key is found, the algorithm returns the matching location.
  • If the search key is not found, the algorithm repeats the search on the remaining left sublist (if the search key was less than the middle element) or the remaining right sublist (if the search key was greater than the middle element).
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Sorting

A
  • Process of converting a list of elements into ascending/descending order.
  • The challenge is that a program can’t “see” the entire list to know where to move an element.
  • Instead, a program is limited to simpler steps, typically observing or swapping just two elements at a time. So sorting just by swapping values is an important part of sorting algorithms.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Heuristic

A
  • A technique that willingly accepts a non-optimal or less accurate solution in order to improve execution speed.
17
Q

Heuristic Algorithm

A
  • Algorithm that quickly determines a near optimal or approximate solution