|
Dear everyone;
I have got a pure C++/ algorithmic question that i would appreciate your input towards.
I have a number of files (lets say 100 files) of similar input formats (Strings). To reduce the complexity of the problem I will give you a simplied example:
File 1: File 2: File 3: File4:
A A B A
B E A B
C D D A
D D F E
E F E E
I want to write a program which reads the files and produces a tree, in which the first node is the node from the first line (from above) with the highest number of occurences (so we basically check every first item in each file 'A, A, B, A' in this case. Item 'A' has occured three times so it will represent the root node). Consequently File 3 is ignored.
The resulting tree will be something like
A (3/4 occurrences = 75%)
B ( 2/4 occurrences = 50%) E (1/4 occurrences = 25%)
C (1 occurrence=25%) A (1 occurrence= 25%) D (1 occurrence=25%)
D (2/4 occurrences = 50%) E (1 occurrence = 25%)
E (2/4 occurrences = 50%) F (1 occurrence = 25%)
SO basically the program should go through the files and construct a tree with a % value of each node. every time branching occurs the % will be divided depending on the number of children.
My question is, is there any specific algorithm / similar algorithms which i can use to overcome this problem ? and What's the best way to visualise the tree?
Your help is very much appreciated
Best Regards
llp00na
|
|
|
|
|
Hi,
I am a bit confused by your example.
It appears that you keep only the highest value for the first line, but keep all values for the following lines.
On the following lines the percentage is based on the number of times the string occurs total, not as part of the tree.
My reading of your algorithum is:
Take the first line from each file.
Find the most common 'first line' value.
Discard all file that do not have this as the first line value
Using all the remaining files, for each line, count how many of each string occurs.
This, to me, is not really a tree.
If it were a tree you would get:
A (3/4 occurrences = 75%)
B ( 2/4 occurrences = 50%) E (1/4 occurrences = 25%)
C (1 occurrence=25%) A (1 occurrence= 25%) D (1 occurrence=25%)
D (1 occurrence=25%) E (1 occurrence= 25%) D (1 occurrence= 25%)
E (1 occurrence=25%) E (1 occurrence= 25%) F (1 occurrence= 25%)
Could you please clarify what you are after?
Hugh
|
|
|
|
|
thanx for your reply,
The problem is exactly how you understood it. except for your proposed tree,
A (3/4 occurrences = 75%)
B ( 2/4 occurrences = 50%) E (1/4 occurrences = 25%)
C (1 occurrence=25%) A (1 occurrence= 25%) D (1 occurrence=25%)
D (1 occurrence=25%) E (1 occurrence= 25%) D (1 occurrence= 25%)
E (1 occurrence=25%) E (1 occurrence= 25%) F (1 occurrence= 25%)
unfortunately i cant show you the arrows of the tree. the tree you proposed is correct. if you check level 4 and level 5 of the tree you will see 2 nodes labelled D and 2 nodes labelled E. The only difference between my tree and yours is that I have grouped the two similar nodes in one node (and increased the % to 50 instead of 25% for each node). If i would represent my tree i would have two arrows coming from Node C and Node D (level three) towards Node D in level 4. So a node can get have two parents or more.
Why did i think a tree would be appropriate? I need to store the data of my files into a data structure for later processing. Please if you do have any other / better suggestion i would be grateful.
Regards
llp00na
|
|
|
|
|
llp00na wrote: C (1 occurrence=25%) A (1 occurrence= 25%) D (1 occurrence=25%)
D (2/4 occurrences = 50%) E (1 occurrence = 25%)
E (2/4 occurrences = 50%) F (1 occurrence = 25%)
What parent node do these child nodes belong to? It would help if you'd line things up so that they are visually intuitive.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Thanx for your reply;
Unfortunately i cant use arrows to show what i really mean. I will try to explain.
Level 1: C (1 occurrence=25%) A (1 occurrence= 25%) D (1 occurrence=25%)
Level 2: D (2/4 occurrences = 50%) E (1 occurrence = 25%)
Level 3: E (2/4 occurrences = 50%) F (1 occurrence = 25%)
Node D (in level 2) will have two arrows coming towards it (from Node C and D -level 1-). So the % will accumulate to 50%. Node E is the child of node A.
Node E (in level 3) will have two arrows coming from node D and node E (both are being the parent of E in this case). Node F (level 3) is the child of Node D.
I hope this is clearer.
Regards
llp00na
|
|
|
|
|
Hi,
If any one knows how resource editor works by using .rc file and .h file completely then it will be very helpful for me.
thanks
sdafsdfdsfs
|
|
|
|
|
|
Hi,
The problem is that, i have some resource (say frame.rc) which is getting corrupted whenever i m saving it or editing it from resource editor, but if i edit it manually then there is no problem.
This resource i think is a satellite resource which is specific for a language.
If i know how the Resource editor compiles or writes the .rc file and how it
uses the resource.h file then it will be very helpful for me.
Thanks
Jaffer
|
|
|
|
|
Hi.
I have a problem with CArchive class.
I use CArchive class for reading and writing in file. However,for reading , I want to khow when it gets at the end of the file.I mean, I want to read whole data from begining to end of file, but when it gets at the end of the file, it throws an exception.
Thancks.
|
|
|
|
|
The CArchive::Read() method will return a value indicating that the EOF has been reached.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
I have an application with doc/view architecture where I can open a new file with File/New option.Now I want to add an option in the menu so that I can create a new file alongwith a view window through the option.I am not able to do it.
Please Help
Prithaa
|
|
|
|
|
Hi!
I need a simple sample to use ToolTip above any control(button, static, edit, ...)
please help me
Zo.Naderi-Iran
|
|
|
|
|
Did you search on the codeproject?
|
|
|
|
|
|
Dear All,
I am playing with Registry Entries. here the code .,
while(RegEnumValue(hRoot1,Cnt,ValName,&nCnt,NULL,NULL,Buffer,&BufferSize)==ERROR_SUCCESS){
if(MemberVariable==ValName){
AfxMessageBox(_T("Matching Success"));
RegSetValueEx(hRoot1,ValName,0,REG_SZ,(BYTE*)&MemberValue,sizeof(MemberValue));
}
}
Here the "RegEnum" function is successed only for two times. But in my registry (hRoot1) Key is having more than seven value names. Here i am doing while loop iteration for all value names. But its doing with first two value names.
Can one help me on this ?
|
|
|
|
|
Sakthiu wrote: if(MemberVariable==ValName){
What are you hoping to accomplish with this? Unless MemberVariable is a CString or std::string object, what you have will not work.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
I think so ., that 'RegEnumKey' function is not properly working.(while doing more iterations).
MemberVarible is a CString.
ValName is a char[256];
now try it ...
|
|
|
|
|
Why are you not incrementing Cnt ? It should be 0 for the first call to RegEnumValue() and then be incremented for each successive call.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
CMyClass::CMyClass()
{
m_thread=(HANDLE)_beginthreadex(0,0,&MyClass::MyFunct,0,0,0);//error C2664: '_beginthreadex' : cannot convert parameter 3 from 'unsigned int (__stdcall CMyClass::* )(void *)' to 'unsigned int (__stdcall *)(void *)'
}
CMyClass::~CMyClass(void)
{
CloseHandle(m_thread);
}
unsigned __stdcall CMyClass::MyFunct(void* param)
{
return 0;
}
|
|
|
|
|
It has nothing to do with the fact that you start it in your constructor. The problem is that the 3rd argument you pass to beginthreadex is invalid: the function expects to have a pointer to a global function and you pass a pointer to a member function. The difference is that they don't have the same prototype: the member function has an implicit parameter: the this parameter (that allows the function to know to which instance of the class it belongs to).
To solve the problem, you can declare the function as static (in that case, the this parameter is not passed). But of course, you won't be able to access members of the class which are non-static (because the function is global to all instances and thus doesn't belong to a specific instance).
Another solution is to pass the pointer to a global function and pass the pointer to the instance of your class as the parameter (this). In the function, you'll then need to cast it to your class:
unsigned __stdcall MyGlobalFunct(void* param)
{
CMyClass* pClass = (CMyClass*)param;
pClass->MyMemFunction();
return 0;
}
|
|
|
|
|
|
What happens if you run this code
<br />
unsigned __stdcall MyFunct(void* param);<br />
...<br />
...<br />
m_thread=(HANDLE)_beginthreadex(0,0,&MyFunct,0,0,0);<br />
<br />
unsigned __stdcall MyFunct(void* param)<br />
{<br />
return 0;<br />
} <br />
|
|
|
|
|
hi,
I want to write large amount of binary data to the database.I wanted to write the same data,which i serialize in serialization into the database.Instead of saving it as disk file ,i want to write the file into database.One of my friend has said we can do it using BLOB.What is BLOB ? i don`t know anything about it.There is any good article about it using ADO.?I am using ADO.
thank`s in before
James.
|
|
|
|
|
RockyJames wrote: What is BLOB ?
See here.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Hi,
Could u tell me the formula of point of intersection?
Here I have two straight lines
First straight line co-ordinate (x,y) & (x1,y1)
Second st. line co-ordinate (x2,y2) & (x3,y3).
Now I have all these co-ordinates with me,so please suggest me the point of intersection formula based on above input.
Thanks in Advance
Ram
|
|
|
|