Solved

Density of selected values within file

Posted on 2011-02-14
7
360 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Math question 3 73
Calculating Standard Deviation inside Excel. 5 80
Calculating Probability 18 86
c++ reading data from file into two dimensional array 3 93
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 …
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…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
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.

930 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now