C++ FP-tree or Prefix tree

1.9k Views Asked by At

I have some sequences as these

(100) - (102) - (103) - (104,106) - (108)
(101) - (103)
(102) - (106)

there is some efficient implementation an prefix tree or fp-tree or similar in C + +?

2

There are 2 best solutions below

0
On BEST ANSWER

I don't understand what are you saying... But if you need to build a FP tree here is best page I've found

FP Tree Algorithm

2
On

It's not clear exactly what you have because the given data doesn't appear to be in any standard notation.

If the prefixes are just a few shared initial decimal digits between integer values, they probably won't make any significant difference to data storage. You could subtract 100 before inserting values into the data structure, store the values as char, and add 100 back after retrieval, but it's probably not worth the effort.

Probably you should store the sequence of sequences as a std::deque< std::vector< int > > where the vector elements are sorted. Unless there is a pattern that I can't see or I'm misinterpreting the problem, optimal performance in finding which sequences contain a given number must be O(N) in the number of sequences times O(lg N) in the sequence length.