Skip Lists with Quad Nodes - Data Stuctures - Lecture Slides, Slides of Data Structures and Algorithms

Skip List Implementation, Implementation TowerNode, Implementation QuadNode, Skip Lists with Quad Nodes, Performance of Skip Lists, Hashing, Finding the hash function are some of data structures topics and terms you will learn in these lecture slides.

Typology: Slides

2011/2012

Uploaded on 11/03/2012

ekna
ekna 🇮🇳

4.2

(5)

75 documents

1 / 17

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Skip List: Implementation
−∞ +∞
S0
S1
S2
S3
−∞ +∞
45 12 23 34
−∞ +∞
34
−∞ +∞
23 34
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Skip Lists with Quad Nodes - Data Stuctures - Lecture Slides and more Slides Data Structures and Algorithms in PDF only on Docsity!

Skip List: Implementation

−∞ +∞

S 0

S 1

S 2

S 3

−∞ 12 23 34 45 +∞

−∞ 34 +∞ −∞ 23 34 +∞

Implementation: TowerNode

 TowerNode will have array of next pointers.  Actual number of next pointers will be decided by the random procedure.  Define MAXLEVEL as an upper limit on number of levels in a node.

40 50 60

head (^) tail

20 26 30 57

Tower Node

Skip Lists with Quad Nodes

−∞ 12 23 26 31 34 44 56 64 78 +∞

−∞ +∞

−∞^31 +∞

−∞ 23 31 34 64 +∞

S 0

S 1

S 2

S 3

Performance of Skip Lists

 In a skip list with n items

  • The expected space used is proportional to n.
  • The expected search, insertion and deletion time is proportional to log n.  Skip lists are fast and simple to implement in practice

Anything better?

 So far we have find, remove and insert where time varies between constant log n.

 It would be nice to have all three as constant time operations!

 An array in which TableNodes are not stored consecutively  Their place of storage is calculated using the key and a hash function

 Keys and entries are scattered throughout the array.

Implementation 6: Hashing

key entry

Key (^) functionhash^ arrayindex

4

10

123

Hashing

 We use an array of some fixed size T to hold the data. T is typically prime.

 Each key is mapped into some number in the range 0 to T-1 using a hash function , which ideally should be efficient to compute.

Example: fruits

 Suppose our hash function gave us the following values: hashCode("apple") = 5 hashCode("watermelon") = 3 hashCode("grapes") = 8 hashCode("cantaloupe") = 7 hashCode("kiwi") = 0 hashCode("strawberry") = 9 hashCode("mango") = 6 hashCode("banana") = 2

kiwi

banana watermelon

apple mango cantaloupe grapes strawberry

0 1 2 3 4 5 6 7 8 9

Example

 Associative array:

table["apple"] table["watermelon"] table["grapes"] table["cantaloupe"] table["kiwi"] table["strawberry"] table["mango"] table["banana"]

kiwi

banana watermelon

apple mango cantaloupe grapes strawberry

0 1 2 3 4 5 6 7 8 9

Example Hash Functions

 If the keys are strings the hash function is some function of the characters in the strings.  One possibility is to simply add the ASCII values of the characters:

Example h ABC TableSize

h str str i TableSize

length

i : ( ) ( 65 66 67 )%

( ) [ ] %

1

0 = + +

 

  

=

Example Hash Functions

 Another possibility is to convert the string into some number in some arbitrary base b ( b also might be a prime number):

Example h ABC b b b T

h str str i b T

length

i

i

: ( ) ( 65 66 67 )%

( ) [ ] %

0 1 2

1

0 = + +

 

  

= ∑ ×

=

Example Hash Functions

 If the keys are integers then key%T is generally a good hash function, unless the data has some undesirable features.  For example, if T = 10 and all keys end in zeros, then key%T = 0 for all keys.  In general, to avoid situations like this, T should be a prime number.