-1

I have this method to perform depth first search on the binary tree

class Node
{
    public Node Left { get; set; }
    public Node Right { get; set; }
    public int value { get; set; }

    public void DepthFirst(Node node)
    {
        if (node != null)
        {
            Console.WriteLine(node.value + " ");
            DepthFirst(node.Left);
            DepthFirst(node.Right);
        }
    }
}

and now I have to use iterative deepening depth first search instead, I know how iterative deepening works but I have no idea how do I implement it.

I don't need any goal, the only purpose is to search the tree and output the node values.

EDIT: I don't have any code that I wrote for the Iterative Deepening, that's what I'm asking for.

G3n1t0
  • 198
  • 1
  • 10
  • _I know how iterative deepening works_ I don't, but if you post pseudo code, I might be able to help you implement it in C#. – Nicholas Hunter Apr 26 '21 at 18:14
  • What _specifically_ do you need help with? You can find details on IDDFS here: https://en.wikipedia.org/wiki/Iterative_deepening_depth-first_search. You should be able to modify the code you have simply by adding a depth parameter, and a top-level loop that calls it iteratively. IDDFS is used for _searching_, and you don't seem to have any actual searching in your example, so it's not clear how that fits in. Please improve the question. – Peter Duniho Apr 26 '21 at 18:18
  • @NicholasHunter the pseudo code is like this: 1.Perform DFS for each level of tree, first it will search the root then the root and the second level and so on. – G3n1t0 Apr 26 '21 at 18:27
  • Please put clarifications in the post itself, by using the [Edit](https://stackoverflow.com/posts/67271493/edit) link found at the bottom of the post. Comments are to be used to _request_ clarification, not to provide it. – Peter Duniho Apr 26 '21 at 18:30
  • @PeterDuniho Sorry but I don't understand how do I clarify anymore, I just need the algorithm for iterative deepening depth first search in C# – G3n1t0 Apr 26 '21 at 18:34
  • To improve your post, you need to do **two** things: first, post the IDDFS code you have so far; second, explain what part of that code you need help with. You've provided that explanation above, but the explanation doesn't go here in the comments. You need to **edit the question itself** to fix it so that it includes any clarification you want to offer. – Peter Duniho Apr 26 '21 at 18:36
  • @PeterDuniho Okay I just did – G3n1t0 Apr 26 '21 at 18:45
  • 1
    No, not really. You didn't. You added a single additional sentence: _"I don't have any code that I wrote for the Iterative Deepening, that's what I'm asking for"_. You wrote in a comment above that you _"don't what the length of that loop will be"_. That implies that if only you knew the upper bound of the loop (i.e. when to terminate it), you could write the rest. So, **do that**. Write the code as if you know how to terminate the outer loop, and then include that code, along with the clarification you've provided in the comment (and which you haven't added to the question yet). – Peter Duniho Apr 26 '21 at 18:47
  • 1
    If you _also_ don't know how write _any_ of the IDDFS code, you need to at least make some effort to _try_ to, and show that. Stack Overflow isn't a code-writing service, and answering homework questions isn't helpful unless the answerer can understand what it is exactly the question's author _specifically_ needs help with. – Peter Duniho Apr 26 '21 at 18:48

1 Answers1

-1

I fixed it. The problem was at the python code below

G3n1t0
  • 198
  • 1
  • 10