Basics Flashcards

1
Q

Why do we use Big O?

A

It’s growth rate what matters, not execution time

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

Recursion

A

Some task from topcoder?

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

Insertion Sort. Write pseudocode for sorting elements in non ascending order.

A

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

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

bit shifting int x = 0x0011; int y = x << 1; y = ?

A

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

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

Translate into binary 28 = ?

A

Suppose we’re working with 8 bit quantities answer is 00011100 https://www.wikihow.com/Convert-from-Decimal-to-Binary

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

Divide&Conquer. Main idea, steps. Example of applying

A

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

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

Quick sort Write the code, estimations

A

https://www.toptal.com/developers/sorting-algorithms/quick-sort

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

Greedy

A

Read after dynamic programming

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

When insertion sort is effective?

A

When sorting a small number of entities

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

Does insertion sort use extra space?

A

It’s in place

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

What is loop invariant?

A

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.

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

What is the essence of algorithm analysis?

A

Analyzing an algorithm has come to mean predicting the resources that the algorithm requires.

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

What technology is assumed when analyzing an algorithm?

A

We shall assume a generic oneprocessor, random-access machine (RAM) model of computation

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

What is a word?

A

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.

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

What parameters does insertion sort performance depend on?

A

Input size and how nearly sorted sequence already is

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

What is the best/worst timing for Insertion Sort? Why?

A

O(n^2) the worst and O(n) the best

17
Q

Write code for MergeSort

A