title: TwoSum and BinarySearchTree in testdome.com; How to solve the warning message: Performance test?
body: <p>I'm trying to solve questions of C# programming in testdome.com, but I found problem about performance. How to solve it?</p>
  
  <p><strong>BinarySearchTree</strong></p>
  
  <pre><code>using System;
  
  public class Node
  {
      public int Value { get; set; }
  
      public Node Left { get; set; }
  
      public Node Right { get; set; }
  
      public Node(int value, Node left, Node right)
      {
          Value = value;
          Left = left;
          Right = right;
      }
  }
  
  public class BinarySearchTree
  {
      public static bool Contains(Node root, int value)
      {
          Console.WriteLine("value=" + value);
          if(root == null)
              return false;
          else if(root.Value == value)
              return true;
          else if(root.Value != value)
          {
              return Contains(root.Left, value) | Contains(root.Right, value);
          }
          return false;
      }
  
      public static void Main(string[] args)
      {
          Node n1 = new Node(1, null, null);
          Node n3 = new Node(3, null, null);
          Node n2 = new Node(2, n1, n3);
  
          Console.WriteLine(Contains(n2, 3));
      }
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/vbp3w.png" rel="noreferrer">Performance test on a large tree: Memory limit exceeded</a></p>
  
  <pre><code>https://www.testdome.com/for-developers/solve-question/7482
  </code></pre>
  
  <p><strong>TwoSum</strong></p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  
  class TwoSum
  {
      public static Tuple&lt;int, int&gt; FindTwoSum(IList&lt;int&gt; list, int sum)
      {
          for(int ctr1=0; ctr1&lt;list.Count; ctr1++)
          {
              for(int ctr2=0; ctr2&lt;list.Count; ctr2++)
              {
                  if ((ctr1 != ctr2) &amp;&amp; (list[ctr1]+list[ctr2] == sum))
                      return new Tuple&lt;int, int&gt;(ctr1, ctr2);
              }
          }
          return null;
      }
  
      public static void Main(string[] args)
      {
          Tuple&lt;int, int&gt; indices = FindTwoSum(new List&lt;int&gt;() { 1, 3, 5, 7, 9 }, 12);
          Console.WriteLine(indices.Item1 + " " + indices.Item2);
      }
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/eWn32.png" rel="noreferrer">Performance test with a large number of elements: Time limit exceeded</a></p>
  
  <pre><code>https://www.testdome.com/for-developers/solve-question/8125
  </code></pre>