Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I find most frequent combinations of numbers in a list?
    primarykey
    data
    text
    <p>Imagine you have a list of numbers (or letters), such as </p> <blockquote> <p>1177783777297461145777267337774652113777236237118777</p> </blockquote> <p>I want to find the most frequent combinations of numbers in this list:</p> <p>for 1-digit-long combinations - it is the most frequent number in this list</p> <p>for 2-digit-long combinations - probably '11'</p> <p>for 3-digits-long combinations - probably '777' etc</p> <p>Is there some special algorythm for such a tasks?</p> <p>UPDATE Well, by myself I have coded the following (Java). Looks like execution time is proportional to data size multiplied by pattern size:</p> <pre><code>public static void main(String[] args) { int DATA_SIZE = 10000; int[] data = new int[DATA_SIZE]; for (int i = 0; i &lt; DATA_SIZE; i++) { data[i] = (int) (10 * Math.random()) % 10; System.out.print(data[i]); } int[] pattern1 = new int[]{1, 2, 3}; int[] pattern2 = new int[]{7, 7, 7}; int[] pattern3 = new int[]{7, 7}; System.out.println(); System.out.println(match(data, pattern1)); System.out.println(match(data, pattern2)); System.out.println(match(data, pattern3)); } static int match(int[] data, int[] pattern) { int matches = 0; int i = 0; while (i &lt; data.length) { matches = isEqual(data, i, pattern) ? matches + 1 : matches; i++; } return matches; } static boolean isEqual(int[] a, int startIndex, int[] a2) { if (a == a2) { return true; } if (a == null || a2 == null) { return false; } for (int i = 0; i &lt; a2.length; i++) { if (a[startIndex + i] != a2[i]) { return false; } } return true; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload