What is the expected space used by the skip list after inserting n elements?
I expect that in the worst case the space consumption may grow indefinitely.
Wikipedia says “Space O(n)”.
How can this be proven one way or another?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
According to this thesis, which I find more reliable then wikipedia, wikipedia is wrong. Probabilistic Skip List is
Theta(nlogn)worst case space complexity.The worst case is not infinite because you can limit yourself to
f(n)number of lists, wheref(n) = O(logn), and stop flipping coins when you reached this height. So, if you havef(n)complete rows, you getO(nlogn)total number of nodes, thus the space complexity in this case isO(nlogn), and notO(n).EDIT:
If you are looking for expected space consumption, and not worst as initially was stated in the question then:
Let’s denote “column” as a bottom node and all the nodes “up” from it.
The above equation is true because linearity of expected value.
E(#nodes_for_column_i) = 1 + 1/2 + ... + 1/n < 2(for each i). This is because with probability 1 it has 1 node, with p=1/2, each of these has an extra node. with p’=1/2, each of these has an extra node (total p*p’=1/4) ,…. Thus we can derive: