Things from notes Flashcards

1
Q

C(n, 2) = ?

Without any factorials

A

2

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

How many comparisons does an algorithm that finds duplicates in an array?

A

C(n, 2)

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

Comparisons needed to find the max value in an array?

A

n-1

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

Comparisons needed in a bubble sort?

A

C(n, 2)

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

Factorial notation for C(n, k)

A

k!(n-k)!

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

Factorial notation for P(n, k)

A

(n-k)!

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

Comparisons on n elements for search?

A

n

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

Comparisons on n elements for BSearch?

A

log2n + 1

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

General type of decomp recursions for:

Build a fractal like Koch snowflake

A

Bottom up

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

General type of decomp recursions for:

Binary search and merge

A

Divide and conquer

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

General type of decomp recursions for:

Reverse a string by moving last element to from, recurse on rest

A

Top Down

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

General type of decomp recursions for:

Check if a string is a palindrome

A

edge and middle

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

General type of decomp recursions for:

Calculate the factorial of n as a recursive program taking a single formal parameter.

A

Top Down

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

General type of decomp recursions for:

Reverse characters in an array in place.

A

Edges and middle

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

Closed form solution for the sum of n positive integers?

A

2

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

Define a function C(n) as follows:
1 if n = 0
2*C(n-1) if n > 0
What is the closed form solution?

A

2^n

17
Q

Closed form solution for sum of n odd integers?

A

n^2

18
Q

Closed form solution for sum of n even numbers?

A

n*(n+1)

19
Q

Geometric proof form closed for solution of sum of n integers?

A

Draw stacks and then duplicate and flip mirror image on to top.

20
Q

Geometric proof form closed for solution of sum of n integers?

A

Draw square made of n cubes and then add a layer for each n.

21
Q

What is proof by contraposition?

A

Prove “If P, Then Q” by the method of contrapositive means to prove “If Not Q, Then Not P”

22
Q

What is generative recursion?

A

usually decomposes the original problem into sub-problems to solve it, works on newly generated data

23
Q

What is structural recursion?

A

usually decomposes on the data orignal data rather than decomposing the problem int smaller pieces, works on smaller immediate structural component of input

24
Q

What is the difference for inductive proofs when using k or k -1 as IH?

A

For k -1 k > 1 for IH, and for k, k >= 1 for IH.

25
Q

If you have n elements how many comparisons does it take to do a search in terms of n-1?

A
T(1) = 1
T(n) = T(n-1) + 1
26
Q

If you have n elements how many comparisons does it take to do a bsearch in terms of n-1?

A
T(1) = 1
T(n) = T(n/2) + 1
27
Q

How many different binary code words are there of length n?

A

2^n

28
Q

Binomial theorem

A

if j +k = n

a^h*b^k in expansion of (a+b)^n is C(n, j)

29
Q

How to approach circle problem

A

Places to break circle * 2 on each side

30
Q

A complete graph with n vertices has how many edges?

A

n choose 2