Tree sort: time complexity

rapt

Why is the average case time complexity of tree sort O(n log n)?

From Wikipedia:

Adding one item to a binary search tree is on average an O(log n) process (in big O notation), so adding n items is an O(n log n) process

But we don't each time add an item to a tree of n items. We start with an empty tree, and gradually increase the size of the tree.

So it looks more like

log1 + log2 + ... + logn = log (1*2*...*n) = log n!

Am I missing something?

Chris Gong

The reason why O(log(n!)) = O(nlog(n)) is a two-part answer. First, expand O(log(n!)),

log(1) + log(2) + ... + log(n)

We can both agree here that log(1), log(2), and all the numbers up to log(n-1) are each less than log(n). Therefore, the following inequality can be made,

log(1) + log(2) + ... + log(n) <= log(n) + log(n) + ... + log(n)

Now the other half of the answer depends on the fact that half of the numbers from 1 to n are greater than n/2. This means that log(n!) would be greater than n/2*log(n/2) aka the first half of the sum log(n!),

log(1) + log(2) + ... + log(n) => log(n/2) + log(n/2) + ... + log(n/2)

The reason being that the first half of log(1) + log(2) + ... + log(n) is log(1) + log(2) + ... + log(n/2), which is less than n/2*log(n/2) as proven by the first inequality so by adding the second half of the sum log(n!), it can be shown that it is greater than n/2*log(n/2).

So with these two inequalities, it can be proven that O(log(n!)) = O(nlog(n))

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Time complexity of recursion-tree

From Dev

Time complexity of recursion-tree

From Dev

time complexity similar to bubble sort

From Dev

Merge sort space and time complexity

From Dev

Will Arrays.sort() increase time complexity and space time complexity?

From Java

Time complexity of testing if a binary tree is balanced

From Dev

Time complexity of checking if a binary tree is balanced

From Dev

Running time complexity for binary search tree

From Dev

Time complexity of deletion in binary search tree

From Dev

GATE 2008: Time Complexity of Binary Search Tree

From Dev

Space/Time complexity of Binary Tree Equality

From Dev

Time complexity of deletion in binary search tree

From Dev

Binary tree level order traversal time complexity

From Dev

time complexity of binary tree to DLL conversion

From Dev

Time complexity of RB Tree insertion inside a loop

From Dev

Time complexity in search of a list within a tree

From Dev

how to calculate Bubble sort Time Complexity

From Dev

Heap-sort time complexity deep understanding

From Dev

What is the time complexity of a modified quick sort algorithm?

From Dev

Recurrence for Merge Sort vs time complexity

From Dev

What is the time complexity of a modified quick sort algorithm?

From Dev

What is the Time complexity of this Algorithm using AVL tree and Binary tree

From Dev

What is time complexity of recursive level order traversal of a binary tree

From Dev

Time complexity for rebuilding binary search tree / quadtree / octtree?

From Dev

Time Complexity of the makeEmpty() of the Top-Down splay tree

From Dev

Time and space complexity of this function to print binary tree level by level

From Dev

What is the time complexity of recursion approach (Java) for "Maximum Depth of Binary Tree"?

From Dev

Max sum root to leaf binary tree time complexity

From Dev

Time complexity of construction of a binary tree from inorder and preorder traversals

Related Related

  1. 1

    Time complexity of recursion-tree

  2. 2

    Time complexity of recursion-tree

  3. 3

    time complexity similar to bubble sort

  4. 4

    Merge sort space and time complexity

  5. 5

    Will Arrays.sort() increase time complexity and space time complexity?

  6. 6

    Time complexity of testing if a binary tree is balanced

  7. 7

    Time complexity of checking if a binary tree is balanced

  8. 8

    Running time complexity for binary search tree

  9. 9

    Time complexity of deletion in binary search tree

  10. 10

    GATE 2008: Time Complexity of Binary Search Tree

  11. 11

    Space/Time complexity of Binary Tree Equality

  12. 12

    Time complexity of deletion in binary search tree

  13. 13

    Binary tree level order traversal time complexity

  14. 14

    time complexity of binary tree to DLL conversion

  15. 15

    Time complexity of RB Tree insertion inside a loop

  16. 16

    Time complexity in search of a list within a tree

  17. 17

    how to calculate Bubble sort Time Complexity

  18. 18

    Heap-sort time complexity deep understanding

  19. 19

    What is the time complexity of a modified quick sort algorithm?

  20. 20

    Recurrence for Merge Sort vs time complexity

  21. 21

    What is the time complexity of a modified quick sort algorithm?

  22. 22

    What is the Time complexity of this Algorithm using AVL tree and Binary tree

  23. 23

    What is time complexity of recursive level order traversal of a binary tree

  24. 24

    Time complexity for rebuilding binary search tree / quadtree / octtree?

  25. 25

    Time Complexity of the makeEmpty() of the Top-Down splay tree

  26. 26

    Time and space complexity of this function to print binary tree level by level

  27. 27

    What is the time complexity of recursion approach (Java) for "Maximum Depth of Binary Tree"?

  28. 28

    Max sum root to leaf binary tree time complexity

  29. 29

    Time complexity of construction of a binary tree from inorder and preorder traversals

HotTag

Archive