{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

MIT6_851S10_lec09

MIT6_851S10_lec09 - 6.851 Advanced Data Structures Spring...

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

View Full Document Right Arrow Icon
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
Image of page 1

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

View Full Document Right Arrow Icon
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 0 i 2 n .
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern