Extension of data Results-skip table

Source: Internet
Author: User

Knowledge Source: An Introduction to Algorithms

Extension steps for Data structures: (in the real design, the order of the following steps can be replaced)

1. Select an underlying data structure 2. Identify additional information that needs to be maintained in the underlying data structure 3. Verify that the basic modification operation on the underlying data structure can maintain additional information 4. New operations required for design

If you want to insert a value of 3, first know where 3 should be inserted. Using two-point lookups allows you to locate the quickest, and the time complexity of this step is O (logn).

During the insertion process, all numbers greater than 3 in the original array are shifted to the right, and the time complexity is O (N). So the overall time complexity is O (N).

If you use a linked list, insert the new number in the following way:

If you want to insert 3, first know where 3 should be inserted. A linked list cannot use a binary lookup and can only determine the location by comparing the size of the nodes in the original list. The time complexity of this step is O (N).

The process of inserting is easy, changing the target of the node pointer directly, the time complexity O (1). So the overall time complexity is also O (N).

Both methods are obviously too slow for larger data operations.

——————————————

Skip Lists is an extension based on ordered linked list。 Insert

The new node and the index nodes of each layer are compared to determine the insertion position of the original linked list. O (LOGN)

Inserts the index into the original linked list. O (1)

The random way of tossing a coin determines whether the new node is promoted to the upper level index. The result is "positive" and then the coin is lifted and the result is "negative" stops. O (LOGN)

Overall, the time complexity of the jump table insert operation is O (Logn), and this data structure occupies a space of 2N, both the spatial complexity of O (N).

Delete

Top-down, find the index of the first occurrence of the node, and find the corresponding node at each level. O (LOGN)

Delete the node that each layer finds, and if the layer has only 1 nodes left, delete the entire layer (except the original linked list). O (LOGN)

Overall, the time complexity of the skip table delete operation is O (LOGN).

Extension of data Results-skip table

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.