why is branching factor(a) is not equal to size(b)? - master-theorem

Isn't it suppose to be same? because we are dividing n units in to n/b which is having b branches in order to keep total n. i know i am misunderstanding this can any give me insight why my thinking is wrong?

Related

Finding generator g for a 20-digit prime integer I'm Elgamal

I was curious to learn if there is a simple method/algorithm through which I can obtain a generator g for a 20-digit prime integer to implement in Elgamal cryptosystem.
The best way to do this is pick your prime such that finding a generator is easy. Often the best way is to find a prime p such that q=2p+1 is also prime. Then in the multiplicative group of order q, elements will have order 2p, p, 2 or 1. Most will have order 2p, so just pick a number g and check that g^2 and g^p are not 1, then it will have order 2p and thus be a generator of the group.
If the prime is given (say q), then the order of the group will be q-1 and you will need to factorise q-1 into prime factors (which is not always easy). Then when picking your candidate g, you need to check that g^x (for x ranging through all combinations of prime factors that are less than q-1) is not 1, then you'll know that g has order q-1 and is a generator. Which is why, if you can pick your prime q, it's easier to make sure that q-1 factorises nicely into just two primes.

Reducing partition prob to decision prob

We have the related and well known problems:
1) PARTITION (decision problem):
Given a set S of n natural numbers. Is it possible to find a subset T of S such that the sum of the numbers of T is equal to the sum of the numbers of T\S?
2) PARTITION (general problem):
Given a set S of n natural numbers. Assuming the answer of the decision problem 1) to this set is 'yes' then find such a subset.
Simple question: How can we solve 2) in polynomial time if we have an algorithm that solves 1) in polynomial time?
Solution: Suppose we want to partition a set S of n natural numbers with the sum equal to a number b and we have a blackbox algorithm that solves the decision problem in polynomial time.
1: If the answer of the partition problem of S is no, then return.
2: Pick an element x of S.
3: If x is equal to b/2 return S\x (partition found).
4. Merge x with another element y of S (set x=x+y and set S=S\y) which is not processed yet.
5: Solve the decision problem for S.
6: If the answer is no then revert step 4, mark y as processed.
7: Go back to step 3.
Each time we repeat step 2 we have to solve a decision problem in polynomial time. Since we only have to repeat step 2 at most n-1 times, the overall time complexity is also polynomial.

unable to get the odds of a user- bayes theorm

I'm trying to solve the question which is quite basic using confusion matrix but my solution is not matching the correct solution.
Q: Let's say we have a drug test that can accurately identify the users of a drug 99% of the time, and accurately has a negative result for 99% of non-users. But only 0.3% of the overall users use this drug.
What are the odds of someone being an actual user of the drug given that they tested positive?
Also, is TP / (TP + FN) is same as P(A) P(B|A)/P(B) ?
My Approach:
TP TN Total
Users Predicted positive 29.7 0.3 30
Non-Users Predicted negative 99.7 9870.3 9970
129.4 9870.6 10000
From the above data, I got : 29.7/129.4 = 0.2295208655 around 22.95%
But the solution states : 22.8% . I'm confused. What is the right way to do this?
I got it :
The approach which was given was something like this - P(B) is 1.3% ( 0.99*0.003 + 0.01*0.997) So, P(B|A) = P(A) P(B|A) / P(B) = 0.003*0.99 / 0.013 = 0.228 . So, '22.8%'
But they have rounded the number to 1.3% instead of 1.294% and that's why the value is different!!

Number of BST's given a linked list of numbers

Suppose I have a linked list of positive numbers, how many BST's can be generated from them, provided all nodes all required to form the tree?
Conversely, how many BST's can be generated, provided any number of the linked list nodes can exist in these trees?
Bonus: how many balanced BST's can be formed? Any help or guidance is greatly appreciated.
You can use dynamic programming to compute that.
Just note that it doesn't matter what the numbers are, just how many. In other words for any n distinct integers there is the same amount of different BSTs. Let's call this number f(n).
Then if you know f(k) for k < n, you can get f(n):
f(n) = Sum ( f(i) + f(n-1-i), i = 0,1,2,...,n-1 )
Each summand represents the number of trees for which the (1+i)-th smallest number is at the root (thus in the left subtree where are i numbers and in the right subtree there are n-1-i).
So DP solves this.
Now the total number of BSTs (with any nodes from the list) is just a sum:
Sum ( Binomial(n,k) * f(k), k=1,2,3,...,n )
This is because you can pick k of them in Binomial(n,k) ways and then you know that there are f(k) BSTs for them.

question about inversion

I have read something in the site that inversion means if i<j then A[i]>A[j] and it has some exercises about this , I have a lot of questions but I want to ask just one of them at first and then i will do the other exercises by myself if I can!!
Exercise: What permutation array (1,2, ..., n) has the highest number of inversion? What are these?
thanks
Clearly N, ..., 2, 1 has the highest number of inversions. Every pair is an inversion. For example for N = 6, we have 6 5 4 3 2 1. The inversions are 6-5, 6-4, 6-3, 6-2, 6-1, 5-4, 5-3 and so on. Their number is N * (N - 1) / 2.
Well, the identity permutation (1,2,...,n) has no inversions. Since an inversion is a pair of elements that are in reverse order than their indices, the answer probably involves some reversal of that permutation.
I have never heard the term inversion used in this way.
A decreasing array of length N, for N>0, has 1/2*N*(N-1) pairs i<j with A[i]>A[j]. This is the maximum possible.