Solved

# Density of selected values within file

Posted on 2011-02-14
363 Views
Hello experts!

Please have a look at the numbers attached to the code.

First number is amount of indexes.
The second number is index itself.
Indexes are valued from 0..7.

So for example:

19, 4

means that we have nineteen indexes with value of 4.

My task is to analyze the density of these indexes.
These density types should be calculated and taken into consideration:
(I want to find index values and position borders they appear)

- single indexes
- couples of indexes
- triples of indexes

So if we look for single indexes we should find out that we have high density of
indexes = 4 (look at line no.2) and indexes = 0 (look at line no. 6).

If we look for triples of indexes we should find out that we have high density
of indexes 0, 1, 7 (from line no. 5 to 66).

Search for couples will be similar as for triples.

How can I make such analysis in a smart way?
Is there any mathematical tool to do such things?

Thank you

panJames

``````1, 5
19, 4
2, 6
1, 2
1, 1
18, 0
1, 1
1, 0
1, 7
3, 0
1, 1
1, 7
1, 0
1, 1
1, 7
1, 0
1, 1
1, 7
5, 0
1, 1
1, 0
1, 7
2, 0
1, 1
1, 7
1, 1
2, 0
1, 7
5, 0
1, 1
1, 7
1, 0
1, 1
2, 0
1, 7
2, 0
1, 1
1, 7
2, 0
1, 1
2, 0
1, 7
1, 0
1, 1
1, 0
1, 7
1, 1
1, 7
3, 0
1, 1
1, 7
1, 1
4, 0
1, 7
1, 1
1, 7
1, 1
1, 7
2, 0
1, 1
1, 7
4, 0
1, 1
1, 7
2, 0
1, 7
1, 5
2, 6
1, 5
2, 6
``````
0
Question by:panJames
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 22

Expert Comment

ID: 34888668
If you have Microsoft Access, you can create a query that will group and count the number of indexes. Using the data provide, I came up with the following results:

22,0
20,1
1,2
1,4
3,5
3,6
20,7

This took all of 5 minutes. If this is what you're looking for, I can provide you with some guidance on how to create the table and query.

Flyster
0

LVL 37

Expert Comment

ID: 34889679
If you don't have Access, you most likely have Excel (or OpenOffice or something that does the same thing). These programs will open the file perfectly (they are built to understand the commas as separating cells). They can do quite a bit of analysis with built-in functions and you can write scripts to do anything that computers are capable of doing.

In a string like 0,1,7,0,1,7,0,1,7, 0. Should the 0,1,7 and 1,7,0 triples both be counted (3 each)?
Does 19,4 indicate a bunch of triples of 4?
The required analysis is not yet clear.
0

Author Comment

ID: 34895179

What I need here is algorithm to solve problem.

panJames
0

LVL 37

Expert Comment

ID: 34897614
Is 4,0 essentially the same as 0,0,0,0? So do you need to look at triples like 0,0,0? We need more specifications before we can help with algorithms.

Also, what platform are you working with? C++, Excel, VBScript, pen and paper, etc
0

Author Comment

ID: 34917414
@TommySzalapski:

"Is 4,0 essentially the same as 0,0,0,0?" <- not really.

I should explain it better.

Values attached describe another file with values inside [values: 0..7]

First file:

0
0
0
0
1
1
2
2
2

it means that in the second file we get:

4, 0
2, 1
3, 2

so the second file is like a summary of the first file.

Algorithm will be using C++

panJames
0

LVL 45

Expert Comment

ID: 34936901
panJames,

Copy the list into Excel and use Data/Text to columns to split the data into 2 columns - Number of Indexes and Index. Having done that set up a small table listing the indexes and use this formula to summarise the results:

=SUMIF(\$B\$1:\$B\$70,D2,\$A\$1:\$A\$70)

It's in the atteched Excel file.

Patrick
panJames-01.xls
0

LVL 37

Accepted Solution

TommySzalapski earned 500 total points
ID: 34937402
Single indexes is easy. You just sum them all.
In C++ I would use an array like
int indexes[8];
for(int i = 0; i < 8; ++i)
indexes[8] = 0;

Then just loop through the input and if you see 4, 3 do
indexes[3] += 4
etc.
But this is the easy part

For triples you need to look at each index individually. I would use an array of arrays of arrays (actually I would call it a tree). So if you see 4, 3 you'll need to send all 4 of the 3s one at a time into your function.
You would need to track what the last two were. If I was implementing it for real, I would use a circular queue, but if you only need to deal with up to triples I would just do it the easy way.
Something like this:
(note: set up constants where they should be etc)
``````const int INDEXES = 8;//You really should use a constant for the 8

int history[3];
int triples[INDEXES][INDEXES][INDEXES];
memset(triples, 0, INDEXES*INDEXES*INDEXES*sizeof(int)); //set all to 0

//Get the first three before you start this part

triples[history[0]][history[1]][history[2]]++;

//This could be a loop (and really should be)
history[0] = history[1];
history[1] = history[2];

history[2] = newValue;

//Then you can do something like
for(int i = 0; i < INDEXES; ++i)
for(int j = 0; j < INDEXES; ++j)
for(int k = 0; k < INDEXES; ++k)
if(triples[i][j][k] > 0)
printf("%d, %d, %d: %d", i, j, k, triples[i][j][k];
``````
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

### Suggested Solutions

Foreword (May 2015) This web page has appeared at Google.  It's definitely worth considering! https://www.google.com/about/careers/students/guide-to-technical-development.html How to Know You are Making a Difference at EE In August, 2013, one …
The greatest common divisor (gcd) of two positive integers is their largest common divisor. Let's consider two numbers 12 and 20. The divisors of 12 are 1, 2, 3, 4, 6, 12 The divisors of 20 are 1, 2, 4, 5, 10 20 The highest number among the c…
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
###### Suggested Courses
Course of the Month4 days, 1 hour left to enroll