Answer the question
In order to leave comments, you need to log in
Efficient algorithm for two way search?
I'm looking for optimal data structure solutions for a two-way search. I have data and its equivalent values, let's say:
I want:
>>> find('A')
value1, value2, value3
>>> find('value1')
A, B
There is enough data that traversal of the double list is inefficient , and speed in this case is a primary indicator. In addition, I need to be able to update the data structure.
Any solutions?
Answer the question
In order to leave comments, you need to log in
It depends on how much is "enough" and how much RAM is available for this task (PC, smartphone, embedded development?).
If memory allows, then the fastest will be two binary trees (or two sorted array-lists, but then after adding an element, you will have to re-sort or look for the insertion point).
If A and Value are themselves large and/or complex objects that cannot be duplicated, then two index tables can be made that refer to the original data.
The fastest is two sorted arrays, each containing both A and Value.
The most convenient, but a little less fast - two binary trees.
if they are sharpened specifically for speed, then storing duplicates is normal.
that is, store all combinations of values:
Key-Value
A - value1
value1 -A
Try 2 dicts (if you already write in python) - under the direct and inverted index.
1. Nodes (graph) are both objects and data. This is a mixed graph.
2. Directions of connections (between nodes in the graph): no connection, one-way, two-way.
3. When you do a search, all directions (toward and away from the node) are immediately scanned at the given nodes to a single depth.
4. Further, depending on the data, a search is performed in depth, backward, or the search stops.
Do it asynchronously to save processing time.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question