Datastructures Flashcards
(381 cards)
Randomized algorithm
An algorithm whose behavior is not only determined by the input, but also by the values by a random number generator.
Give the formal definition of the sorting problem
Input: A sequence of n numbers (a1, …, an)
Output: A permutation (a’1, …, a’n) of the input sequence such that a’1 <_ … <_ a’n.
The instance of a problem consists of…
the input needed to compute a solution to the problem.
When is an algorithm for a computational problem correct?
When it halts for every problem instance and outputs the correct solution.
What does n! denote?
The factorial function.
For n=6, n! = 6 x 5 x 4 x 3 x 2 x 1
data structure
A way to store and organize data in order to facilitate access and modification.
How much time does the algorithm insertion sort take to sort n items?
c1 * n^2
with c1 = constant
How much time does the algorithm merge sort take to sort n items?
c2 * n * log2(n)
with c2 = constant
keys
the numbers to be sorted in the sorting problem
What is the form of the input in the sorting problem?
An array with n elements.
satellite data
The data that the input keys are associated with.
record
The key and the satellite data.
insertion sort
An algorithm for sorting a small number of elements. A key is compared to each value and inserted when a value is encountered that is less or equal to the key.
What are the 3 things you need to show in a loop invariant?
1) initialization
2) maintenance
3) termination
What are objects composed of?
attributes
Analyzing an algorithm
Predicting the resources an algorithm requires.
RAM
Random-Access Machine
What 3 instructions does the RAM model contain?
1) arithmetic
2) data movement
3) control
What are arithmetic instructions? (7)
add, subtract, multiply, divide,
remainder, floor, ceiling
What are data movement instructions? (3)
load, store, copy
What are control instructions?
conditional and unconditional branch, subroutine call and return.
What are the data types in the RAM model?
integer, floating point and character
How do we assume integers are represented as data?
As c * log2 (n) bits
with c = a constant bigger than or equal to 1.
DIvide-and-conquer method
Breaking the problem into several subproblems that are similar to the original, but smaller in size. Solve the problems recursively and combine the solutions to create solution to original problem.