DSA & DAA Fast Study
DSA & DAA Fast Study
DSA & DAA Fast Study
Array
Definition:
Optimal for indexing; bad at searching, inserting, and deleting (except at the
end).
Linear arrays, or one dimensional arrays, are the most basic.
Are static in size, meaning that they are declared with a fixed size.
Dynamic arrays are like one dimensional arrays, but have reserved space for
additional elements.
If a dynamic array is full, it copies it's contents to a larger array.
Two dimensional arrays have x and y indices like a grid or nested arrays.
Big O efficiency:
Definition:
Definition:
Definition:
Is a tree like data structure where every node has at most two children.
There is one left and right child node.
What you need to know:
Definition:
An algorithm that searches a tree (or graph) by searching levels of the tree first,
starting at the root.
It finds every node on the same level, most often moving left to right.
While doing this it tracks the children nodes of the nodes on the current level.
When finished examining a level it moves to the left most node on the next level.
The bottom-right most node is evaluated last (the node that is deepest and is
farthest right of it's level).
What you need to know:
Definition:
An algorithm that searches a tree (or graph) by searching depth of the tree first,
starting at the root.
It traverses left down a tree until it cannot go further.
Once it reaches the end of a branch it traverses back up trying the right child of
nodes on that branch, and if possible left from the right children.
When finished examining a branch it moves to the node right of the root then tries
to go left on all it's children until it reaches the bottom.
The right most node is evaluated last (the node that is right of all it's
ancestors).
What you need to know:
The simple answer to this question is that it depends on the size and shape of the
tree.
For wide, shallow trees use Breadth First Search
For deep, narrow trees use Depth First Search
Nuances:
Because BFS uses queues to store information about the nodes and its children, it
could use more memory than is available on your computer. (But you probably won't
have to worry about this.)
If using a DFS on a tree that is very deep you might go unnecessarily deep in the
search. See xkcd for more information.
Breadth First Search tends to be a looping algorithm.
Depth First Search tends to be a recursive algorithm.
Efficient Sorting Basics
Merge Sort
Definition:
Definition:
While it has the same Big O as (or worse in some cases) many other sorting
algorithms it is often faster in practice than many other sorting algorithms, such
as merge sort.
Know that it halves the data set by the average continuously until all the
information is sorted.
Big O efficiency:
Definition:
Definition:
Definition:
An algorithm that is called repeatedly but for a finite number of times, each time
being a single iteration.
Often used to move incrementally through a data set.
What you need to know:
Generally you will see iteration as loops, for, while, and until statements.
Think of iteration as moving one at a time through a set.
Often used to move through an array.
Recursion Vs. Iteration
Recursion | Iteration
----------------------------------|----------------------------------
recursive method (array, n) | iterative method (array)
if array[n] is not nil | for n from 0 to size of array
print array[n] | print(array[n])
recursive method(array, n+1) |
else |
exit loop |
Greedy Algorithm
Definition:
An algorithm that, while executing, selects only the information that meets a
certain criteria.
The general five components, taken from Wikipedia:
A candidate set, from which a solution is created.
A selection function, which chooses the best candidate to be added to the solution.
A feasibility function, that is used to determine if a candidate can be used to
contribute to a solution.
An objective function, which assigns a value to a solution, or a partial solution.
A solution function, which will indicate when we have discovered a complete
solution.
What you need to know: