19h
19h

Reputation: 829

Finding the k-longest sequences in an one-dimensional array?

In context of the realization of a project I need to find the k-longest sequences in PHP. There are many ways to implement this - but which algorithm is the fastest for PHP?

Which algorithm would you implement? (overview)

Which one is most-efficient and dynamic (numbers, strings, etc)? (fast?, time for n-elems?)

How would you implement it? (example)

Thank you!


Post Scriptum

I'm about to implement the ONISI k-nearest neightbour algorithm. The longest sequences are visualised in this schematic. The interaction history since t and the immediate history. This shematic gives a brief overview on the ONISI algorithm.enter image description here

The total/immediate-history-elements are strings representing a $state --> $action pattern. This means, considering the first 3 elements of schematic (1), data would be displayed, for instance, like: $immediate_history = array( array( "s2" => "a2" ), array( "s3" => "a3" ), array( "s1" => "a1" ) [..] );

Still any questions about the problematic?

Cheers!

Upvotes: 5

Views: 532

Answers (1)

footy
footy

Reputation: 5911

Which algorithm would you implement? (overview)

KNN is a special case of a variable-bandwidth, kernel density "balloon" estimator with a uniform kernel

Which one is most-efficient and dynamic (numbers, strings, etc)? (fast?, time for n-elems?)

I depends on your data structure. An array is defnetly slower. But use of better and advanced structure will speed things up.

How would you implement it? (example)

I highly doubt anyone will give you this here as the program is not a small one. You have to do this on your own.

Upvotes: 1

Related Questions