What does Logn really mean?

I am just learning my class in Algorithms and browsing through QuickSort. I understand the algorithm and how it works, but not how to get the number of comparisons that it makes, or what logn really means at the end of the day.

I understand the basics, within:

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

But what does this mean in terms of algorithm performance? This is the number of comparisons you need to make, I understand that ... the whole idea seems so incomprehensible. For example, for QuickSort, each K-level call includes 2^kcalls, each of which includes a sublist of lengthn/2^K.

So, summing up to find the number of comparisons:

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

Why do we sum to log n? Where did 2n (1 + logn) come from? Sorry for the vagueness of my descriptions, I'm just so embarrassed.

+5
5

, , 1 + 2 + 4 + 8 +... . 2 ^ n - 1, 1 + 2 + 4 + 8 +... + 2 ^ (n-1) , . N = 2 ^ n ( ), n, n = log2 (N) ( ). , log (n) Big O.

+4

- :

      1
    /   \ 
   2     3
  / \   / \
 4   5 6   7

7, log 7 = 3, , , 2 , , , logn ( ), log n, O (n), N ( , N , N). , , log n , .

+1

1 b-

here 'math: log2 N = k 2 ^ k = N.. log , log (e) N = k aka e ^ k = n decimal log10 N = k 10 ^ k = n

2 . ,

1
1+ 1 1 + 1 + 1+ 1 8 16 ..

? 1 + 2 + 4 + 8..etc, b- 2 ^ 2-1 , 3- 2 ^ 3-1 .. SO SOERE MAGIC FORMULA: N_TREE_ELEMENTS = ^ 2 -1, log: log2 OF = number_of_tree_elements ( -1)

3 , N b-tree, w/K levels (aka height)

b- log2 height = number_of_tree

b- "" , N .. : log2 number_of_tree_elements..

log2 N_number_of_tree_elements.. log (N)

+1

, O (log (n)) , Big O notaion. , 1024 , 10 ( ) ( 2).

MergeSort O (n * log (n)), , 10 240 . Bubble sort O (n ^ 2), , 1024 ^ 2 = 1 048 576 . , :)


, mergesort :

         sort(3,1,2,4)
        /            \
   sort(3,1)      sort(2,4)
    /     \        /     \
sort(3) sort(1) sort(2) sort(4)

. k = 0, , k = log (n) - . log2 (n) ( > ).

:

Σ 2^k * 2(n/2^k) = 
2 * Σ 2^k * (n/2^k) =
2 * Σ n*2^k/2^k = 
2 * Σ n = 
2 * n * (1+log(n)) //As there are log(n)+1 steps from 0 to log(n) inclusive

, , , . -, . , , .

0

, , .

0

All Articles