9/13/17 CMPS 2200 Intro. to Algorithms 1
CMPS 2200 – Fall 2017
Red-black trees
Carola Wenk
Slides courtesy of Charles Leiserson with changes by Carola Wenk
Red-black trees Carola Wenk Slides courtesy of Charles Leiserson - - PowerPoint PPT Presentation
CMPS 2200 Fall 2017 Red-black trees Carola Wenk Slides courtesy of Charles Leiserson with changes by Carola Wenk 9/13/17 1 CMPS 2200 Intro. to Algorithms Dynamic Set A dynamic set , or dictionary , is a data structure which supports
9/13/17 CMPS 2200 Intro. to Algorithms 1
Slides courtesy of Charles Leiserson with changes by Carola Wenk
9/13/17 CMPS 2200 Intro. to Algorithms 2
8 15 15 10 10 18 18 22 22 3 7 12 12 17 17
9/13/17 CMPS 2200 Intro. to Algorithms 3
8 15 15 10 10 18 18 22 22 3 7 12 12 17 17
9/13/17 CMPS 2200 Intro. to Algorithms 4
8 15 15 10 10 18 18 22 22 3 7 12 12 17 17 1 12 12
10 25 6 2 7 8 12 15 21 11 14 20 23 24 27 40 50 30 45 12 1 6 8 12 14 17 26 35 41 42 43 59 61 6 26 41 59 1 14 35 43 42 8 17
9/13/17 CMPS 2200 Intro. to Algorithms 5
9/13/17 CMPS 2200 Intro. to Algorithms 6
9/13/17 CMPS 2200 Intro. to Algorithms 7
null null null null null null null null null
9/13/17 CMPS 2200 Intro. to Algorithms 8
null null null null null null null null null
9/13/17 CMPS 2200 Intro. to Algorithms 9
null null null null null null null null null
9/13/17 CMPS 2200 Intro. to Algorithms 10
null null null null null null null null null
9/13/17 CMPS 2200 Intro. to Algorithms 11
9/13/17 CMPS 2200 Intro. to Algorithms 12
9/13/17 CMPS 2200 Intro. to Algorithms 13
9/13/17 CMPS 2200 Intro. to Algorithms 14
9/13/17 CMPS 2200 Intro. to Algorithms 15
9/13/17 CMPS 2200 Intro. to Algorithms 16
9/13/17 CMPS 2200 Intro. to Algorithms 17
9/13/17 CMPS 2200 Intro. to Algorithms 18
9/13/17 CMPS 2200 Intro. to Algorithms 19
9/13/17 CMPS 2200 Intro. to Algorithms 20
9/13/17 CMPS 2200 Intro. to Algorithms 21
39 39 41 41 42 42 9 31 31 6 20 20 2 8 16 16 22 22 15 15 17 17 11 11
RIGHT-ROTATE(20)
39 39 41 41 42 42 9 31 31 6 16 16 2 8 15 15 20 20 11 11 17 17 22 22
A B RIGHT-ROTATE(B) B A LEFT-ROTATE(A)
In-order(v){ if v==null return; In-order(v.left); print(v.key+” ”); In-order(v.right); }
In-order traversal: 2 6 8 9 11 15 16 17 20 22 31 39 41 42 In-order traversal: 2 6 8 9 11 15 16 17 20 22 31 39 41 42
9/13/17 CMPS 2200 Intro. to Algorithms 22
9/13/17 CMPS 2200 Intro. to Algorithms 23
9/13/17 CMPS 2200 Intro. to Algorithms 24
9/13/17 CMPS 2200 Intro. to Algorithms 25
9/13/17 CMPS 2200 Intro. to Algorithms 26
9/13/17 CMPS 2200 Intro. to Algorithms 27
9/13/17 CMPS 2200 Intro. to Algorithms 28
9/13/17 CMPS 2200 Intro. to Algorithms 29
9/13/17 CMPS 2200 Intro. to Algorithms 30
9/13/17 CMPS 2200 Intro. to Algorithms 31
9/13/17 CMPS 2200 Intro. to Algorithms 32
9/13/17 CMPS 2200 Intro. to Algorithms 33
9/13/17 CMPS 2200 Intro. to Algorithms 34
9/13/17 CMPS 2200 Intro. to Algorithms 35
9/13/17 CMPS 2200 Intro. to Algorithms 36
9/13/17 CMPS 2200 Intro. to Algorithms 37
9/13/17 CMPS 2200 Intro. to Algorithms 38
9/13/17 CMPS 2200 Intro. to Algorithms 39
9/13/17 CMPS 2200 Intro. to Algorithms 40
9/13/17 CMPS 2200 Intro. to Algorithms 41