CS 350 : Data Structures Skip Lists

Similar documents
CS 350 : Data Structures B-Trees

CS350: Data Structures Red-Black Trees

CS350: Data Structures B-Trees

CS 350 : Data Structures Binary Search Trees

CS350: Data Structures Heaps and Priority Queues

CS 350 : Data Structures Hash Tables

CS350: Data Structures AVL Trees

Search Trees: BSTs and B-Trees

CS 261: Data Structures. Skip Lists

Treaps. 1 Binary Search Trees (BSTs) CSE341T/CSE549T 11/05/2014. Lecture 19

Sorted Arrays. Operation Access Search Selection Predecessor Successor Output (print) Insert Delete Extract-Min

Lecture 7. Random number generation More randomized data structures Skip lists: ideas and implementation Skip list time costs

CS100: CPADS. Decisions. David Babcock / Don Hake Department of Physical Sciences York College of Pennsylvania

Lecture 23: Binary Search Trees

CS102 Binary Search Trees

Binary Search Trees. Analysis of Algorithms

Module 4: Index Structures Lecture 13: Index structure. The Lecture Contains: Index structure. Binary search tree (BST) B-tree. B+-tree.

CS350: Data Structures AA Trees

Disk Accesses. CS 361, Lecture 25. B-Tree Properties. Outline

Chapter 12 Advanced Data Structures

CS350: Data Structures Binary Search Trees

Balanced Search Trees. CS 3110 Fall 2010

Data Structure. A way to store and organize data in order to support efficient insertions, queries, searches, updates, and deletions.

CS Transform-and-Conquer

1 Probability Review. CS 124 Section #8 Hashing, Skip Lists 3/20/17. Expectation (weighted average): the expectation of a random quantity X is:

CS 206 Introduction to Computer Science II

CS350: Data Structures Tree Traversal

Some Search Structures. Balanced Search Trees. Binary Search Trees. A Binary Search Tree. Review Binary Search Trees

Skip Lists: Motivation

CS 240 Fall Mike Lam, Professor. Priority Queues and Heaps

Solved by: Syed Zain Ali Bukhari (BSCS)

Red-black trees (19.5), B-trees (19.8), trees

CS350: Data Structures Linked Lists

We have used both of the last two claims in previous algorithms and therefore their proof is omitted.

Red-Black, Splay and Huffman Trees

Data Structures and Algorithms for Engineers

Orthogonal line segment intersection. Computational Geometry [csci 3250] Laura Toma Bowdoin College

Programming Abstractions

COSC 2011 Section N Data structure for efficient Thursday, April

Linked Structures Songs, Games, Movies Part III. Fall 2013 Carola Wenk

Skip Lists S 3 S 2 S 1. Skip Lists Goodrich, Tamassia

Heapsort. Why study Heapsort?

CS 331 DATA STRUCTURES & ALGORITHMS BINARY TREES, THE SEARCH TREE ADT BINARY SEARCH TREES, RED BLACK TREES, THE TREE TRAVERSALS, B TREES WEEK - 7

More Binary Search Trees AVL Trees. CS300 Data Structures (Fall 2013)

CS 106B Lecture 26: Esoteric Data Structures: Skip Lists and Bloom Filters

BRONX COMMUNITY COLLEGE of the City University of New York DEPARTMENT OF MATHEMATICS AND COMPUTER SCIENCE

CS 361, Lecture 21. Outline. Things you can do. Things I will do. Evaluation Results

Delhi Noida Bhopal Hyderabad Jaipur Lucknow Indore Pune Bhubaneswar Kolkata Patna Web: Ph:

Self-Balancing Search Trees. Chapter 11

Transform & Conquer. Presorting

Introduction to Linked List: Review. Source:

More BSTs & AVL Trees bstdelete

CSE 100 Tutor Review Section. Anish, Daniel, Galen, Raymond

CS-301 Data Structure. Tariq Hanif

Concurrent Skip Lists. Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit

Lecture 5. Treaps Find, insert, delete, split, and join in treaps Randomized search trees Randomized search tree time costs

Exercise 1 : B-Trees [ =17pts]

This is a set of practice questions for the final for CS16. The actual exam will consist of problems that are quite similar to those you have

AVL Trees. (AVL Trees) Data Structures and Programming Spring / 17

Range Queries. Kuba Karpierz, Bruno Vacherot. March 4, 2016

Binary search trees (chapters )

1 Binary Search Trees (BSTs)

University of Illinois at Urbana-Champaign Department of Computer Science. Second Examination

Garbage Collection: recycling unused memory

Line segment intersection (I): Orthogonal line segment intersection. Computational Geometry [csci 3250] Laura Toma Bowdoin College

CS350: Data Structures Dijkstra s Shortest Path Alg.

Problem Set 5 Solutions

Trees. Reading: Weiss, Chapter 4. Cpt S 223, Fall 2007 Copyright: Washington State University

CPSC 221: Programming Project 1

Lecture 7. Transform-and-Conquer

Data Structures and Algorithms

CS420: Operating Systems. Paging and Page Tables

ECE260: Fundamentals of Computer Engineering. Supporting Procedures in Computer Hardware

Unit III - Tree TREES

CSE332: Data Abstractions Lecture 7: B Trees. James Fogarty Winter 2012

12 July, Red-Black Trees. Red-Black Trees

CS350: Data Structures. Doubly Linked Lists

Balanced Binary Search Trees

Algorithms. AVL Tree

CS 2150 Final Exam, Spring 2018 Page 1 of 10 UVa userid:

An AVL tree with N nodes is an excellent data. The Big-Oh analysis shows that most operations finish within O(log N) time

Question Bank Subject: Advanced Data Structures Class: SE Computer

CSE 326: Data Structures Lecture #8 Binary Search Trees

Organizing Screens with Mission Control

Assignment 4 - AVL Binary Search Trees

CSI33 Data Structures

About this exam review

DATA STRUCTURES AND ALGORITHMS

COMP171. AVL-Trees (Part 1)

Data Structures in Java

Balanced Binary Search Trees

CS 261 Data Structures. AVL Trees

9.4.1 Search and Update Operations in a Skip List

CMPSCI 187: Programming With Data Structures. Lecture #26: Binary Search Trees David Mix Barrington 9 November 2012

Note that this is a rep invariant! The type system doesn t enforce this but you need it to be true. Should use repok to check in debug version.

COSC 2007 Data Structures II Final Exam. Part 1: multiple choice (1 mark each, total 30 marks, circle the correct answer)

CS350: Data Structures Stacks

Copyright 1998 by Addison-Wesley Publishing Company 147. Chapter 15. Stacks and Queues

CSE100. Advanced Data Structures. Lecture 8. (Based on Paul Kube course materials)

Avi Sharma # Remo Reuben #

Transcription:

CS 350 : Data Structures Skip Lists David Babcock (courtesy of James Moscola) Department of Physical Sciences York College of Pennsylvania James Moscola

Skip List Introduction A data structure used for storing a sorted list of elements using layers of linked lists - Bottom layer is a standard, ordered linked list - Upper layer linked lists create shortcuts or fast lanes from one location of the list to another Higher levels traverse greater portions of the list than lower levels 6 8 0 3 2

Skip List Introduction The example skip list below shows the skip list divided perfectly in halves, quarters, etc. 6 8 0 3 3

Skip List Introduction In practice, skip list node heights are distributed randomly throughout the skip list - Helps us avoid the need to rebalance the list when insertions or deletions occur 6 8 0 3 4

Skip Lists Operations on skip lists are comparable in efficiency to balanced binary search trees (e.g. AVL trees, Red-Black trees) - Insertion, Deletion, and Search operations all run in O(log N) time 5

Skip List Search 6

Skip List Searching To search for an element in a skip list: - Start at the highest level at the of the skip list and begin moving horizontally through the list If the next node in the list has the desired data then done If the data in the next node is less than the desired value, move to the next node and continue the search If the data in the next node is greater than the desired value, drop down one level and continue the search 7

Skip List Searching Example -- find the node with a key value 6 6 8 0 3 8

Skip List Searching Example -- find the node with a key value 6 () Start at highest level of the node and check data value at node.next (2) Compare node.next.data to the desired value, 5 < 6 so move to node 5 and continue the search 6 8 0 3 9

Skip List Searching Example -- find the node with a key value 6 (3) Compare node.next.data to the desired value, 0 > 6 so stay at node 5, drop down one level and continue the search 6 8 0 3 0

Skip List Searching Example -- find the node with a key value 6 (4) Compare node.next.data to the desired value, 8 > 6 so stay at node 5, drop down another level and continue the search 6 8 0 3

Skip List Searching Example -- find the node with a key value 6 (5) Compare node.next.data to the desired value, 6 == 6 so move to node 6, the desired node 6 8 0 3 2

Skip List Searching Example -- find the node with a key value 6 6 8 0 3 3

Skip List Searching Example -- find the node with a key value 7 - In this example, the desired element does not exist in the list - Search the list just as before, but when a value is found that exceed that desired value, AND there are no more levels to drop, then the desired element doesn t exist 6 8 0 3 4

Skip List Searching Example -- find the node with a key value 5 - Another example where the desired element does not exist in the list - Start with a normal search, if search reaches bottom-most level and next node is null, then element does not exist in list If not at bottom-most level and node.next ==, then drop a level and continue search 6 8 0 3 5

Skip List Insertion 6

Skip List Insertion When inserting a node into a skip list, first perform a search to determine where the new node must be inserted The height of a newly inserted node is chosen at random - Flip a coin, if s, then add an additional level to the newly inserted node, if tails then don t add anymore levels Probability of /2 that newly inserted node will only be at the bottom-most level Probability of /2 that newly inserted node will have one additional level Probability of /4 that newly inserted node will have two additional levels Probability of /8 that newly inserted node will have three additional levels etc. During the insert procedure, maintain an array that remembers the rightmost node that is to the left of the current location for each level 7

Skip List Insertion Example -- insert the node with a key value 7 Start with a search to determine where the node should be inserted 6 8 0 3 8

Skip List Insertion Example -- insert the node with a key value 7 () Start at highest level of the node and check data value at node.next (2) Compare node.next.data to the new value, 5 < 7 so move to node 5 and continue the search (3) Remember rightmost node at each level 6 8 0 3 9

Skip List Insertion Example -- insert the node with a key value 7 (4) Compare node.next.data to the new value, 0 > 7 so stay at node 5, drop down one level and continue the search 6 8 0 3 20

Skip List Insertion Example -- insert the node with a key value 7 (5) Compare node.next.data to the new value, 8 > 7 so stay at node 5, drop down one level and continue the search (6) Remember rightmost node at each level 6 8 0 3 2

Skip List Insertion Example -- insert the node with a key value 7 (7) Compare node.next.data to the new value, 6 < 7 so move to node 6 and continue the search (8) Remember rightmost node at each level 6 8 0 3 22

Skip List Insertion Example -- insert the node with a key value 7 (9) Compare node.next.data to the new value, 8 > 7 so new node must be inserted here between node 6 and node 8 6 8 0 3 23

Skip List Insertion Example -- insert the node with a key value 7 - To insert node 7: Randomly pick height for node 7 Markers were left behind to remember the rightmost node at each level to the left of the insertion location... use them to update next pointers 6 7 8 0 3 24

Skip List Deletion 25

Skip List Deletion For each level of which a skip list node is a part, splice the node out in the same fashion as a standard linked list Example -- delete the node with a key value 0 6 8 0 3 26

Skip List Deletion For each level of which a skip list node is a part, splice the node out in the same fashion as a standard linked list Example -- delete the node with a key value 0 First find the node to be deleted 6 8 0 3 27

Skip List Deletion For each level of which a skip list node is a part, splice the node out in the same fashion as a standard linked list Example -- delete the node with a key value 0 Then splice the node out 6 8 0 3 28

Skip List Deletion For each level of which a skip list node is a part, splice the node out in the same fashion as a standard linked list Example -- delete the node with a key value 0 6 8 3 29