Concepts Flashcards

Algorithms & Data Structure concepts

1
Q

What is a greedy algorithm?

A

A greedy algorithm builds up a solution by choosing the option that looks the best (eg: maximum or minimum of something) at every step.

Ex: giving someone an amount using the minimum number of coins

Sometimes, greedy algorithms doesn’t provide the optimal solution to a problem.

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

What is “divide and conquer”?

A

It is the act of breaking the problem down into two or more subproblems, solve them, and then use that solution to solve the original problem.

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

What is an Abstract Data Type (ADT)? Give 3 examples.

A

It is a mathematical model for a data type, defined by its behaviors from the point of view of the user of the data (not the implementor). Defines the possible operations, behaviors and values of the data type.

Ex: Integer, Tree, Stack, Map

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

What is a Data Structure?

A

It is a data organization and storage format that implements one or more Abstract Data Type.

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

What is an algorithm?

A

It is a procedure to accomplish a specific task.

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

What are heuristics?

A

They are a set of rules that may achieve a good result for a task but it is not guaranteed.
Think of as a Rule of Thumb.

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

What is the best way to disprove the correctness of a heuristics?

A

By finding a counter example.

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

According to Skiena, what is the most important single step towards a solution to a problem?

A

Modeling it in terms of well defined structures and algorithms.
Ex: it is a problem of: permutation, subset, trees, graphs, points, polygons, strings

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

What are the 3 notations used for algorithm complexity analysts?

A

O (bigOh) - represents an upper bound for an algorithm time

Big Omega - represents a lower bound
Big Theta - represents an upper an lower bound.

For those 3, we say that the real function is in the bounds given a constant and after a certain value of n (the input size), this is the assymptotic

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

What does it mean to say a time complexity function dominates another one?

A

It means it grows faster

Ex: n^2&raquo_space; n

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

What is the best way to solve an “unbounded” Knapsack problem?

A

Using a iterative approach with memoization using an array.
Starting from capacity 1 iterate until W.
For each capacity, iterate over all items.
If the item weight is less then capacity get the maximum of: itemVal + knapsack(W-itemweight)

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

What does polynomial time mean?

A

Mean a time that is O(n^k) for some k. Where N is the size of input.
Ex: O(n^2) is polynomial (selection sort)
O(n!) is not polynomial (traveling salesman)

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

In time complexity analysis, what does “size of input to a problem” mean?

A

The size of input to a problem is the number of bits required to write out that input.

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

What does pseudo polynomial time complexity mean?

A

Means that the runtime is some polynomial in the numeric value of the input, and not in the number of bits of the input.

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

What types of problems can be solved using backtracking?

A

Problems which admit the concept of a “partial candidate solution” and a relatively quick test of whether it can possibly be completed to a valid solution.

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

What are P and NP problems?

A

P are problems that can be solved in polynomial time. NP problems are problems that does not have a known polynomial time solution but given a solution we can verify if the solution is correct in polynomial time.