Basics Flashcards
Why do we use Big O?
It’s growth rate what matters, not execution time
Recursion
Some task from topcoder?
Insertion Sort. Write pseudocode for sorting elements in non ascending order.
for i = 2:n, for (k = i; k > 1 and a[k] > a[k-1]; k–) swap a[k,k-1] → invariant: a[1..i] is sorted end https://www.toptal.com/developers/sorting-algorithms/insertion-sort
bit shifting int x = 0x0011; int y = x << 1; y = ?
For example, if you “decimal shifted” the number 14 left, you’d have 140 and if you did it to the right, you’d wind up with 1 (rounding down from 1.4). Decimal shifting is really just a question of multiplying and dividing by powers of 10. Bit-shifting is the same thing, but with powers of two. y = 6
Translate into binary 28 = ?
Suppose we’re working with 8 bit quantities answer is 00011100 https://www.wikihow.com/Convert-from-Decimal-to-Binary
Divide&Conquer. Main idea, steps. Example of applying
1.Find the base case (the easiest one) 2.Divide until getting to the base case. 1.DIvide problem into non-overlapping subproblems 2.Solve them recursively 3. Combine results. Examples: quick sort, merge sort
Quick sort Write the code, estimations
https://www.toptal.com/developers/sorting-algorithms/quick-sort
Greedy
Read after dynamic programming
When insertion sort is effective?
When sorting a small number of entities
Does insertion sort use extra space?
It’s in place
What is loop invariant?
A loop invariant is a property of a program loop that is true before (and after) each iteration. It is a logical assertion, sometimes checked within the code by an assertion call. Knowing its invariant(s) is essential in understanding the effect of a loop.
What is the essence of algorithm analysis?
Analyzing an algorithm has come to mean predicting the resources that the algorithm requires.
What technology is assumed when analyzing an algorithm?
We shall assume a generic oneprocessor, random-access machine (RAM) model of computation
What is a word?
A word is the natural unit of data used by a particular processor design. A word is a fixed-sized piece of data handled as a unit by the instruction set or the hardware of the processor. The number of bits in a word (the word size, word width, or word length) is an important characteristic of any specific processor design or computer architecture.
What parameters does insertion sort performance depend on?
Input size and how nearly sorted sequence already is