Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For full credit, you need to process a million such queries ( and n is at least a few hundred thousand ) , this is

For full credit, you need to process a million such queries (and n is at least
a few hundred thousand), this is not feasible.
There is actually a \Theta (log n) algorithm for answering range queries in AVL
trees. But for this algorithm, you will need to store subtree sizes at every node.
In other words, at every node, you need to store the number of descendants of
that node. Once you have subtree sizes, range queries can be answered more
quickly. I wont give the full solution, but let me give some hints.
As I always say, think recursion. Suppose you want to find the size of a range
[str1, str2] in the subtree rooted at some node, say x. First, compare the key at x with str1 and str2. You will have three possibilities for the comparisons
(assuming, of course, that str1< str2). Two of the those possibilities can be
resolved by a single recursive call.
The third case is the interesting one, where you have to look at both children
of x. But, if you think about it carefully, for the child subtrees, you only need
to answer a less than or greater than query. These are queries where you
need to find the number of nodes greater than (or less than) a given string.
These types of queries can again be handled by recursion. Here, you will
notice (again thinking about it carefully) that if subtree sizes are already stored,
then it will save you recursive calls. Indeed, less than or greater than queries
can be answered by making at most one recursive call.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Databases Object Oriented Deductive Hypermedia Technologies

Authors: Kamran Parsaye, Mark Chignell, Setrag Khoshafian, Harry Wong

1st Edition

0471503452, 978-0471503453

More Books

Students also viewed these Databases questions

Question

What branding options are available to retailers?

Answered: 1 week ago

Question

draft a research report or dissertation;

Answered: 1 week ago