Data Structure for Representing Paths of a Tree Without Redundancy

Anton Harald

Consider the following tree structure in a Clojure code:

(def tree [7 9 [7 5 3 [4 6 9] 9 3] 1 [2 7 9 9]])

The paths to - for instance - all even numbers in the tree would be:

[[2 3 0] [2 3 1] [4 0]]

This is a list of lists. Each 'inner' list represents an absolute path from the root of the tree to the leaves of interest.

I'm looking now for a data structure to represent such a result without redundancy. As you can see, for instance the fragment of [2 3] is repeated in two entries. I came up with a nested hash-map, but maybe there's something simpler:

{2 {3 {0 true 1 true}
 4 {0 true}}
OlegTheCat

I believe that DAWG is overkill for your problem. Suffixes of your paths are barely going to be shared. So usage of trie should be enough (this is actually your nested hash map approach). Also it's pretty easy to generate it in clojure.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Representing tree structure in kdb

From Java

Representing graphs (data structure) in Python

From Dev

Structure representing time without date in Python

From Dev

Structure representing time without date in Python

From Dev

Given a 'tree' like data structure, print out all the paths from leaf to root

From Dev

Given a 'tree' like data structure, print out all the paths from leaf to root

From Dev

Finding all unique paths in tree structure

From Dev

Expression tree data structure

From Dev

Tree data structure in Julia

From Dev

Binary Tree Data Structure

From Dev

Nature of Tree Data Structure

From Dev

Converting tree representing math expression to a string without redundant parentheses

From Dev

What is the best data structure for representing an upper triangular matrix in Java?

From Dev

How to convert data structure to another tree structure

From Dev

Optimizing Firebase data structure for two large paths

From Dev

Deleting a tree(data structure) in Python

From Dev

Tree Data Structure with Valued Edges

From Dev

Core Data Directory (tree) Structure

From Dev

Printing a Tree data structure in Python

From Dev

Core Data Directory (tree) Structure

From Dev

Store tree data structure in database

From Dev

Pentaho to convert tree structure data

From Dev

PHP: Save data in tree structure

From Dev

Data Structure: Dictionary Like Tree

From Dev

Representing tree as a list

From Dev

representing a tree as a list in python

From Dev

Representing a Syntax Tree with QTreeview

From Dev

Avoid data redundancy in Prolog

From Dev

HT Access - Remove redundancy in long list of paths