Inge Li Gørtz. Thank you to Kevin Wayne for inspiration to slides
|
|
- Hilary Heath
- 5 years ago
- Views:
Transcription
1 02110 Inge Li Gørtz Thank you to Kevin Wayne for inspiration to slides
2 Welcome Inge Li Gørtz. Reverse teaching and discussion of exercises: 3 teaching assistants Group work Discussions of your solutions in class Lecture Work on exercises in the new material Round up Weekly assignments (You have to get 40 points + pass 2 implementation exercises in order to be able to attend the written exam). Prerequisites: 02105/02326 lgorithms and Data Structures I 2
3 Balanced Search Trees trees red-black trees References: LRS hapter 13, lgorithms in Java (handout)
4 Balanced search trees Dynamic sets Search Insert Delete Maximum Minimum Successor(x) (find minimum element x) Predecessor(x) (find maximum element x) This lecture: trees, red-black trees Next time: Splay trees 4
5 Dynamic set implementations Worst case running times Implementation search insert delete minimum maximum successor predecessor linked lists O(n) O(1) O(1) O(n) O(n) O(n) O(n) ordered array O(log n) O(n) O(n) O(1) O(1) O(log n) O(log n) BST O(h) O(h) O(h) O(h) O(h) O(h) O(h) In worst case h=n. In best case h= log n (fully balanced binary tree) Today: How to keep the trees balanced. 5
6 2-3-4 trees
7 2-3-4 trees trees. llow nodes to have multiple keys. Perfect balance. Every path from root to leaf has same length. llow 1, 2, or 3 keys per node 2-node: one key, 2 children 3-node: 2 keys, 3 children 4-node: 3 keys, 4 children K R smaller than K larger than R B D F between K and R M O X E G J L N Q S V Y Z 7
8 Searching in a tree Search. ompare search key against keys in node. Find interval containing search key Follow associated link (recursively) Ex. Search for L K R between K and R E M O X smaller than M D F G J L N Q S V Y Z found L 8
9 Insertion in a tree Insert. Search to bottom for key. smaller than K K R Ex. Insert B smaller than E M O X D F G J L N Q S V Y Z B not found 10
10 Insertion in a tree Insert. Search to bottom for key. 2-node at bottom: convert to 3-node smaller than K K R Ex. Insert B smaller than E M O X B D F G J L N Q S V Y Z B fits here 11
11 Insertion in a tree Insert. Search to bottom for key. 2-node at bottom: convert to 3-node K R larger than R Ex. Insert X E M O U larger than U D F G J L N Q S T Y Z X not found12
12 Insertion in a tree Insert. Search to bottom for key. 2-node at bottom: convert to 3-node 3-node at bottom: convert to 4-node K R Ex. Insert X larger than R E M O U larger than W D F G J L N Q S T X Y Z X fits here 13
13 Insertion in a tree Insert. Search to bottom for key. 2-node at bottom: convert to 3-node 3-node at bottom: convert to 4-node K R smaller than K Ex. Insert H E M O X larger than E D F G J L N Q S V Y Z H not found 14
14 Insertion in a tree Insert. Search to bottom for key. 2-node at bottom: convert to 3-node 3-node at bottom: convert to 4-node 4-node at bottom:?? smaller than K K R Ex. Insert H E M O X larger than E D F G J L N Q S V Y Z H does not fit here! 15
15 Splitting a 4-node in a tree Idea: split the 4-node to make room E G E B D F J B D F G J H does fit here! H does not fit here E G Problem: Doesn t work if parent is a 4-node Solution 1: Split the parent (and continue splitting B D F H J while necessary). Solution 2: Split 4-nodes on the way down. 16
16 Splitting 4-nodes in a tree Idea: split 4-nodes on the way down the tree. Ensures last node is not a 4-node. Transformations to split 4-nodes: B F G J B G F J x y z v x y z v B D B D G F G J F J Invariant. urrent node is not a 4-node. onsequence. Insertion at bottom is easy since it's not a 4-node. root B D G x y z v B x y D G z v x y z v x y z v 17
17 Insertion in a tree Insert. Search to bottom for key. 2-node at bottom: convert to 3-node 3-node at bottom: convert to 4-node 4-node at bottom:?? not a 4-node K R Ex. Insert H not a 4-node E M O X 4-node D F G J L N Q S V Y Z 18
18 Insertion in a tree Insert. Search to bottom for key. 2-node at bottom: convert to 3-node 3-node at bottom: convert to 4-node 4-node at bottom:?? K R Ex. Insert H E G M O X D F J L N Q S V Y Z 19
19 Insertion in a tree Insert. Search to bottom for key. 2-node at bottom: convert to 3-node 3-node at bottom: convert to 4-node 4-node at bottom:?? K R Ex. Insert H E G M O X D F H J L N Q S V Y Z 20
20 Splitting 4-nodes in a tree Local transformations that work anywhere in the tree. Ex. Splitting a 4-node attached to a 2-node D D Q - K Q W - K W E-J L-P R-V X-Z E-J L-P R-V X-Z could be huge unchanged 21
21 Splitting 4-nodes in a tree Local transformations that work anywhere in the tree Ex. Splitting a 4-node attached to a 3-node D H D H Q - E-G K Q W K W - E-G I-J L-P R-V X-Z I-J L-P R-V X-Z could be huge unchanged 22
22 Splitting 4-nodes in a tree Local transformations that work anywhere in the tree. Splitting a 4-node attached to a 4-node never happens when we split nodes on the way down the tree. Invariant. urrent node is not a 4-node. 23
23 Insertion trees E R Insert U E R Insert G E I R B H I N S B H I N S U B H N S U Insert U Insert G Split Insert G Insert T I I E I R Split E R E R B G H N S U B G H N S U B G H N S T U Insert T 24
24 Deletions in trees Delete minimum: minimum always in leftmost leaf If 3- or 4-node: delete key K R Ex. Delete minimum E M O X is minimum B D F G J L N Q S V Y Z 25
25 Deletions in trees Delete minimum: minimum always in leftmost leaf If 3- or 4-node: delete key K R Ex. Delete minimum E M O X Delete B D F G J L N Q S V Y Z 26
26 Deletions in trees Delete minimum: minimum always in leftmost leaf If 3- or 4-node: delete key 2-node?? K R Ex. Delete minimum E M O X Delete B? B D F G J L N Q S V Y Z 27
27 Deletions in trees Idea: On the way down maintain the invariant that current node is not a 2-node. hild of root and root is a 2-node: B x B y z w or B D E B D E x y on the way down: B F G z w F G x y z w r s x y z w r s or D E B D E x y z w r s x y z w r s B D E D E B x y z w x y z w 28
28 Deletions in trees Delete minimum: minimum always in leftmost leaf If 3- or 4-node: delete key 2-node: split/merge on way down. K R Ex. Delete minimum not a 2-node E M O X 2-node B D F G J L N Q S V Y Z 29
29 Deletions in trees Delete minimum: minimum always in leftmost leaf If 3- or 4-node: delete key 2-node: split/merge on way down. K R Ex. Delete minimum E M O X B D F G J L N Q S V Y Z 30
30 Deletions in trees Delete minimum: minimum always in leftmost leaf If 3- or 4-node: delete key 2-node: split/merge on way down. K R Ex. Delete minimum E M O X D F G J L N Q S V Y Z 31
31 Deletions in trees Delete: During search maintain invariant that current node is not a 2-node If key is in a leaf: delete key Key not in leaf: replace with successor (always leaf in subtree) and delete successor from leaf. Ex. Delete K Find successor K R E M O X B D F G J L N Q S V Y Z 38
32 Deletions in trees Delete: During search maintain invariant that current node is not a 2-node If key is in a leaf: delete key Key not in leaf: replace with successor (always leaf in subtree) and delete successor from leaf. Ex. Delete K K R Find successor not a 2-node E M O X B D F G J L N Q S V Y Z 39
33 Deletions in trees Delete: During search maintain invariant that current node is not a 2-node If key is in a leaf: delete key Key not in leaf: replace with successor (always leaf in subtree) and delete successor from leaf. Ex. Delete K K R Find successor not a 2-node E M O X 2-node B D F G J L N Q S V Y Z 40
34 Deletions in trees Delete: During search maintain invariant that current node is not a 2-node If key is in a leaf: delete key Key not in leaf: replace with successor (always leaf in subtree) and delete successor from leaf. Ex. Delete K Find successor K R E O X B D F G J L M N Q S V Y Z 41
35 Deletions in trees Delete: During search maintain invariant that current node is not a 2-node If key is in a leaf: delete key Key not in leaf: replace with successor (always leaf in subtree) and delete successor from leaf. Ex. Delete K Find successor K R Delete L from leaf E O X B D F G J L M N Q S V Y Z 42
36 Deletions in trees Delete: During search maintain invariant that current node is not a 2-node If key is in a leaf: delete key Key not in leaf: replace with successor (always leaf in subtree) and delete successor from leaf. Ex. Delete K Find successor K R Delete L from leaf E O X B D F G J M N Q S V Y Z 43
37 Deletions in trees Delete: During search maintain invariant that current node is not a 2-node If key is in a leaf: delete key Key not in leaf: replace with successor (always leaf in subtree) and delete successor from leaf. Ex. Delete K Find successor K R Delete L from leaf Replace K with L E O X B D F G J M N Q S V Y Z 44
38 Deletions in trees Delete: During search maintain invariant that current node is not a 2-node If key is in a leaf: delete key Key not in leaf: replace with successor (always leaf in subtree) and delete successor from leaf. Ex. Delete K Find successor L R Delete L from leaf E O X Replace K with L B D F G J M N Q S V Y Z 45
39 2-3-4 Tree: Balance Property. ll paths from root to leaf have same length. Tree height. Worst case: lg N [all 2-nodes] Best case: log 4 N = 1/2 lg N [all 4-nodes] Between 10 and 20 for a million nodes. Between 15 and 30 for a billion nodes. 46
40 Dynamic set implementations Worst case running times Implementation search insert delete minimum maximum successor predecessor linked lists O(n) O(1) O(1) O(n) O(n) O(n) O(n) ordered array O(log n) O(n) O(n) O(1) O(1) O(log n) O(log n) BST O(h) O(h) O(h) O(h) O(h) O(h) O(h) tree O(log n) O(log n) O(log n) O(log n) O(log n) O(log n) O(log n) 47
41 Red-black trees
42 Red-black tree (Guibas-Sedgewick, 1979) Represent tree as a binary search tree Use colors on nodes to represent 3- and 4-nodes. G K O G K O H L H L or H L B B 49
43 Red-black tree (Guibas-Sedgewick, 1979) Represent tree as a binary search tree Use colors on nodes to represent 3- and 4-nodes. or onnection between trees and red-black trees: E R E R H I N S I S H N 50
44 Red-black tree (Guibas-Sedgewick, 1979) Represent tree as a binary search tree Use colors on nodes to represent 3- and 4-nodes. or onnection between trees and red-black trees: E R E R H I N S I S H N 51
45 Red-black tree Properties of red-black trees: The root is always black ll root-to-leaf paths have the same number of black nodes. Red nodes do not have red children LRS: ll leaves (NIL) are black 52
46 Red-black tree onnection between trees and red-black trees: E R H I N S 53
47 Red-black tree onnection between trees and red-black trees: E R H I N S E R I S H N 54
48 Red-black tree onnection between trees and red-black trees: E R H I N S E R or E R S I S I H N H N 55
49 Insertion in red-black trees Insertion in 2-node: F F F F Insert Insertion in 3-node: F F F F H Insert H H 56
50 Red-black tree: Splitting 4-nodes Two easy cases: B D I M B D I M B D I M B I D M B D E I M B D E I M B D E I M B D I E M 57
51 Insertion in red-black trees Insertion in 3-node (continued): F F F F H Insert H H F?? Insert H F F H F?? Insert E F F E 58
52 Red-black trees: Splitting of 4-nodes Example of hard case: B L D H K B D L H K B D H K?? Solution: Rotations!
53 Rotations in red-black trees Two types of rotations B a B b a b c d c d a b B c d a b B c d 60
54 Rotations in red-black trees Two types of rotations: 61 B a b c d B b c d a B a b c d B a b c d B b c d a B a b c d B a b c d B a b c d
55 Insertion in red-black trees Insertion in 3-node: F Insert H F F H F H?? F?? Insert E F F E 62
56 Insertion in red-black trees Insertion in 3-node: F F F H Insert H F F H H F?? Insert E F F E 63
57 Insertion in red-black trees Insertion in 3-node: F F F H Insert H F F H H F E Insert E F F F E E F E F 64
58 Insert x: Search to bottom after key (x) Insert red leaf Balance: 3 cases (+ symmetric) Insertion in red-black tree 65 a a b Keep balancing with z b d z c d b d b c z a c b d z d a b c z z a b a z c c d a b c z d d
59 Eksempel E E B R B R I S I S H N H N U Insert U Insert V E E B R B R H I N S U V Rotate U H I N S U V 66
60 67 Example S E R H N B I U V Insert G S E R H N B I U V G S E R H N B I U V G E R H N B I S U V G I B R N S U V H G E Rotate I Rotate I
61 Running times in red-black trees Time for insertion: Search to bottom after key: O(h) Insert red leaf: O(1) Perform recoloring and rotations on way up: O(h) Total O(h). an recolor many times (but at most h) t most 2 rotations. Time for search Same as BST: O(h) Height: O(log n) 68
62 Dynamic set implementations Worst case running times Implementation search insert delete minimum maximum successor predecessor linked lists O(n) O(1) O(1) O(n) O(n) O(n) O(n) ordered array O(log n) O(n) O(n) O(1) O(1) O(log n) O(log n) BST O(h) O(h) O(h) O(h) O(h) O(h) O(h) tree O(log n) O(log n) O(log n) O(log n) O(log n) O(log n) O(log n) red-black tree O(log n) O(log n) O(log n) O(log n) O(log n) O(log n) O(log n) 69
63 Balanced trees: implementations Redblack trees: Java: java.util.treemap, java.util.treeset. ++ STL: map, multimap, multiset. Linux kernel: linux/rbtree.h. 70
64 Exercise time Start working on the exercises on weekplan BST talk about solutions to the first 2-3 exercises + info about the mandatory exercises. 71
65 Mandatory exercise To be handed in before 8PM the following Sunday on DTU Learn. This week: Binary tries from weekplan warmup. 72
66 Grading of mandatory assignments You can get up to 20 points for an exercise: 5 points for the example (draw tree/run algorithm etc) 15 points for design an algorithm exercise: 4 points for the description of your algorithm 4 points for the quality of your algorithm 4 points for the complexity analysis 3 points for the correctness arguments 73
Advanced Data Structures
Simon Gog gog@kit.edu - Simon Gog: KIT The Research University in the Helmholtz Association www.kit.edu Predecessor data structures We want to support the following operations on a set of integers from
More informationWelcome. Balanced search trees. Balanced Search Trees. Inge Li Gørtz
Welome nge Li Gørt. everse tehing n isussion of exerises: 02110 nge Li Gørt 3 tehing ssistnts 8.00-9.15 Group work 9.15-9.45 isussions of your solutions in lss 10.00-11.15 Leture 11.15-11.45 Work on exerises
More informationAdvanced Data Structures
Simon Gog gog@kit.edu - Simon Gog: KIT University of the State of Baden-Wuerttemberg and National Research Center of the Helmholtz Association www.kit.edu Predecessor data structures We want to support
More informationFundamental Algorithms
Fundamental Algorithms Chapter 5: Searching Michael Bader Winter 2014/15 Chapter 5: Searching, Winter 2014/15 1 Searching Definition (Search Problem) Input: a sequence or set A of n elements (objects)
More informationCS 151. Red Black Trees & Structural Induction. Thursday, November 1, 12
CS 151 Red Black Trees & Structural Induction 1 Announcements Majors fair tonight 4:30-6:30pm in the Root Room in Carnegie. Come and find out about the CS major, or some other major. Winter Term in CS
More informationFixed-Universe Successor : Van Emde Boas. Lecture 18
Fixed-Universe Successor : Van Emde Boas Lecture 18 Fixed-universe successor problem Goal: Maintain a dynamic subset S of size n of the universe U = {0, 1,, u 1} of size u subject to these operations:
More informationAVL Trees. Properties Insertion. October 17, 2017 Cinda Heeren / Geoffrey Tien 1
AVL Trees Properties Insertion October 17, 2017 Cinda Heeren / Geoffrey Tien 1 BST rotation g g e h b h b f i a e i a c c f d d Rotations preserve the in-order BST property, while altering the tree structure
More informationAssignment 5: Solutions
Comp 21: Algorithms and Data Structures Assignment : Solutions 1. Heaps. (a) First we remove the minimum key 1 (which we know is located at the root of the heap). We then replace it by the key in the position
More informationpast balancing schemes require maintenance of balance info at all times, are aggresive use work of searches to pay for work of rebalancing
1 Splay Trees Sleator and Tarjan, Self Adjusting Binary Search Trees JACM 32(3) 1985 The claim planning ahead. But matches previous idea of being lazy, letting potential build up, using it to pay for expensive
More informationSearch Trees. Chapter 10. CSE 2011 Prof. J. Elder Last Updated: :52 AM
Search Trees Chapter 1 < 6 2 > 1 4 = 8 9-1 - Outline Ø Binary Search Trees Ø AVL Trees Ø Splay Trees - 2 - Outline Ø Binary Search Trees Ø AVL Trees Ø Splay Trees - 3 - Binary Search Trees Ø A binary search
More informationBinary Search Trees. Motivation
Binary Search Trees Motivation Searching for a particular record in an unordered list takes O(n), too slow for large lists (databases) If the list is ordered, can use an array implementation and use binary
More informationEach internal node v with d(v) children stores d 1 keys. k i 1 < key in i-th sub-tree k i, where we use k 0 = and k d =.
7.5 (a, b)-trees 7.5 (a, b)-trees Definition For b a an (a, b)-tree is a search tree with the following properties. all leaves have the same distance to the root. every internal non-root vertex v has at
More informationRecitation 7. Treaps and Combining BSTs. 7.1 Announcements. FingerLab is due Friday afternoon. It s worth 125 points.
Recitation 7 Treaps and Combining BSTs 7. Announcements FingerLab is due Friday afternoon. It s worth 25 points. RangeLab will be released on Friday. 39 40 RECITATION 7. TREAPS AND COMBINING BSTS 7.2 Deletion
More informationENS Lyon Camp. Day 2. Basic group. Cartesian Tree. 26 October
ENS Lyon Camp. Day 2. Basic group. Cartesian Tree. 26 October Contents 1 Cartesian Tree. Definition. 1 2 Cartesian Tree. Construction 1 3 Cartesian Tree. Operations. 2 3.1 Split............................................
More informationOutline for Today. Static Optimality. Splay Trees. Properties of Splay Trees. Dynamic Optimality (ITA) Balanced BSTs aren't necessarily optimal!
Splay Trees Outline for Today Static Optimality alanced STs aren't necessarily optimal! Splay Trees self-adjusting binary search tree. Properties of Splay Trees Why is splaying worthwhile? ynamic Optimality
More information4.8 Huffman Codes. These lecture slides are supplied by Mathijs de Weerd
4.8 Huffman Codes These lecture slides are supplied by Mathijs de Weerd Data Compression Q. Given a text that uses 32 symbols (26 different letters, space, and some punctuation characters), how can we
More informationData Structures and Algorithms " Search Trees!!
Data Structures and Algorithms " Search Trees!! Outline" Binary Search Trees! AVL Trees! (2,4) Trees! 2 Binary Search Trees! "! < 6 2 > 1 4 = 8 9 Ordered Dictionaries" Keys are assumed to come from a total
More informationSearch Trees. EECS 2011 Prof. J. Elder Last Updated: 24 March 2015
Search Trees < 6 2 > 1 4 = 8 9-1 - Outline Ø Binary Search Trees Ø AVL Trees Ø Splay Trees - 2 - Learning Outcomes Ø From this lecture, you should be able to: q Define the properties of a binary search
More informationThe null-pointers in a binary search tree are replaced by pointers to special null-vertices, that do not carry any object-data
Definition 1 A red black tree is a balanced binary search tree in which each internal node has two children. Each internal node has a color, such that 1. The root is black. 2. All leaf nodes are black.
More information8: Splay Trees. Move-to-Front Heuristic. Splaying. Splay(12) CSE326 Spring April 16, Search for Pebbles: Move found item to front of list
: Splay Trees SE Spring 00 pril, 00 Move-to-Front Heuristic Search for ebbles: Fred Wilma ebbles ino Fred Wilma ino ebbles Move found item to front of list Frequently searched items will move to start
More informationINF2220: algorithms and data structures Series 1
Universitetet i Oslo Institutt for Informatikk I. Yu, D. Karabeg INF2220: algorithms and data structures Series 1 Topic Function growth & estimation of running time, trees (Exercises with hints for solution)
More informationBinary Search Trees. Lecture 29 Section Robb T. Koether. Hampden-Sydney College. Fri, Apr 8, 2016
Binary Search Trees Lecture 29 Section 19.2 Robb T. Koether Hampden-Sydney College Fri, Apr 8, 2016 Robb T. Koether (Hampden-Sydney College) Binary Search Trees Fri, Apr 8, 2016 1 / 40 1 Binary Search
More informationCS Data Structures and Algorithm Analysis
CS 483 - Data Structures and Algorithm Analysis Lecture VII: Chapter 6, part 2 R. Paul Wiegand George Mason University, Department of Computer Science March 22, 2006 Outline 1 Balanced Trees 2 Heaps &
More informationCS 240 Data Structures and Data Management. Module 4: Dictionaries
CS 24 Data Structures and Data Management Module 4: Dictionaries A. Biniaz A. Jamshidpey É. Schost Based on lecture notes by many previous cs24 instructors David R. Cheriton School of Computer Science,
More informationChapter 5 Arrays and Strings 5.1 Arrays as abstract data types 5.2 Contiguous representations of arrays 5.3 Sparse arrays 5.4 Representations of
Chapter 5 Arrays and Strings 5.1 Arrays as abstract data types 5.2 Contiguous representations of arrays 5.3 Sparse arrays 5.4 Representations of strings 5.5 String searching algorithms 0 5.1 Arrays as
More informationPriority queues implemented via heaps
Priority queues implemented via heaps Comp Sci 1575 Data s Outline 1 2 3 Outline 1 2 3 Priority queue: most important first Recall: queue is FIFO A normal queue data structure will not implement a priority
More informationChapter 5 Data Structures Algorithm Theory WS 2017/18 Fabian Kuhn
Chapter 5 Data Structures Algorithm Theory WS 2017/18 Fabian Kuhn Priority Queue / Heap Stores (key,data) pairs (like dictionary) But, different set of operations: Initialize-Heap: creates new empty heap
More informationDecision Trees. Lewis Fishgold. (Material in these slides adapted from Ray Mooney's slides on Decision Trees)
Decision Trees Lewis Fishgold (Material in these slides adapted from Ray Mooney's slides on Decision Trees) Classification using Decision Trees Nodes test features, there is one branch for each value of
More information16. Binary Search Trees. [Ottman/Widmayer, Kap. 5.1, Cormen et al, Kap ]
418 16. Binary Search Trees [Ottman/Widmayer, Kap. 5.1, Cormen et al, Kap. 12.1-12.3] 419 Dictionary implementation Hashing: implementation of dictionaries with expected very fast access times. Disadvantages
More information16. Binary Search Trees. [Ottman/Widmayer, Kap. 5.1, Cormen et al, Kap ]
423 16. Binary Search Trees [Ottman/Widmayer, Kap. 5.1, Cormen et al, Kap. 12.1-12.3] Dictionary implementation 424 Hashing: implementation of dictionaries with expected very fast access times. Disadvantages
More informationBinary Search Trees. Dictionary Operations: Additional operations: find(key) insert(key, value) erase(key)
Binary Search Trees Dictionary Operations: find(key) insert(key, value) erase(key) Additional operations: ascend() get(index) (indexed binary search tree) delete(index) (indexed binary search tree) Complexity
More informationSplay Trees. CMSC 420: Lecture 8
Splay Trees CMSC 420: Lecture 8 AVL Trees Nice Features: - Worst case O(log n) performance guarantee - Fairly simple to implement Problem though: - Have to maintain etra balance factor storage at each
More informationCS1800: Mathematical Induction. Professor Kevin Gold
CS1800: Mathematical Induction Professor Kevin Gold Induction: Used to Prove Patterns Just Keep Going For an algorithm, we may want to prove that it just keeps working, no matter how big the input size
More informationNotes on induction proofs and recursive definitions
Notes on induction proofs and recursive definitions James Aspnes December 13, 2010 1 Simple induction Most of the proof techniques we ve talked about so far are only really useful for proving a property
More informationCS 4349 Lecture August 30th, 2017
CS 4349 Lecture August 30th, 2017 Main topics for #lecture include #recurrances. Prelude I will hold an extra office hour Friday, September 1st from 3:00pm to 4:00pm. Please fill out prerequisite forms
More informationDictionary: an abstract data type
2-3 Trees 1 Dictionary: an abstract data type A container that maps keys to values Dictionary operations Insert Search Delete Several possible implementations Balanced search trees Hash tables 2 2-3 trees
More informationProblem: Data base too big to fit memory Disk reads are slow. Example: 1,000,000 records on disk Binary search might take 20 disk reads
B Trees Problem: Data base too big to fit memory Disk reads are slow Example: 1,000,000 records on disk Binary search might take 20 disk reads Disk reads are done in blocks Example: One block read can
More informationProblem. Problem Given a dictionary and a word. Which page (if any) contains the given word? 3 / 26
Binary Search Introduction Problem Problem Given a dictionary and a word. Which page (if any) contains the given word? 3 / 26 Strategy 1: Random Search Randomly select a page until the page containing
More informationFibonacci Heaps These lecture slides are adapted from CLRS, Chapter 20.
Fibonacci Heaps These lecture slides are adapted from CLRS, Chapter 20. Princeton University COS 4 Theory of Algorithms Spring 2002 Kevin Wayne Priority Queues Operation mae-heap insert find- delete- union
More informationLecture 6 September 21, 2016
ICS 643: Advanced Parallel Algorithms Fall 2016 Lecture 6 September 21, 2016 Prof. Nodari Sitchinava Scribe: Tiffany Eulalio 1 Overview In the last lecture, we wrote a non-recursive summation program and
More informationToday s Outline. CS 362, Lecture 4. Annihilator Method. Lookup Table. Annihilators for recurrences with non-homogeneous terms Transformations
Today s Outline CS 362, Lecture 4 Jared Saia University of New Mexico Annihilators for recurrences with non-homogeneous terms Transformations 1 Annihilator Method Lookup Table Write down the annihilator
More informationAVL Trees. Manolis Koubarakis. Data Structures and Programming Techniques
AVL Trees Manolis Koubarakis 1 AVL Trees We will now introduce AVL trees that have the property that they are kept almost balanced but not completely balanced. In this way we have O(log n) search time
More informationDefinition A transition system S is a pair of the form. where C is the set of configurations and T C C is a relation, the
Transition system Definition 1.3.1 transition system S is a pair of the form = S T) (, where is the set of configurations and T is a relation, the transition relation. lgorithms and Data Structures hapter
More informationDivide-and-Conquer Algorithms Part Two
Divide-and-Conquer Algorithms Part Two Recap from Last Time Divide-and-Conquer Algorithms A divide-and-conquer algorithm is one that works as follows: (Divide) Split the input apart into multiple smaller
More information6.854 Advanced Algorithms
6.854 Advanced Algorithms Homework Solutions Hashing Bashing. Solution:. O(log U ) for the first level and for each of the O(n) second level functions, giving a total of O(n log U ) 2. Suppose we are using
More informationFunctional Data Structures
Functional Data Structures with Isabelle/HOL Tobias Nipkow Fakultät für Informatik Technische Universität München 2017-2-3 1 Part II Functional Data Structures 2 Chapter 1 Binary Trees 3 1 Binary Trees
More informationOrdered Dictionary & Binary Search Tree
Ordered Dictionary & Binary Search Tree Finite map from keys to values, assuming keys are comparable (). insert(k, v) lookup(k) aka find: the associated value if any delete(k) (Ordered set: No values;
More informationData Structures and and Algorithm Xiaoqing Zheng
Data Structures and Algorithm Xiaoqing Zheng zhengxq@fudan.edu.cn Trees (max heap) 1 16 2 3 14 10 4 5 6 7 8 7 9 3 8 9 10 2 4 1 PARENT(i) return i /2 LEFT(i) return 2i RIGHT(i) return 2i +1 16 14 10 8 7
More informationOutline for Today. Static Optimality. Splay Trees. Properties of Splay Trees. Dynamic Optimality (ITA) Balanced BSTs aren't necessarily optimal!
Splay Trees Outline for Today Static Optimality Balanced BSTs aren't necessarily optimal! Splay Trees A self-adjusting binary search tree. Properties of Splay Trees Why is splaying worthwhile? Dynamic
More informationAlgorithm Design and Analysis
Algorithm Design and Analysis LECTURE 9 Divide and Conquer Merge sort Counting Inversions Binary Search Exponentiation Solving Recurrences Recursion Tree Method Master Theorem Sofya Raskhodnikova S. Raskhodnikova;
More informationAnalysis of Algorithms. Outline 1 Introduction Basic Definitions Ordered Trees. Fibonacci Heaps. Andres Mendez-Vazquez. October 29, Notes.
Analysis of Algorithms Fibonacci Heaps Andres Mendez-Vazquez October 29, 2015 1 / 119 Outline 1 Introduction Basic Definitions Ordered Trees 2 Binomial Trees Example 3 Fibonacci Heap Operations Fibonacci
More informationDisjoint-Set Forests
Disjoint-Set Forests Thanks for Showing Up! Outline for Today Incremental Connectivity Maintaining connectivity as edges are added to a graph. Disjoint-Set Forests A simple data structure for incremental
More informationLecture 4: Divide and Conquer: van Emde Boas Trees
Lecture 4: Divide and Conquer: van Emde Boas Trees Series of Improved Data Structures Insert, Successor Delete Space This lecture is based on personal communication with Michael Bender, 001. Goal We want
More informationAlgorithms. Quicksort. Slide credit: David Luebke (Virginia)
1 Algorithms Quicksort Slide credit: David Luebke (Virginia) Sorting revisited We have seen algorithms for sorting: INSERTION-SORT, MERGESORT More generally: given a sequence of items Each item has a characteristic
More informationAmortized Complexity Main Idea
omp2711 S1 2006 Amortized Complexity Example 1 Amortized Complexity Main Idea Worst case analysis of run time complexity is often too pessimistic. Average case analysis may be difficult because (i) it
More informationAlgorithms and Data Structures 2016 Week 5 solutions (Tues 9th - Fri 12th February)
Algorithms and Data Structures 016 Week 5 solutions (Tues 9th - Fri 1th February) 1. Draw the decision tree (under the assumption of all-distinct inputs) Quicksort for n = 3. answer: (of course you should
More informationSelection and Adversary Arguments. COMP 215 Lecture 19
Selection and Adversary Arguments COMP 215 Lecture 19 Selection Problems We want to find the k'th largest entry in an unsorted array. Could be the largest, smallest, median, etc. Ideas for an n lg n algorithm?
More informationOutline. Computer Science 331. Cost of Binary Search Tree Operations. Bounds on Height: Worst- and Average-Case
Outline Computer Science Average Case Analysis: Binary Search Trees Mike Jacobson Department of Computer Science University of Calgary Lecture #7 Motivation and Objective Definition 4 Mike Jacobson (University
More informationDictionary: an abstract data type
2-3 Trees 1 Dictionary: an abstract data type A container that maps keys to values Dictionary operations Insert Search Delete Several possible implementations Balanced search trees Hash tables 2 2-3 trees
More informationPremaster Course Algorithms 1 Chapter 3: Elementary Data Structures
Premaster Course Algorithms 1 Chapter 3: Elementary Data Structures Christian Scheideler SS 2018 23.04.2018 Chapter 3 1 Overview Basic data structures Search structures (successor searching) Dictionaries
More informationAsymptotic Analysis. Slides by Carl Kingsford. Jan. 27, AD Chapter 2
Asymptotic Analysis Slides by Carl Kingsford Jan. 27, 2014 AD Chapter 2 Independent Set Definition (Independent Set). Given a graph G = (V, E) an independent set is a set S V if no two nodes in S are joined
More informationCS173 Lecture B, November 3, 2015
CS173 Lecture B, November 3, 2015 Tandy Warnow November 3, 2015 CS 173, Lecture B November 3, 2015 Tandy Warnow Announcements Examlet 7 is a take-home exam, and is due November 10, 11:05 AM, in class.
More informationAdvanced Implementations of Tables: Balanced Search Trees and Hashing
Advanced Implementations of Tables: Balanced Search Trees and Hashing Balanced Search Trees Binary search tree operations such as insert, delete, retrieve, etc. depend on the length of the path to the
More informationLecture 1: Asymptotics, Recurrences, Elementary Sorting
Lecture 1: Asymptotics, Recurrences, Elementary Sorting Instructor: Outline 1 Introduction to Asymptotic Analysis Rate of growth of functions Comparing and bounding functions: O, Θ, Ω Specifying running
More informationV. Adamchik 1. Recurrences. Victor Adamchik Fall of 2005
V. Adamchi Recurrences Victor Adamchi Fall of 00 Plan Multiple roots. More on multiple roots. Inhomogeneous equations 3. Divide-and-conquer recurrences In the previous lecture we have showed that if the
More informationData selection. Lower complexity bound for sorting
Data selection. Lower complexity bound for sorting Lecturer: Georgy Gimel farb COMPSCI 220 Algorithms and Data Structures 1 / 12 1 Data selection: Quickselect 2 Lower complexity bound for sorting 3 The
More informationCS 4407 Algorithms Lecture 2: Iterative and Divide and Conquer Algorithms
CS 4407 Algorithms Lecture 2: Iterative and Divide and Conquer Algorithms Prof. Gregory Provan Department of Computer Science University College Cork 1 Lecture Outline CS 4407, Algorithms Growth Functions
More informationPartition and Select
Divide-Conquer-Glue Algorithms Quicksort, Quickselect and the Master Theorem Quickselect algorithm Tyler Moore CSE 3353, SMU, Dallas, TX Lecture 11 Selection Problem: find the kth smallest number of an
More informationChapter 10 Search Structures
Chapter 1 Search Structures 1 1.2 AVL Trees : 동기 Objective : maintain binary search tree structure for O(log n) access time with dynamic changes of identifiers (i.e., elements) in the tree. JULY APR AUG
More informationLecture 2 September 4, 2014
CS 224: Advanced Algorithms Fall 2014 Prof. Jelani Nelson Lecture 2 September 4, 2014 Scribe: David Liu 1 Overview In the last lecture we introduced the word RAM model and covered veb trees to solve the
More informationDesign and Analysis of Algorithms
Design and Analysis of Algorithms 6.046J/18.401J LECTURE 7 Skip Lists Data structure Randomized insertion With high probability (w.h.p.) bound 7/10/15 Copyright 2001-8 by Leiserson et al L9.1 Skip lists
More informationComputational Models Lecture 8 1
Computational Models Lecture 8 1 Handout Mode Nachum Dershowitz & Yishay Mansour. Tel Aviv University. May 17 22, 2017 1 Based on frames by Benny Chor, Tel Aviv University, modifying frames by Maurice
More information5 Spatial Access Methods
5 Spatial Access Methods 5.1 Quadtree 5.2 R-tree 5.3 K-d tree 5.4 BSP tree 3 27 A 17 5 G E 4 7 13 28 B 26 11 J 29 18 K 5.5 Grid file 9 31 8 17 24 28 5.6 Summary D C 21 22 F 15 23 H Spatial Databases and
More information1. [10 marks] Consider the following two algorithms that find the two largest elements in an array A[1..n], where n >= 2.
CSC 6 H5S Homework Assignment # 1 Spring 010 Worth: 11% Due: Monday February 1 (at class) For each question, please write up detailed answers carefully. Make sure that you use notation and terminology
More informationData Structures and Algorithms Winter Semester
Page 0 German University in Cairo December 26, 2015 Media Engineering and Technology Faculty Prof. Dr. Slim Abdennadher Dr. Wael Abouelsadaat Data Structures and Algorithms Winter Semester 2015-2016 Final
More informationAlgorithms. Algorithms 2.2 MERGESORT. mergesort bottom-up mergesort sorting complexity divide-and-conquer ROBERT SEDGEWICK KEVIN WAYNE
Algorithms ROBERT SEDGEWICK KEVIN WAYNE 2.2 MERGESORT Algorithms F O U R T H E D I T I O N mergesort bottom-up mergesort sorting complexity divide-and-conquer ROBERT SEDGEWICK KEVIN WAYNE http://algs4.cs.princeton.edu
More informationComputational Models Lecture 8 1
Computational Models Lecture 8 1 Handout Mode Ronitt Rubinfeld and Iftach Haitner. Tel Aviv University. May 11/13, 2015 1 Based on frames by Benny Chor, Tel Aviv University, modifying frames by Maurice
More informationN/4 + N/2 + N = 2N 2.
CS61B Summer 2006 Instructor: Erin Korber Lecture 24, 7 Aug. 1 Amortized Analysis For some of the data structures we ve discussed (namely hash tables and splay trees), it was claimed that the average time
More informationCSE 421 Algorithms. Richard Anderson Autumn 2015 Lecture 1
CSE 421 Algorithms Richard Anderson Autumn 2015 Lecture 1 CSE 421 Course Introduction CSE 421, Introduction to Algorithms MWF, 1:30-2:20 pm MGH 421 Instructor Richard Anderson, anderson@cs.washington.edu
More informationMultidimensional Divide and Conquer 1 Skylines
Yufei Tao ITEE University of Queensland The next few lectures will be dedicated to an important technique: divide and conquer. You may have encountered the technique in an earlier algorithm course, but
More informationsearching algorithms
searching algorithms learning objectives algorithms your software system software hardware learn what the searching problem is about learn two algorithms for solving this problem learn the importance of
More informationCSE332: Data Structures & Parallelism Lecture 2: Algorithm Analysis. Ruth Anderson Winter 2018
CSE332: Data Structures & Parallelism Lecture 2: Algorithm Analysis Ruth Anderson Winter 2018 Today Algorithm Analysis What do we care about? How to compare two algorithms Analyzing Code Asymptotic Analysis
More information8 Priority Queues. 8 Priority Queues. Prim s Minimum Spanning Tree Algorithm. Dijkstra s Shortest Path Algorithm
8 Priority Queues 8 Priority Queues A Priority Queue S is a dynamic set data structure that supports the following operations: S. build(x 1,..., x n ): Creates a data-structure that contains just the elements
More informationThe Tree Evaluation Problem: Towards Separating P from NL. Lecture #6: 26 February 2014
The Tree Evaluation Problem: Towards Separating P from NL Lecture #6: 26 February 2014 Lecturer: Stephen A. Cook Scribe Notes by: Venkatesh Medabalimi 1. Introduction Consider the sequence of complexity
More informationCSE332: Data Structures & Parallelism Lecture 2: Algorithm Analysis. Ruth Anderson Winter 2018
CSE332: Data Structures & Parallelism Lecture 2: Algorithm Analysis Ruth Anderson Winter 2018 Today Algorithm Analysis What do we care about? How to compare two algorithms Analyzing Code Asymptotic Analysis
More informationThe Complexity of Constructing Evolutionary Trees Using Experiments
The Complexity of Constructing Evolutionary Trees Using Experiments Gerth Stlting Brodal 1,, Rolf Fagerberg 1,, Christian N. S. Pedersen 1,, and Anna Östlin2, 1 BRICS, Department of Computer Science, University
More informationDivide and Conquer Algorithms. CSE 101: Design and Analysis of Algorithms Lecture 14
Divide and Conquer Algorithms CSE 101: Design and Analysis of Algorithms Lecture 14 CSE 101: Design and analysis of algorithms Divide and conquer algorithms Reading: Sections 2.3 and 2.4 Homework 6 will
More informationCSE332: Data Structures & Parallelism Lecture 2: Algorithm Analysis. Ruth Anderson Winter 2019
CSE332: Data Structures & Parallelism Lecture 2: Algorithm Analysis Ruth Anderson Winter 2019 Today Algorithm Analysis What do we care about? How to compare two algorithms Analyzing Code Asymptotic Analysis
More informationSorting Algorithms. We have already seen: Selection-sort Insertion-sort Heap-sort. We will see: Bubble-sort Merge-sort Quick-sort
Sorting Algorithms We have already seen: Selection-sort Insertion-sort Heap-sort We will see: Bubble-sort Merge-sort Quick-sort We will show that: O(n log n) is optimal for comparison based sorting. Bubble-Sort
More informationAdvanced Algorithms (2IL45)
Technische Universiteit Eindhoven University of Technology Course Notes Fall 2013 Advanced Algorithms (2IL45) Mark de Berg Contents 1 Introduction to randomized algorithms 4 1.1 Some probability-theory
More informationAn analogy from Calculus: limits
COMP 250 Fall 2018 35 - big O Nov. 30, 2018 We have seen several algorithms in the course, and we have loosely characterized their runtimes in terms of the size n of the input. We say that the algorithm
More information1 Probability Review. CS 124 Section #8 Hashing, Skip Lists 3/20/17. Expectation (weighted average): the expectation of a random quantity X is:
CS 24 Section #8 Hashing, Skip Lists 3/20/7 Probability Review Expectation (weighted average): the expectation of a random quantity X is: x= x P (X = x) For each value x that X can take on, we look at
More informationAMORTIZED ANALYSIS. binary counter multipop stack dynamic table. Lecture slides by Kevin Wayne. Last updated on 1/24/17 11:31 AM
AMORTIZED ANALYSIS binary counter multipop stack dynamic table Lecture slides by Kevin Wayne http://www.cs.princeton.edu/~wayne/kleinberg-tardos Last updated on 1/24/17 11:31 AM Amortized analysis Worst-case
More informationCSE 151 Machine Learning. Instructor: Kamalika Chaudhuri
CSE 151 Machine Learning Instructor: Kamalika Chaudhuri Announcements Midterm is graded! Average: 39, stdev: 6 HW2 is out today HW2 is due Thursday, May 3, by 5pm in my mailbox Decision Tree Classifiers
More informationOptimal Color Range Reporting in One Dimension
Optimal Color Range Reporting in One Dimension Yakov Nekrich 1 and Jeffrey Scott Vitter 1 The University of Kansas. yakov.nekrich@googlemail.com, jsv@ku.edu Abstract. Color (or categorical) range reporting
More informationLecture 8 HASHING!!!!!
Lecture 8 HASHING!!!!! Announcements HW3 due Friday! HW4 posted Friday! Q: Where can I see examples of proofs? Lecture Notes CLRS HW Solutions Office hours: lines are long L Solutions: We will be (more)
More informationCMPUT 675: Approximation Algorithms Fall 2014
CMPUT 675: Approximation Algorithms Fall 204 Lecture 25 (Nov 3 & 5): Group Steiner Tree Lecturer: Zachary Friggstad Scribe: Zachary Friggstad 25. Group Steiner Tree In this problem, we are given a graph
More informationLecture 1: September 25, A quick reminder about random variables and convexity
Information and Coding Theory Autumn 207 Lecturer: Madhur Tulsiani Lecture : September 25, 207 Administrivia This course will cover some basic concepts in information and coding theory, and their applications
More informationCSCE 750 Final Exam Answer Key Wednesday December 7, 2005
CSCE 750 Final Exam Answer Key Wednesday December 7, 2005 Do all problems. Put your answers on blank paper or in a test booklet. There are 00 points total in the exam. You have 80 minutes. Please note
More informationNon-context-Free Languages. CS215, Lecture 5 c
Non-context-Free Languages CS215, Lecture 5 c 2007 1 The Pumping Lemma Theorem. (Pumping Lemma) Let be context-free. There exists a positive integer divided into five pieces, Proof for for each, and..
More information