Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
352 views
in Technique[技术] by (71.8m points)

recursion - Can you prove that average cost of n insertions to BST/AVL/Splay tree can't be lower than nlog(n)?

I'm curious if you guys know an answer to this question that came to my mind.

We know that an average cost of BST insertion is O(log n) and worst case as well as average for AVL/Splay is O(log n).

Since we are inserting n times (basically we are building a tree) we will recieve the final cost being n*logn.

How can we prove that we can't get lower than that? It's easy to observe but kind of hard to prove.

Maybe we can use recursive equations and somehow limit them?

Thanks in advance.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

As a hint, you can do an inorder traversal of any binary search tree in time O(n) to retrieve the elements of that BST in sorted order.

The algorithms for inserting into a red/black tree, AVL tree, splay tree, etc. are all comparison-based and work by comparing the newly-inserted element to a sequence of other elements in the tree. What would happen if you were able to do this in time o(n log n) (using little-o notation)?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...