Click here to Skip to main content
15,891,184 members
Home / Discussions / Algorithms
   

Algorithms

 
GeneralRe: Decision tree on random examples? Pin
Plasticstone6-Feb-16 6:55
Plasticstone6-Feb-16 6:55 
GeneralRe: Decision tree on random examples? Pin
Gerry Schmitz6-Feb-16 7:12
mveGerry Schmitz6-Feb-16 7:12 
QuestionWhat will be the time complexity and the size of subset for the following illustration in a polynomial time algorithm? Pin
operan5-Feb-16 6:59
operan5-Feb-16 6:59 
SuggestionRe: What will be the time complexity and the size of subset for the following illustration in a polynomial time algorithm? Pin
Richard Deeming5-Feb-16 7:23
mveRichard Deeming5-Feb-16 7:23 
GeneralRe: What will be the time complexity and the size of subset for the following illustration in a polynomial time algorithm? Pin
operan9-Mar-16 5:03
operan9-Mar-16 5:03 
AnswerRe: What will be the time complexity and the size of subset for the following illustration in a polynomial time algorithm? Pin
Matt T Heffron5-Feb-16 14:52
professionalMatt T Heffron5-Feb-16 14:52 
GeneralRe: What will be the time complexity and the size of subset for the following illustration in a polynomial time algorithm? Pin
operan9-Mar-16 5:17
operan9-Mar-16 5:17 
QuestionAdding branch to a tree Pin
Plasticstone4-Feb-16 8:10
Plasticstone4-Feb-16 8:10 
Hello,

I have a class Tree
C#
public class Tree{
    private int tree_height;
    private int tree_width;
    private int nodes_count;
    private List<Node> tree_nodes;}

and class node
C#
public class Node{
    //private
    private object state;
    private int ordering;
    private int height;
    private int parent;}

I would like to create a method to add a branch to a tree
here is my code:
C#
public void AddBranch(Tree branch, int node_num)
{
    if (nodes_count >= node_num && node_num > 0)
    {
        int last_el_ordering = nodes_count,
            first_parent_height = tree_nodes[node_num - 1].Height,
            first_parent_ordering = tree_nodes[node_num - 1].Ordering;
        tree_nodes.Add(new Node(branch.Tree_nodes.First().State, last_el_ordering + 1, first_parent_ordering, first_parent_height + 1));
        foreach (Node el in branch.Tree_nodes.Skip(1))
            tree_nodes.Add(new Node(el.State, el.Ordering + last_el_ordering, el.Parent + last_el_ordering, el.Height + first_parent_height));
        tree_nodes = tree_nodes.OrderBy(match => match.Height).ToList();
        int i = 1;
        foreach (Node el in tree_nodes)
        {
            List<Node> temp = tree_nodes.ToList().FindAll(match => match.Parent == el.Ordering).ToList();
            el.Ordering = i++;
            if (temp.Count() > 0)
                foreach (Node el2 in temp)
                    el2.Parent = el.Ordering;
        }
    }
}

I have a little problem when I add new node after connecting two trees eg: to tree
first
a b c
false false false
i want to add a branch
d
false
to the first node
The label "false" which is child of "d" is getting misplaced and I cannot figure out why. Please help.


the input
C#
Tree testing_tree1 = new Tree(new Node("start"));
List<string> temp = new List<string> { "a", "b", "c" };
foreach(string el in temp)
    testing_tree1.AddBranch(new Tree(new Node(el)),1);
for (int i = 0; i < 3; i++)
   testing_tree1.AddBranch(new Tree(new Node("false")), i+2);
Tree testing_tree2 = new Tree(new Node("d"));
testing_tree2.AddBranch(new Tree(new Node("false")), 1);
testing_tree1.AddBranch(testing_tree2, 1);
testing_tree1.DisplayTree();
Console.Read();

the output
tree depth: 3 tree width: 4 nodes count: 9
Node number:1, Node parent:-1, Node height:1, Node value:start
Node number:2, Node parent:1, Node height:2, Node value:a
Node number:3, Node parent:1, Node height:2, Node value:b
Node number:4, Node parent:1, Node height:2, Node value:c
Node number:5, Node parent:1, Node height:2, Node valueBig Grin | :-D
Node number:6, Node parent:2, Node height:3, Node value:false
Node number:7, Node parent:3, Node height:3, Node value:false
Node number:8, Node parent:4, Node height:3, Node value:false
Node number:9, Node parent:8, Node height:3, Node value:false
AnswerRe: Adding branch to a tree Pin
Patrice T4-Feb-16 22:11
mvePatrice T4-Feb-16 22:11 
QuestionAlgorithm for plotting charts with more than three (3) Axis Pin
Makinde A.29-Jan-16 19:31
professionalMakinde A.29-Jan-16 19:31 
AnswerRe: Algorithm for plotting charts with more than three (3) Axis Pin
Gerry Schmitz2-Feb-16 9:36
mveGerry Schmitz2-Feb-16 9:36 
AnswerRe: Algorithm for plotting charts with more than three (3) Axis Pin
NeverJustHere4-Feb-16 23:39
NeverJustHere4-Feb-16 23:39 
QuestionPlease feedback on class Node, Tree and help to finish DecisionTreeLearning class Pin
Plasticstone28-Jan-16 10:18
Plasticstone28-Jan-16 10:18 
AnswerRe: Please feedback on class Node, Tree and help to finish DecisionTreeLearning class Pin
Richard MacCutchan28-Jan-16 22:31
mveRichard MacCutchan28-Jan-16 22:31 
QuestionSine wave Analysis Alogoritham Pin
haritheera28-Jan-16 6:39
haritheera28-Jan-16 6:39 
AnswerRe: Sine wave Analysis Alogoritham Pin
Chris Losinger29-Jan-16 9:51
professionalChris Losinger29-Jan-16 9:51 
GeneralRe: Sine wave Analysis Alogoritham Pin
Daniel Pfeffer30-Jan-16 23:21
professionalDaniel Pfeffer30-Jan-16 23:21 
Questioncalculating the effect of "weighted vectors" Pin
BillWoodruff23-Jan-16 14:09
professionalBillWoodruff23-Jan-16 14:09 
AnswerRe: calculating the effect of "weighted vectors" Pin
Kenneth Haugland26-Jan-16 8:16
mvaKenneth Haugland26-Jan-16 8:16 
GeneralRe: calculating the effect of "weighted vectors" Pin
BillWoodruff26-Jan-16 23:07
professionalBillWoodruff26-Jan-16 23:07 
GeneralRe: calculating the effect of "weighted vectors" Pin
Kenneth Haugland27-Jan-16 3:46
mvaKenneth Haugland27-Jan-16 3:46 
AnswerRe: calculating the effect of "weighted vectors" Pin
Daniel Pfeffer26-Jan-16 23:23
professionalDaniel Pfeffer26-Jan-16 23:23 
AnswerRe: calculating the effect of "weighted vectors" Pin
jschell27-Jan-16 9:00
jschell27-Jan-16 9:00 
GeneralRe: calculating the effect of "weighted vectors" Pin
Daniel Pfeffer27-Jan-16 22:21
professionalDaniel Pfeffer27-Jan-16 22:21 
GeneralRe: calculating the effect of "weighted vectors" Pin
jschell28-Jan-16 13:47
jschell28-Jan-16 13:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.