Answer the question
In order to leave comments, you need to log in
Is it possible to save a graph or a tree in a file?
You need to create a very large graph (adjacency list) or tree, and creating it every time you start the program is not an option. Is it possible to save it in a file (and then somehow read or recreate) so as not to lose information after the program is closed.
PS The whole complexity is not in the size of the graph, but rather in tons of information that needs to be read and the same number of operations to create it. Therefore, if it can be created only 1 time and saved, then this will solve my problem.
Language : C++ or Python
Answer the question
In order to leave comments, you need to log in
Here it is proposed to use a dictionary with keys-vertices and values - lists of adjacent vertices.
Serialization - to your taste, even in JSON.
import json
g = {
'A': ['B', 'C'],
'B': ['C', 'D'],
'C': ['D'],
'D': ['C'],
'E': ['F'],
'F': ['C']
}
output = json.dumps(g)
Usually they use caching through redis / sqlite or something else. Interfaces and bindings will decide for themselves how to serialize the object for the cache.
In the 12th lecture, Dm. Soshnikov according to func. programming is told how any tree can be converted to binary, and binary to a list (a list is the basic structure for FP languages). And there is no problem to reset the list to a file.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question