Is it possible to select a subset from a large set based on a property or predicate in less than O(n)?
For a simple example, let's say I have a large set of authors. Each author has a one-to-many relationship with a set of books and a one-to-one relationship with the city of birth.
Is there a way to effectively make a request like "get all the books of authors who were born in Chicago"? The only way I can come up with is to first select all the authors from the city (quickly with a good index), then thin out them and accumulate all my books ( O(n)where nis the number of authors from Chicago).
I know that databases do something like this in certain joins, and Endeca claims to be able to do it “quickly” using what they call “Navigation with respect to records”, but I could not find anything about real algorithms used or even their computational complexity.
I'm not really interested in the exact data structure ... I would be thrilled to find out how to do this in RDBMS , or a key / value store, or just about anything.
Also, what about the third or fourth requests of this kind? (Get me all the books written by authors living in cities with an immigrant population of more than 10,000 ...) Is there a generalized n-degree algorithm and what are its performance characteristics?
Edit:
, , , , . , , :
DATA
1. Milton England
2. Shakespeare England
3. Twain USA
4. Milton Paridise Lost
5. Shakespeare Hamlet
6. Shakespeare Othello
7. Twain Tom Sawyer
8. Twain Huck Finn
INDEX
"Milton" (1, 4)
"Shakespeare" (2, 5, 6)
"Twain" (3, 7, 8)
"Paridise Lost" (4)
"Hamlet" (5)
"Othello" (6)
"Tom Sawyer" (7)
"Huck Finn" (8)
"England" (1, 2)
"USA" (3)
, " ". , O(1) -, : (1, 2). , , , {1, 2} ANOTHER O(1) lookup: 1 -> {4}, 2 -> {5, 6}, {4, 5, 6}.
- ? , , , Book to Country. . , , .