Solved

Density of selected values within file

Posted on 2011-02-14
7
362 Views
Last Modified: 2012-06-27
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

Open in new window

0
Comment
Question by:panJames
7 Comments
 
LVL 22

Expert Comment

by:Flyster
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

by:TommySzalapski
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

by:panJames
ID: 34895179
Flyster: Thank you for your answer.

What I need here is algorithm to solve problem.


panJames
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 37

Expert Comment

by:TommySzalapski
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

by:panJames
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

by:patrickab
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

by:
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

//Write your code to read the values in.
//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];

Open in new window

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Perecntage 4 73
Math Question 1 105
Triangles - computing angles 6 52
Why Two pairs of CAN_H and CAN_L going into One CAN Transciever ? 5 25
Article by: Nadia
Linear search (searching each index in an array one by one) works almost everywhere but it is not optimal in many cases. Let's assume, we have a book which has 42949672960 pages. We also have a table of contents. Now we want to read the content on p…
Lithium-ion batteries area cornerstone of today's portable electronic devices, and even though they are relied upon heavily, their chemistry and origin are not of common knowledge. This article is about a device on which every smartphone, laptop, an…
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…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question