MIT6_851S10_lec09

MIT6_851S10_lec09 - 6.851: Advanced Data Structures Spring...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 6.851: Advanced Data Structures Spring 2010 Lecture 9 — March 4, 2010 Dr. Andr´ e Schulz 1 Overview Last lecture we defined the Least Common Ancestor (LCA) and Range Min Query (RMQ) problems. Recall that an LCA query asks for the deepest node in a given rooted tree which is an ancestor of each of two query nodes, while an RMQ query asks for the minimal value stored in some contiguous subarray of a given array. We showed last lecture that an LCA query is nothing more than an RMQ query on an Euler tour of the given tree (where the value assigned to any node is its depth in the tree). Moreover, this array has the property that the difference between any pair of consecutive elements is ± 1. Thus if we could solve the RMQ problem for so-called “ ± 1 arrays” we could solve LCA. In the first part of lecture, we show how to answer RMQ queries ± 1 arrays and then using this data structure how to answer general RMQ queries. In the second part of lecture, we present some models of computations on integers and then develop data structures to answer predecessor/successor queries on a set S ⊂ { 1 , 2 ,...,u } : given a query integer x , we will be able to report the smallest element of S greater than x or the largest element of S less than x . We will develop van Emde Boas trees and y-fast trees, which both attain query times of O (log log u ) for this problem. 2 RMQ and LCA We use the same notation from the last lecture; namely, we say an algorithm is f,g for a certain class of queries if it can answer queries from that class in g time with f preprocessing. Throughout, we write A for the array on which we wish to perform RMQ queries, and n for the length of A . 2.1 O ( n log n ) ,O (1) algorithm for RMQ Our first data structure for RMQ uses a sparse lookup table M to answer queries. The width of this table is n , but the height is only log n . The entry M [ i,j ] stores the minimum index in A [ i,i + 2 j − 1]. We can build this table in O ( n log n ) time using dynamic programming: M [ i,j ] = min M [ i,j − 1] ,M [ i + 2 j − 1 ,j − 1] . Once we have built this table, we can answer a query RMQ[ i,j ] in constant time as follows. Suppose 2 k < j − i < 2 k +1 . Then the minimum entry in A [ i,j ] is simply the minimum of A [ i,i +2 k − 1] and A [ j − 2 k + 1 ,i ], both of which are stored in the sparse table. 1 2.2 O ( n ) ,O (1) algorithm for RMQ ± 1 Our next data structure reduces space by a factor of O (log n ) with the same trick we used for LAQ in the last lecture. Namely, we break A into blocks of size log 2 n and precompute all queries on small blocks. More precisely, form new arrays A and B of the length 2 n such that A [ i ] is the log n i log n ( i +1) log n minimum value stored in A 2 , 2 and B [ i ] is the index of the element attaining that minimum. Then, form a new array SUB[ i ] = A i log n , ( i +1) log n for each ≤ i ≤ 2 n ....
View Full Document

This note was uploaded on 03/31/2011 for the course EECS 6.851 taught by Professor Erikdemaine during the Spring '10 term at MIT.

Page1 / 7

MIT6_851S10_lec09 - 6.851: Advanced Data Structures Spring...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online