Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does Logn actually mean?

I am just studying for my class in Algorithms and have been looking over QuickSort. I understand the algorithm and how it works, but not how to get the number of comparisons it does, or what logn actually means, at the end of the day.

I understand the basics, to the extent of :

x=logb(Y) then
b^x = Y

But what does this mean in terms of algorithm performance? It's the number of comparisons you need to do, I understand that...the whole idea just seems so unintelligible though. Like, for QuickSort, each level K invocation involves 2^k invocations each involving sublists of length n/2^K.

So, summing to find the number of comparisons :

log n
Σ 2^k. 2(n/2^k) = 2n(1+logn)
k=0

Why are we summing up to log n ? Where did 2n(1+logn) come from? Sorry for the vagueness of my descriptions, I am just so confused.

like image 929
John Curtsy Avatar asked May 01 '11 09:05

John Curtsy


1 Answers

If you consider a full, balanced binary tree, then layer by layer you have 1 + 2 + 4 + 8 + ... vertices. If the total number of vertices in the tree is 2^n - 1 then you have 1 + 2 + 4 + 8 + ... + 2^(n-1) vertices, counting layer by layer. Now, let N = 2^n (the size of the tree), then the height of the tree is n, and n = log2(N) (the height of the tree). That's what the log(n) means in these Big O expressions.

like image 176
Rafe Avatar answered Oct 08 '22 10:10

Rafe