How to find a pattern

233 Views Asked by At

I have a list of objects. Each object has $3$ values that will have a value from $0$ to $100$. I want to know how iI be able to find the pattern that is most common in that list.

Object 1: 1-2-3 Object 2: 2-2-3 Object 3: 3-2-3 Object 4: 1-2-3

As example the list above i want to find out what pattern occurs the most in this list. In this example it would be 1-2-3 with 50%. However the list will be updated daily and i want to know how i will be able to make a algorithm that will give me the most used pattern of that day.

1

There are 1 best solutions below

0
On BEST ANSWER

Assuming you're not dealing with a large data set (read: millions of objects) and thus aren't concerned with performance, the following algorithm should work:

Each object will be numbered, e.g. object $k$, and $k$ will be it's id number. It's data will be an ordered triple with each constrained to $[0,100]$ (are these integers? I think you intend for that.)

The algorithm proceeds as follows:

Create list of pairs $($object id$,$ $1)$

For $i$ in 1 to number of objects

For $j$ in $[1,i-1]$

Check data for object $i=$ data for object $j$.

If true add $1$ to right entry of $($object $i,$ $n)$ obtaining $($object id$i,$ $n+1)$ (This step is how we count how many times data for object $i$ occurred in the list. This only counts occurred at and beyond $i$ though, but that's ok, because if some $p<i$ shared the same data, then the list element for object $p$ will have a higher $n$).

After above For loops, print the data for the object id with the largest right entry in the list. (This shows user what ordered triple was most common in original dataset.)