Binary Search Trees. Adnan Aziz. Heaps can perform extract-max, insert efficiently O(log n) worst case

Size: px
Start display at page:

Download "Binary Search Trees. Adnan Aziz. Heaps can perform extract-max, insert efficiently O(log n) worst case"

Transcription

1 Binary Searc Trees Adnan Aziz 1 BST basics Based on CLRS, C 12. Motivation: Heaps can perform extract-max, insert efficiently O(log n) worst case Has tables can perform insert, delete, lookup efficiently O(1) (on average) Wat about doing searcing in a eap? Min in a eap? Max in a as table? Binary Searc Trees support searc, insert, delete, max, min, successor, predecessor time complexity is proportional to eigt of tree recall tat a complete binary tree on n nodes as eigt O(log n) Basics: A BST is organized as a binary tree added caveat: keys are stored at nodes, in a way so as to satisfy te BST property: for any node x in a BST, if y is a node in x s left subtree, ten key[y] key[x], and if y is a node in x s rigt subtree, ten key[y] key[x]. Implementation represent a node by an object wit 4 data members: key, pointer to left cild, pointer to rigt cild, pointer to parent (use NIL pointer to denote empty) 1

2 Figure 1: BST examples Figure 2: BST working example for queries and updates 2

3 1.1 Query operations Print keys in sorted order Te BST property allows us to print out all te keys in a BST in sorted order: INORDER-TREE-WALK(x) if x!= NIL ten INORDER-TREE-WALK(left[x]) print key[x] INORDER-TREE-WALK(rigt[x]) Searc for a key TREE-SEARCH(x,k) if x = NIL or k = key[x] ten return x if k < key[x] ten return TREE-SEARCH(left[x],k) else return TREE-SEARCH(rigt[x],k) Try searc 13, 11 in example Min, Max TREE-MINIMUM(x) wile (left[x]!= NIL) do x <- left[x] return x Symmetric procedure to find max. Try min=2, max=20 3

4 1.2 Successor and Predecessor Given a node x in a BST, sometimes want to find its successor node wose key appears immediately after x s key in an in-order walk Conceptually: if te rigt cild of x is not NIL, get min of rigt cild, oterwise examine parent Tricky wen x is left cild of parent, need to keep going up te searc tree TREE-SUCCESSOR(x) if rigt[x]!= NIL ten return TREE-MINIMUM( rigt[x] ) y <- p[x] wile y!= NIL and x = rigt[y] do x <- y y <- p[y] Symmetric procedure to find pred. Try succ 15, 6, 13, 20; pred 15, 6, 7, 2 Teorem: all operations above take time O() were is te eigt of te tree. 1.3 Updates Inserts Insert: Given a node z wit key v, left[z],rigt[z],p[z] all NIL, and a BST T update T and z so tat updated tree includes te node z wit BST property still true Idea beind algoritm: begin at root, trace pat downward comparing v wit key at current node. get to te bottom insert node z by setting its parent to last node on pat, update parent left/rigt cild appropriately Refer to TREE-INSERT(T,z) in CLRS for detailed pseudo-code. Try insert keys 12, 1, 7, 16, 25 in te example 4

5 1.3.2 Deletions Given a node z (assumed to be a node in a BST T ), delete it from T. Tricky, need to consider 3 cases: 1. z as no cildren modify p[z] to replace te z-cild of p[z] by NIL 2. z as one cild splice z out of te tree 3. z as two cildren splice z s successor (call it y) out of te tree, and replace z s contents wit tose of y. Crucial fact: y cannot ave a left cild Refer to TREE-DELETE(T,z) in CLRS for detailed pseudo-code. Try deleting 9, 7, 6 from example Teorem: Insertion and deletion can be performed in O() time, were is te eigt of te tree. note ow we crucially made use of te BST property 2 Balanced binary searc trees Fact: if we build a BST using n inserts (assuming insert is implemented as above), and te keys appear in a random sequence, ten te eigt is very likely to be O(log n) (proved in CLRS 12.4). random sequence of keys: extremely unrealistic assumption Result olds only wen tere are no deletes if tere are deletes, te eigt will tend to O( n). Tis is because of te asymmetry in deletion te predecessor is always used to replace te node. Te asymmetry can be removed by alternating between te successor and predecessor. Question 1. Given a BST on n nodes, can you always find a BST on te same n keys aving eigt O(log n)? 5

6 Yes, just tink of a (near) complete binary tree Question 2. Can you implement insertion and deletion so tat te eigt of te tree is always O(log n)? Yes, but tis is not so obvious performing tese operations in O(log n) time is a lot tricker. Broadly speaking, two options to keeping BST balanced Make te insert sequence look random (treaps) Store some extra information at te nodes, related to te relative balance of te cildren modify insert and delete to ceck for and correct skewedness several classes of balanced BSTs, e.g., AVL, Red-Black, 2-3, etc. 2.1 Treaps Randomly builts BSTs tend to be balanced given set S randomly permute elements, ten insert in tat order. (CLRS 12.4) In general, all elements in S are not available at start Solution: assign a random number called te priority for eac key (assume keys are distinct). In addition to satisfying BST property (v left/rigt cild of u key(v) < / > key(u)), require tat if v is cild of u, ten priority(v) > priority(u). Treaps will ave te following property: If we insert x 1,..., x n into a treap, ten te resulting tree is te one tat would ave resulted if keys ad been inserted in te order of teir priorities Treap insertion is very fast only a constant number of pointer updates. It is used in LEDA, a widely used advanced data structure library for C Deterministic balanced trees Many alternatives: AVL, Red-Black, 2-3, B-trees, weigt balance trees, etc. most commonly used are AVL and Red-Black trees. 6

7 G:4 B:7 H:5 C:25 G:4 B:7 H:5 A:10 E:23 K:65 A:10 E:23 K:65 I:73 C:25 I:73 D:9 G:4 G:4 B:7 H:5 B:7 H:5 A:10 E:23 K:65 A:10 E:23 K:65 C:25 I:73 D:9 I:73 D:9 C:25 G:4 F:2 F:2 B:7 H:5.. B:7 G:4 A:10 D:9 H:5 A:10 D:9 K:65 C:25 E:23 I:73 C:25 E:23 K:65 I:73 Figure 3: Treap 7 insertion

8 x left rotate(x) y a y rigt rotate(x) x c b c a b Figure 4: Rotations 2.3 AVL Trees Keep tree eigt balanced for eac node eigts of left and rigt subtrees differ by at most 1. Implement by keeping an extra field [x] (eigt) for eac node. Heigt of AVL tree on n nodes is O(lg n). Follows from te following recurrence: If M is te minimum number of nodes in an AVL tree of eigt, M = 1 + M 1 + M 2. Te minimum number of nodes in an AVL tree of eigt 0 or 1 is 1. Te recurrence F = F 1 + F 2 wit F 0 = F 1 = 1 is known yields wat are known as te Fibonnaci numbers. Tese numbers ave been studied in great detail; in particular, F = φ (1 φ) 5, were φ = (1 + 5)/2. Clearly, te Fibonnaci numbers grow exponentially. Since M > F, tis guarantees tat M grows exponentially wit. Ordinary insertion can trow off balance by at most 1, and only along te searc pat. moving up from added leaf, find first place along searc pat were tree is not balanced re-balance te tree using rotations (Figure 4) Upsot: insertion takes O(lg n) time, and te number of rotations is O(1). Proof: based on figures Deletions, as usual, are more complicated. Rebalancing cannot in general be acieved wit a single rotation tere are cases were Θ(lg n) rotations are required. AVL trees are very efficient in practice te worst cases require 45% more compares tan optimal trees. Empirical studies sow tat tey require lg n compares on average. 8

9 A A B C B C T3 T4 T3 T4 T1 T2 T1 T2 new new Figure 5: AVL: Two possible insertions tat invalidate balances. Tere are two symmetric cases on te rigt side. A is te first node on te searc pat from te new node to te root were te eigt property fails. A B B C A C T1 T2 T3 T4 T1 1 1 new new T2 T3 T4 Figure 6: AVL: single rotation to rectify invalidation 9

10 A D B C B A E D E F G C F G 1 T4 T2 1 T3 T1 T2 T3 T1 new T4 new Figure 7: AVL: double rotation to rectify invalidation 2.4 Red-black trees CLRS Capter 13 RB-tree is a BST wit an additional bit of storage per node its color, wic can be red or black. Needs to satisfy te following properties: P1 Every node is colored red or black P2 Te root is black P3 Every leaf (NIL) is black P4 If a node is red, bot its cildren are black P5 For every node, all pats to descendant leaves ave te same number of black nodes Define te black eigt of node x, b(x), to be te number of black nodes, not including x, on any pat from x to leaf (note tat P5 guarantees tat te black eigt is well defined). Lemma 1 A red-black tree wit n internal nodes as eigt at most lg n. 10

11 Figure 8: RB tree: Tick circles represent black nodes; we re ignoring te NIL leaves. Proof: Subtree rooted at any node x as at least 2 b(x) 1 internal nodes tis follows directly by induction. Ten note tat P4 guarantees at least alf te nodes on any pat from root to leaf are black (including root). So te black eigt is at least /2, ence n 2 /2 1; result follows from moving te 1 to left side, and taking logs. From te above it follows tat te insert and delete operations take O(lg n) time. However, tey may leave result in violations of some of te properties P1 P5. Properties are restored by canging colors, and updating pointers troug rotations. Conceptually rotation is simple, but code looks a mess see page 278, CLRS. Example of update sequence for insertion in Figure Splay trees Based on Tarjan, Data Structures and Network Algoritms, 1983, Capter 4, Section 3. Key idea adjust BST after eac searc, insert, and delete operation. (Tarjan actually allows a couple more operations, specifically, joining two trees, and splitting a tree at a node, but we ll stick to te searc/insert/delete ops.) Key result altoug a single operation may be expensive (Θ(n), were n is te number of keys in te tree), a sequence of m total operations, of wic n are inserts will complete in O(m lg n). Basic operation: splaying. 11

12 z z and p[z] red, z s uncle red > recolor 11 2 z z & p[z] red, z s uncle black, z rigt cild of p[z] > left rotate 11 z z & p[z] red, z left cild of p[z] > rigt rotate, recolor 7 z Figure 9: Insert in RB-tree

13 As part of searc/insert/update, perform splaying on eac node on pat from x to root. Definition of splaying at a node x: if x as a parent, but no grandparent, rotate at p(x) if x as a grandparent (wic implies it as a parent), and bot x and p(x) are left cildren or bot are rigt cildren, ten rotate at p(p(x)) ten at p(x) if x as a grandparent and x is a left cild, and p(x) is a rigt cild or vice versa, roate at p(x) and ten te new p(x) (wic will be te old grandparent of x) Searc/update node x splay at x Delete x splay its parent just prior to deletion 3 Augmenting data structures CLRS Capter 14 Typical engineering situation: rarely te case tat cut-and-paste from textbook suffices. sometimes need a wole new data structure most often, augment existing data structure wit some auxiliary information Two examples dynamic order statistics, and interval trees 3.1 Dynamic order statistics In addition to usual BST operations (insert, delete, lookup, succ, pred, min, max), would like to ave a rank operation: rank of element is its position in te linear order of te set One approac to return fast rank information balanced BST wit additional size field size[x] = number of nodes in subtree rooted at x, including x itself size[x] = size[left[x]] + size[rigt[x]] + 1, were size[nil] = 0 Two kinds of queries: 13

14 Retrieve element wit given rank Determine rank of element Let s see ow to compute rank information using size field; later will sow ow size can be updated troug inserts and deletes. // Return element wit rank i in tree rooted at node x OS_SELECT(x,i) r <- size[left[x]] + 1 if ( i = r ) ten return x; elseif ( i < r ) ten return OS_SELECT(left[x], i) else return OS_SELECT(rigt[x], i-r) Idea: case analysis // Return rank of element at node x in tree T OS_RANK(T,x) r <- size[left[x]] + 1 y <- x wile ( y!= root[t] ) do if ( y = rigt[p[y]] ) return r ten r <- r + size[left[p[y]]] + 1 y <- p[y] Idea: at start of eac iteration of wile loop, r is rank of key[x] in subtree rooted at node y Bot rank algoritms are O() (= O(lg n) for balanced BST). How to preserve size field troug inserts and deletes? 14

15 Insert before rotations: simply increment size field for eac node on searc pat rotations: only two nodes ave field canges upsot: insert remains O() Deletion: similar argument 3.2 Interval trees Augment BSTs to support operations on intervals. A closed interval [t 1, t 2 ] is an ordered pair of real numbers t 1 t 2 ; it represents te set {t R t 1 t t 2 }. (Can also define open and alf-open intervals, but no real difference). Useful for representing events wic occupy a continuous period of time. Natural query: wat events appened in a given time? Nice solution via BSTs. Represent interval [t 1, t 2 ] as an object i, wit fields low[i] = t 1 and ig[i] = t 2. Fact: intervals satisfy tricotomy if i, i are intervals, ten eiter tey overlap, or one is to te left of te oter Interval tree BST wit eac node containing an interval. given node x wit interval int[x], BST key is low[int[x]] store additional information: max[x], maximum value of any endpoint stored in subtree rooted at x must update information troug inserts and deletes can be done efficiently: max[x] = max(ig[int[x]], max[left[x]], max[rigt[x]]) New operation: interval searc 15

16 // find node in T wose interval overlaps wit interval i INTERVAL_SEARCH( T, i ) x <- root[t] wile ( x!= nil[t] ) && ( i does not overlap int[x] ) do if ( left[x]!= nil[t] && ( max[left[x]] >= low[i] ) return x ten x <- left[x] else x <- rigt[x] Wy does tis work? If tree T contains an interval tat overlaps i, ten tere is suc an interval in te subtree rooted at T 16

M(0) = 1 M(1) = 2 M(h) = M(h 1) + M(h 2) + 1 (h > 1)

M(0) = 1 M(1) = 2 M(h) = M(h 1) + M(h 2) + 1 (h > 1) Insertion and Deletion in VL Trees Submitted in Partial Fulfillment of te Requirements for Dr. Eric Kaltofen s 66621: nalysis of lgoritms by Robert McCloskey December 14, 1984 1 ackground ccording to Knut

More information

schema binary search tree schema binary search trees data structures and algorithms 2015 09 21 lecture 7 AVL-trees material

schema binary search tree schema binary search trees data structures and algorithms 2015 09 21 lecture 7 AVL-trees material scema binary searc trees data structures and algoritms 05 0 lecture 7 VL-trees material scema binary searc tree binary tree: linked data structure wit nodes containing binary searc trees VL-trees material

More information

Introduction to Data Structures and Algorithms

Introduction to Data Structures and Algorithms Introduction to Data Structures and Algorithms Chapter: Binary Search Trees Lehrstuhl Informatik 7 (Prof. Dr.-Ing. Reinhard German) Martensstraße 3, 91058 Erlangen Search Trees Search trees can be used

More information

Binary Search Trees. Each child can be identied as either a left or right. parent. right. A binary tree can be implemented where each node

Binary Search Trees. Each child can be identied as either a left or right. parent. right. A binary tree can be implemented where each node Binary Search Trees \I think that I shall never see a poem as lovely as a tree Poem's are wrote by fools like me but only G-d can make atree \ {Joyce Kilmer Binary search trees provide a data structure

More information

Algorithms Chapter 12 Binary Search Trees

Algorithms Chapter 12 Binary Search Trees Algorithms Chapter 1 Binary Search Trees Outline Assistant Professor: Ching Chi Lin 林 清 池 助 理 教 授 [email protected] Department of Computer Science and Engineering National Taiwan Ocean University

More information

SAT Subject Math Level 1 Facts & Formulas

SAT Subject Math Level 1 Facts & Formulas Numbers, Sequences, Factors Integers:..., -3, -2, -1, 0, 1, 2, 3,... Reals: integers plus fractions, decimals, and irrationals ( 2, 3, π, etc.) Order Of Operations: Aritmetic Sequences: PEMDAS (Parenteses

More information

Binary Search Trees. A Generic Tree. Binary Trees. Nodes in a binary search tree ( B-S-T) are of the form. P parent. Key. Satellite data L R

Binary Search Trees. A Generic Tree. Binary Trees. Nodes in a binary search tree ( B-S-T) are of the form. P parent. Key. Satellite data L R Binary Search Trees A Generic Tree Nodes in a binary search tree ( B-S-T) are of the form P parent Key A Satellite data L R B C D E F G H I J The B-S-T has a root node which is the only node whose parent

More information

Derivatives Math 120 Calculus I D Joyce, Fall 2013

Derivatives Math 120 Calculus I D Joyce, Fall 2013 Derivatives Mat 20 Calculus I D Joyce, Fall 203 Since we ave a good understanding of its, we can develop derivatives very quickly. Recall tat we defined te derivative f x of a function f at x to be te

More information

Outline BST Operations Worst case Average case Balancing AVL Red-black B-trees. Binary Search Trees. Lecturer: Georgy Gimel farb

Outline BST Operations Worst case Average case Balancing AVL Red-black B-trees. Binary Search Trees. Lecturer: Georgy Gimel farb Binary Search Trees Lecturer: Georgy Gimel farb COMPSCI 220 Algorithms and Data Structures 1 / 27 1 Properties of Binary Search Trees 2 Basic BST operations The worst-case time complexity of BST operations

More information

- 1 - Handout #22 May 23, 2012 Huffman Encoding and Data Compression. CS106B Spring 2012. Handout by Julie Zelenski with minor edits by Keith Schwarz

- 1 - Handout #22 May 23, 2012 Huffman Encoding and Data Compression. CS106B Spring 2012. Handout by Julie Zelenski with minor edits by Keith Schwarz CS106B Spring 01 Handout # May 3, 01 Huffman Encoding and Data Compression Handout by Julie Zelenski wit minor edits by Keit Scwarz In te early 1980s, personal computers ad ard disks tat were no larger

More information

ACT Math Facts & Formulas

ACT Math Facts & Formulas Numbers, Sequences, Factors Integers:..., -3, -2, -1, 0, 1, 2, 3,... Rationals: fractions, tat is, anyting expressable as a ratio of integers Reals: integers plus rationals plus special numbers suc as

More information

1.6. Analyse Optimum Volume and Surface Area. Maximum Volume for a Given Surface Area. Example 1. Solution

1.6. Analyse Optimum Volume and Surface Area. Maximum Volume for a Given Surface Area. Example 1. Solution 1.6 Analyse Optimum Volume and Surface Area Estimation and oter informal metods of optimizing measures suc as surface area and volume often lead to reasonable solutions suc as te design of te tent in tis

More information

Instantaneous Rate of Change:

Instantaneous Rate of Change: Instantaneous Rate of Cange: Last section we discovered tat te average rate of cange in F(x) can also be interpreted as te slope of a scant line. Te average rate of cange involves te cange in F(x) over

More information

Analysis of Algorithms I: Binary Search Trees

Analysis of Algorithms I: Binary Search Trees Analysis of Algorithms I: Binary Search Trees Xi Chen Columbia University Hash table: A data structure that maintains a subset of keys from a universe set U = {0, 1,..., p 1} and supports all three dictionary

More information

Math 113 HW #5 Solutions

Math 113 HW #5 Solutions Mat 3 HW #5 Solutions. Exercise.5.6. Suppose f is continuous on [, 5] and te only solutions of te equation f(x) = 6 are x = and x =. If f() = 8, explain wy f(3) > 6. Answer: Suppose we ad tat f(3) 6. Ten

More information

A binary search tree is a binary tree with a special property called the BST-property, which is given as follows:

A binary search tree is a binary tree with a special property called the BST-property, which is given as follows: Chapter 12: Binary Search Trees A binary search tree is a binary tree with a special property called the BST-property, which is given as follows: For all nodes x and y, if y belongs to the left subtree

More information

Lecture 10: What is a Function, definition, piecewise defined functions, difference quotient, domain of a function

Lecture 10: What is a Function, definition, piecewise defined functions, difference quotient, domain of a function Lecture 10: Wat is a Function, definition, piecewise defined functions, difference quotient, domain of a function A function arises wen one quantity depends on anoter. Many everyday relationsips between

More information

From Last Time: Remove (Delete) Operation

From Last Time: Remove (Delete) Operation CSE 32 Lecture : More on Search Trees Today s Topics: Lazy Operations Run Time Analysis of Binary Search Tree Operations Balanced Search Trees AVL Trees and Rotations Covered in Chapter of the text From

More information

The modelling of business rules for dashboard reporting using mutual information

The modelling of business rules for dashboard reporting using mutual information 8 t World IMACS / MODSIM Congress, Cairns, Australia 3-7 July 2009 ttp://mssanz.org.au/modsim09 Te modelling of business rules for dasboard reporting using mutual information Gregory Calbert Command, Control,

More information

How To Create A Tree From A Tree In Runtime (For A Tree)

How To Create A Tree From A Tree In Runtime (For A Tree) Binary Search Trees < 6 2 > = 1 4 8 9 Binary Search Trees 1 Binary Search Trees A binary search tree is a binary tree storing keyvalue entries at its internal nodes and satisfying the following property:

More information

Learning Outcomes. COMP202 Complexity of Algorithms. Binary Search Trees and Other Search Trees

Learning Outcomes. COMP202 Complexity of Algorithms. Binary Search Trees and Other Search Trees Learning Outcomes COMP202 Complexity of Algorithms Binary Search Trees and Other Search Trees [See relevant sections in chapters 2 and 3 in Goodrich and Tamassia.] At the conclusion of this set of lecture

More information

Geometric Stratification of Accounting Data

Geometric Stratification of Accounting Data Stratification of Accounting Data Patricia Gunning * Jane Mary Horgan ** William Yancey *** Abstract: We suggest a new procedure for defining te boundaries of te strata in igly skewed populations, usual

More information

Optimized Data Indexing Algorithms for OLAP Systems

Optimized Data Indexing Algorithms for OLAP Systems Database Systems Journal vol. I, no. 2/200 7 Optimized Data Indexing Algoritms for OLAP Systems Lucian BORNAZ Faculty of Cybernetics, Statistics and Economic Informatics Academy of Economic Studies, Bucarest

More information

Computer Science and Engineering, UCSD October 7, 1999 Goldreic-Levin Teorem Autor: Bellare Te Goldreic-Levin Teorem 1 Te problem We æx a an integer n for te lengt of te strings involved. If a is an n-bit

More information

Pressure. Pressure. Atmospheric pressure. Conceptual example 1: Blood pressure. Pressure is force per unit area:

Pressure. Pressure. Atmospheric pressure. Conceptual example 1: Blood pressure. Pressure is force per unit area: Pressure Pressure is force per unit area: F P = A Pressure Te direction of te force exerted on an object by a fluid is toward te object and perpendicular to its surface. At a microscopic level, te force

More information

2 Limits and Derivatives

2 Limits and Derivatives 2 Limits and Derivatives 2.7 Tangent Lines, Velocity, and Derivatives A tangent line to a circle is a line tat intersects te circle at exactly one point. We would like to take tis idea of tangent line

More information

Schedulability Analysis under Graph Routing in WirelessHART Networks

Schedulability Analysis under Graph Routing in WirelessHART Networks Scedulability Analysis under Grap Routing in WirelessHART Networks Abusayeed Saifulla, Dolvara Gunatilaka, Paras Tiwari, Mo Sa, Cenyang Lu, Bo Li Cengjie Wu, and Yixin Cen Department of Computer Science,

More information

A Comparison of Dictionary Implementations

A Comparison of Dictionary Implementations A Comparison of Dictionary Implementations Mark P Neyer April 10, 2009 1 Introduction A common problem in computer science is the representation of a mapping between two sets. A mapping f : A B is a function

More information

The EOQ Inventory Formula

The EOQ Inventory Formula Te EOQ Inventory Formula James M. Cargal Matematics Department Troy University Montgomery Campus A basic problem for businesses and manufacturers is, wen ordering supplies, to determine wat quantity of

More information

Verifying Numerical Convergence Rates

Verifying Numerical Convergence Rates 1 Order of accuracy Verifying Numerical Convergence Rates We consider a numerical approximation of an exact value u. Te approximation depends on a small parameter, suc as te grid size or time step, and

More information

New Vocabulary volume

New Vocabulary volume -. Plan Objectives To find te volume of a prism To find te volume of a cylinder Examples Finding Volume of a Rectangular Prism Finding Volume of a Triangular Prism 3 Finding Volume of a Cylinder Finding

More information

FINITE DIFFERENCE METHODS

FINITE DIFFERENCE METHODS FINITE DIFFERENCE METHODS LONG CHEN Te best known metods, finite difference, consists of replacing eac derivative by a difference quotient in te classic formulation. It is simple to code and economic to

More information

Binary Heaps * * * * * * * / / \ / \ / \ / \ / \ * * * * * * * * * * * / / \ / \ / / \ / \ * * * * * * * * * *

Binary Heaps * * * * * * * / / \ / \ / \ / \ / \ * * * * * * * * * * * / / \ / \ / / \ / \ * * * * * * * * * * Binary Heaps A binary heap is another data structure. It implements a priority queue. Priority Queue has the following operations: isempty add (with priority) remove (highest priority) peek (at highest

More information

Note nine: Linear programming CSE 101. 1 Linear constraints and objective functions. 1.1 Introductory example. Copyright c Sanjoy Dasgupta 1

Note nine: Linear programming CSE 101. 1 Linear constraints and objective functions. 1.1 Introductory example. Copyright c Sanjoy Dasgupta 1 Copyrigt c Sanjoy Dasgupta Figure. (a) Te feasible region for a linear program wit two variables (see tet for details). (b) Contour lines of te objective function: for different values of (profit). Te

More information

Laboratory Module 6 Red-Black Trees

Laboratory Module 6 Red-Black Trees Laboratory Module 6 Red-Black Trees Purpose: understand the notion of red-black trees to build, in C, a red-black tree 1 Red-Black Trees 1.1 General Presentation A red-black tree is a binary search tree

More information

In other words the graph of the polynomial should pass through the points

In other words the graph of the polynomial should pass through the points Capter 3 Interpolation Interpolation is te problem of fitting a smoot curve troug a given set of points, generally as te grap of a function. It is useful at least in data analysis (interpolation is a form

More information

2.1: The Derivative and the Tangent Line Problem

2.1: The Derivative and the Tangent Line Problem .1.1.1: Te Derivative and te Tangent Line Problem Wat is te deinition o a tangent line to a curve? To answer te diiculty in writing a clear deinition o a tangent line, we can deine it as te iting position

More information

SAT Math Facts & Formulas

SAT Math Facts & Formulas Numbers, Sequences, Factors SAT Mat Facts & Formuas Integers:..., -3, -2, -1, 0, 1, 2, 3,... Reas: integers pus fractions, decimas, and irrationas ( 2, 3, π, etc.) Order Of Operations: Aritmetic Sequences:

More information

Section 3.3. Differentiation of Polynomials and Rational Functions. Difference Equations to Differential Equations

Section 3.3. Differentiation of Polynomials and Rational Functions. Difference Equations to Differential Equations Difference Equations to Differential Equations Section 3.3 Differentiation of Polynomials an Rational Functions In tis section we begin te task of iscovering rules for ifferentiating various classes of

More information

Theoretical calculation of the heat capacity

Theoretical calculation of the heat capacity eoretical calculation of te eat capacity Principle of equipartition of energy Heat capacity of ideal and real gases Heat capacity of solids: Dulong-Petit, Einstein, Debye models Heat capacity of metals

More information

Determine the perimeter of a triangle using algebra Find the area of a triangle using the formula

Determine the perimeter of a triangle using algebra Find the area of a triangle using the formula Student Name: Date: Contact Person Name: Pone Number: Lesson 0 Perimeter, Area, and Similarity of Triangles Objectives Determine te perimeter of a triangle using algebra Find te area of a triangle using

More information

Data Structures Fibonacci Heaps, Amortized Analysis

Data Structures Fibonacci Heaps, Amortized Analysis Chapter 4 Data Structures Fibonacci Heaps, Amortized Analysis Algorithm Theory WS 2012/13 Fabian Kuhn Fibonacci Heaps Lacy merge variant of binomial heaps: Do not merge trees as long as possible Structure:

More information

Math Test Sections. The College Board: Expanding College Opportunity

Math Test Sections. The College Board: Expanding College Opportunity Taking te SAT I: Reasoning Test Mat Test Sections Te materials in tese files are intended for individual use by students getting ready to take an SAT Program test; permission for any oter use must be sougt

More information

Binary Search Trees. Data in each node. Larger than the data in its left child Smaller than the data in its right child

Binary Search Trees. Data in each node. Larger than the data in its left child Smaller than the data in its right child Binary Search Trees Data in each node Larger than the data in its left child Smaller than the data in its right child FIGURE 11-6 Arbitrary binary tree FIGURE 11-7 Binary search tree Data Structures Using

More information

How To Ensure That An Eac Edge Program Is Successful

How To Ensure That An Eac Edge Program Is Successful Introduction Te Economic Diversification and Growt Enterprises Act became effective on 1 January 1995. Te creation of tis Act was to encourage new businesses to start or expand in Newfoundland and Labrador.

More information

Can a Lump-Sum Transfer Make Everyone Enjoy the Gains. from Free Trade?

Can a Lump-Sum Transfer Make Everyone Enjoy the Gains. from Free Trade? Can a Lump-Sum Transfer Make Everyone Enjoy te Gains from Free Trade? Yasukazu Icino Department of Economics, Konan University June 30, 2010 Abstract I examine lump-sum transfer rules to redistribute te

More information

College Planning Using Cash Value Life Insurance

College Planning Using Cash Value Life Insurance College Planning Using Cas Value Life Insurance CAUTION: Te advisor is urged to be extremely cautious of anoter college funding veicle wic provides a guaranteed return of premium immediately if funded

More information

Average and Instantaneous Rates of Change: The Derivative

Average and Instantaneous Rates of Change: The Derivative 9.3 verage and Instantaneous Rates of Cange: Te Derivative 609 OBJECTIVES 9.3 To define and find average rates of cange To define te derivative as a rate of cange To use te definition of derivative to

More information

6. Differentiating the exponential and logarithm functions

6. Differentiating the exponential and logarithm functions 1 6. Differentiating te exponential and logaritm functions We wis to find and use derivatives for functions of te form f(x) = a x, were a is a constant. By far te most convenient suc function for tis purpose

More information

Lecture 4: Balanced Binary Search Trees

Lecture 4: Balanced Binary Search Trees Lecture 4 alanced inar Search Trees 6.006 Fall 009 Lecture 4: alanced inar Search Trees Lecture Overview The importance of being balanced VL trees Definition alance Insert Other balanced trees Data structures

More information

Data Structures and Algorithms

Data Structures and Algorithms Data Structures and Algorithms CS245-2016S-06 Binary Search Trees David Galles Department of Computer Science University of San Francisco 06-0: Ordered List ADT Operations: Insert an element in the list

More information

B-Trees. Algorithms and data structures for external memory as opposed to the main memory B-Trees. B -trees

B-Trees. Algorithms and data structures for external memory as opposed to the main memory B-Trees. B -trees B-Trees Algorithms and data structures for external memory as opposed to the main memory B-Trees Previous Lectures Height balanced binary search trees: AVL trees, red-black trees. Multiway search trees:

More information

Notes: Most of the material in this chapter is taken from Young and Freedman, Chap. 12.

Notes: Most of the material in this chapter is taken from Young and Freedman, Chap. 12. Capter 6. Fluid Mecanics Notes: Most of te material in tis capter is taken from Young and Freedman, Cap. 12. 6.1 Fluid Statics Fluids, i.e., substances tat can flow, are te subjects of tis capter. But

More information

Previous Lectures. B-Trees. External storage. Two types of memory. B-trees. Main principles

Previous Lectures. B-Trees. External storage. Two types of memory. B-trees. Main principles B-Trees Algorithms and data structures for external memory as opposed to the main memory B-Trees Previous Lectures Height balanced binary search trees: AVL trees, red-black trees. Multiway search trees:

More information

TREE BASIC TERMINOLOGIES

TREE BASIC TERMINOLOGIES TREE Trees are very flexible, versatile and powerful non-liner data structure that can be used to represent data items possessing hierarchical relationship between the grand father and his children and

More information

S. Muthusundari. Research Scholar, Dept of CSE, Sathyabama University Chennai, India e-mail: [email protected]. Dr. R. M.

S. Muthusundari. Research Scholar, Dept of CSE, Sathyabama University Chennai, India e-mail: nellailath@yahoo.co.in. Dr. R. M. A Sorting based Algorithm for the Construction of Balanced Search Tree Automatically for smaller elements and with minimum of one Rotation for Greater Elements from BST S. Muthusundari Research Scholar,

More information

Chapter 14 The Binary Search Tree

Chapter 14 The Binary Search Tree Chapter 14 The Binary Search Tree In Chapter 5 we discussed the binary search algorithm, which depends on a sorted vector. Although the binary search, being in O(lg(n)), is very efficient, inserting a

More information

Binary Search Trees CMPSC 122

Binary Search Trees CMPSC 122 Binary Search Trees CMPSC 122 Note: This notes packet has significant overlap with the first set of trees notes I do in CMPSC 360, but goes into much greater depth on turning BSTs into pseudocode than

More information

Chapter 10: Refrigeration Cycles

Chapter 10: Refrigeration Cycles Capter 10: efrigeration Cycles Te vapor compression refrigeration cycle is a common metod for transferring eat from a low temperature to a ig temperature. Te above figure sows te objectives of refrigerators

More information

Writing Mathematics Papers

Writing Mathematics Papers Writing Matematics Papers Tis essay is intended to elp your senior conference paper. It is a somewat astily produced amalgam of advice I ave given to students in my PDCs (Mat 4 and Mat 9), so it s not

More information

Binary Heap Algorithms

Binary Heap Algorithms CS Data Structures and Algorithms Lecture Slides Wednesday, April 5, 2009 Glenn G. Chappell Department of Computer Science University of Alaska Fairbanks [email protected] 2005 2009 Glenn G. Chappell

More information

Tables so far. set() get() delete() BST Average O(lg n) O(lg n) O(lg n) Worst O(n) O(n) O(n) RB Tree Average O(lg n) O(lg n) O(lg n)

Tables so far. set() get() delete() BST Average O(lg n) O(lg n) O(lg n) Worst O(n) O(n) O(n) RB Tree Average O(lg n) O(lg n) O(lg n) Hash Tables Tables so far set() get() delete() BST Average O(lg n) O(lg n) O(lg n) Worst O(n) O(n) O(n) RB Tree Average O(lg n) O(lg n) O(lg n) Worst O(lg n) O(lg n) O(lg n) Table naïve array implementation

More information

Persistent Binary Search Trees

Persistent Binary Search Trees Persistent Binary Search Trees Datastructures, UvA. May 30, 2008 0440949, Andreas van Cranenburgh Abstract A persistent binary tree allows access to all previous versions of the tree. This paper presents

More information

Symbol Tables. Introduction

Symbol Tables. Introduction Symbol Tables Introduction A compiler needs to collect and use information about the names appearing in the source program. This information is entered into a data structure called a symbol table. The

More information

Converting a Number from Decimal to Binary

Converting a Number from Decimal to Binary Converting a Number from Decimal to Binary Convert nonnegative integer in decimal format (base 10) into equivalent binary number (base 2) Rightmost bit of x Remainder of x after division by two Recursive

More information

Catalogue no. 12-001-XIE. Survey Methodology. December 2004

Catalogue no. 12-001-XIE. Survey Methodology. December 2004 Catalogue no. 1-001-XIE Survey Metodology December 004 How to obtain more information Specific inquiries about tis product and related statistics or services sould be directed to: Business Survey Metods

More information

Lecture 6: Binary Search Trees CSCI 700 - Algorithms I. Andrew Rosenberg

Lecture 6: Binary Search Trees CSCI 700 - Algorithms I. Andrew Rosenberg Lecture 6: Binary Search Trees CSCI 700 - Algorithms I Andrew Rosenberg Last Time Linear Time Sorting Counting Sort Radix Sort Bucket Sort Today Binary Search Trees Data Structures Data structure is a

More information

SAT Math Must-Know Facts & Formulas

SAT Math Must-Know Facts & Formulas SAT Mat Must-Know Facts & Formuas Numbers, Sequences, Factors Integers:..., -3, -2, -1, 0, 1, 2, 3,... Rationas: fractions, tat is, anyting expressabe as a ratio of integers Reas: integers pus rationas

More information

Sections 3.1/3.2: Introducing the Derivative/Rules of Differentiation

Sections 3.1/3.2: Introducing the Derivative/Rules of Differentiation Sections 3.1/3.2: Introucing te Derivative/Rules of Differentiation 1 Tangent Line Before looking at te erivative, refer back to Section 2.1, looking at average velocity an instantaneous velocity. Here

More information

Binary Search Trees 3/20/14

Binary Search Trees 3/20/14 Binary Search Trees 3/0/4 Presentation for use ith the textbook Data Structures and Algorithms in Java, th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldasser, Wiley, 04 Binary Search Trees 4

More information

Improved dynamic programs for some batcing problems involving te maximum lateness criterion A P M Wagelmans Econometric Institute Erasmus University Rotterdam PO Box 1738, 3000 DR Rotterdam Te Neterlands

More information

Persistent Data Structures and Planar Point Location

Persistent Data Structures and Planar Point Location Persistent Data Structures and Planar Point Location Inge Li Gørtz Persistent Data Structures Ephemeral Partial persistence Full persistence Confluent persistence V1 V1 V1 V1 V2 q ue V2 V2 V5 V2 V4 V4

More information

SAMPLE DESIGN FOR THE TERRORISM RISK INSURANCE PROGRAM SURVEY

SAMPLE DESIGN FOR THE TERRORISM RISK INSURANCE PROGRAM SURVEY ASA Section on Survey Researc Metods SAMPLE DESIG FOR TE TERRORISM RISK ISURACE PROGRAM SURVEY G. ussain Coudry, Westat; Mats yfjäll, Statisticon; and Marianne Winglee, Westat G. ussain Coudry, Westat,

More information

3 Ans. 1 of my $30. 3 on. 1 on ice cream and the rest on 2011 MATHCOUNTS STATE COMPETITION SPRINT ROUND

3 Ans. 1 of my $30. 3 on. 1 on ice cream and the rest on 2011 MATHCOUNTS STATE COMPETITION SPRINT ROUND 0 MATHCOUNTS STATE COMPETITION SPRINT ROUND. boy scouts are accompanied by scout leaders. Eac person needs bottles of water per day and te trip is day. + = 5 people 5 = 5 bottles Ans.. Cammie as pennies,

More information

SWITCH T F T F SELECT. (b) local schedule of two branches. (a) if-then-else construct A & B MUX. one iteration cycle

SWITCH T F T F SELECT. (b) local schedule of two branches. (a) if-then-else construct A & B MUX. one iteration cycle 768 IEEE RANSACIONS ON COMPUERS, VOL. 46, NO. 7, JULY 997 Compile-ime Sceduling of Dynamic Constructs in Dataæow Program Graps Soonoi Ha, Member, IEEE and Edward A. Lee, Fellow, IEEE Abstract Sceduling

More information

Tangent Lines and Rates of Change

Tangent Lines and Rates of Change Tangent Lines and Rates of Cange 9-2-2005 Given a function y = f(x), ow do you find te slope of te tangent line to te grap at te point P(a, f(a))? (I m tinking of te tangent line as a line tat just skims

More information

Analysis of Algorithms I: Optimal Binary Search Trees

Analysis of Algorithms I: Optimal Binary Search Trees Analysis of Algorithms I: Optimal Binary Search Trees Xi Chen Columbia University Given a set of n keys K = {k 1,..., k n } in sorted order: k 1 < k 2 < < k n we wish to build an optimal binary search

More information

6 March 2007 1. Array Implementation of Binary Trees

6 March 2007 1. Array Implementation of Binary Trees Heaps CSE 0 Winter 00 March 00 1 Array Implementation of Binary Trees Each node v is stored at index i defined as follows: If v is the root, i = 1 The left child of v is in position i The right child of

More information

Lecture Notes on Binary Search Trees

Lecture Notes on Binary Search Trees Lecture Notes on Binary Search Trees 15-122: Principles of Imperative Computation Frank Pfenning André Platzer Lecture 17 October 23, 2014 1 Introduction In this lecture, we will continue considering associative

More information

Binary Heaps. CSE 373 Data Structures

Binary Heaps. CSE 373 Data Structures Binary Heaps CSE Data Structures Readings Chapter Section. Binary Heaps BST implementation of a Priority Queue Worst case (degenerate tree) FindMin, DeleteMin and Insert (k) are all O(n) Best case (completely

More information

PES Institute of Technology-BSC QUESTION BANK

PES Institute of Technology-BSC QUESTION BANK PES Institute of Technology-BSC Faculty: Mrs. R.Bharathi CS35: Data Structures Using C QUESTION BANK UNIT I -BASIC CONCEPTS 1. What is an ADT? Briefly explain the categories that classify the functions

More information

Chapter 7 Numerical Differentiation and Integration

Chapter 7 Numerical Differentiation and Integration 45 We ave a abit in writing articles publised in scientiþc journals to make te work as Þnised as possible, to cover up all te tracks, to not worry about te blind alleys or describe ow you ad te wrong idea

More information

CS711008Z Algorithm Design and Analysis

CS711008Z Algorithm Design and Analysis CS711008Z Algorithm Design and Analysis Lecture 7 Binary heap, binomial heap, and Fibonacci heap 1 Dongbo Bu Institute of Computing Technology Chinese Academy of Sciences, Beijing, China 1 The slides were

More information

2.12 Student Transportation. Introduction

2.12 Student Transportation. Introduction Introduction Figure 1 At 31 Marc 2003, tere were approximately 84,000 students enrolled in scools in te Province of Newfoundland and Labrador, of wic an estimated 57,000 were transported by scool buses.

More information

Shell and Tube Heat Exchanger

Shell and Tube Heat Exchanger Sell and Tube Heat Excanger MECH595 Introduction to Heat Transfer Professor M. Zenouzi Prepared by: Andrew Demedeiros, Ryan Ferguson, Bradford Powers November 19, 2009 1 Abstract 2 Contents Discussion

More information

Introduction Advantages and Disadvantages Algorithm TIME COMPLEXITY. Splay Tree. Cheruku Ravi Teja. November 14, 2011

Introduction Advantages and Disadvantages Algorithm TIME COMPLEXITY. Splay Tree. Cheruku Ravi Teja. November 14, 2011 November 14, 2011 1 Real Time Applications 2 3 Results of 4 Real Time Applications Splay trees are self branching binary search tree which has the property of reaccessing the elements quickly that which

More information

Binary Search Tree. 6.006 Intro to Algorithms Recitation 03 February 9, 2011

Binary Search Tree. 6.006 Intro to Algorithms Recitation 03 February 9, 2011 Binary Search Tree A binary search tree is a data structure that allows for key lookup, insertion, and deletion. It is a binary tree, meaning every node of the tree has at most two child nodes, a left

More information

f(x + h) f(x) h as representing the slope of a secant line. As h goes to 0, the slope of the secant line approaches the slope of the tangent line.

f(x + h) f(x) h as representing the slope of a secant line. As h goes to 0, the slope of the secant line approaches the slope of the tangent line. Derivative of f(z) Dr. E. Jacobs Te erivative of a function is efine as a limit: f (x) 0 f(x + ) f(x) We can visualize te expression f(x+) f(x) as representing te slope of a secant line. As goes to 0,

More information

Lecture 2 February 12, 2003

Lecture 2 February 12, 2003 6.897: Advanced Data Structures Spring 003 Prof. Erik Demaine Lecture February, 003 Scribe: Jeff Lindy Overview In the last lecture we considered the successor problem for a bounded universe of size u.

More information

CS104: Data Structures and Object-Oriented Design (Fall 2013) October 24, 2013: Priority Queues Scribes: CS 104 Teaching Team

CS104: Data Structures and Object-Oriented Design (Fall 2013) October 24, 2013: Priority Queues Scribes: CS 104 Teaching Team CS104: Data Structures and Object-Oriented Design (Fall 2013) October 24, 2013: Priority Queues Scribes: CS 104 Teaching Team Lecture Summary In this lecture, we learned about the ADT Priority Queue. A

More information

An inquiry into the multiplier process in IS-LM model

An inquiry into the multiplier process in IS-LM model An inquiry into te multiplier process in IS-LM model Autor: Li ziran Address: Li ziran, Room 409, Building 38#, Peing University, Beijing 00.87,PRC. Pone: (86) 00-62763074 Internet Address: [email protected]

More information

Operations: search;; min;; max;; predecessor;; successor. Time O(h) with h height of the tree (more on later).

Operations: search;; min;; max;; predecessor;; successor. Time O(h) with h height of the tree (more on later). Binary search tree Operations: search;; min;; max;; predecessor;; successor. Time O(h) with h height of the tree (more on later). Data strutcure fields usually include for a given node x, the following

More information

Research on the Anti-perspective Correction Algorithm of QR Barcode

Research on the Anti-perspective Correction Algorithm of QR Barcode Researc on te Anti-perspective Correction Algoritm of QR Barcode Jianua Li, Yi-Wen Wang, YiJun Wang,Yi Cen, Guoceng Wang Key Laboratory of Electronic Tin Films and Integrated Devices University of Electronic

More information

CSE 326: Data Structures B-Trees and B+ Trees

CSE 326: Data Structures B-Trees and B+ Trees Announcements (4//08) CSE 26: Data Structures B-Trees and B+ Trees Brian Curless Spring 2008 Midterm on Friday Special office hour: 4:-5: Thursday in Jaech Gallery (6 th floor of CSE building) This is

More information

Introduction to Data Structures and Algorithms

Introduction to Data Structures and Algorithms Introduction to Data Structures and Algorithms Chapter: Elementary Data Structures(1) Lehrstuhl Informatik 7 (Prof. Dr.-Ing. Reinhard German) Martensstraße 3, 91058 Erlangen Overview on simple data structures

More information

1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++

1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++ Answer the following 1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++ 2) Which data structure is needed to convert infix notations to postfix notations? Stack 3) The

More information

Cpt S 223. School of EECS, WSU

Cpt S 223. School of EECS, WSU Priority Queues (Heaps) 1 Motivation Queues are a standard mechanism for ordering tasks on a first-come, first-served basis However, some tasks may be more important or timely than others (higher priority)

More information