1. public String getPath(Object data) {
  2.         if (this.data.equals(data))
  3.         return data.toString();
  4.     String leftPath="",rightPath="";
  5.     if (left!=null)
  6.         leftPath=left.getPath(data);
  7.     if (right!=null)
  8.         rightPath=right.getPath(data);
  9.     if (leftPath!="")
  10.         return this.data+leftPath;
  11.     if (rightPath!="")
  12.         return this.data+rightPath;
  13.     return "";            
  14. }

Grading key:

  • A (-1) small mistake like : missing return statement, a value is not passed to recursive call, Syntax error
  • B (-2) redundant code, using IndexOf() for a String, calling toString() of Node instead of data, not checking for null pointer
  • C (-3) using auxiliary function, non-recursive solution
  • D (-5) using functions that were not defined, partial traversal of the sub tree, incorrect recursive call, result is in reverse order
  • E (-3 to -5 ) missing or incorrect stopping condition
  • F(-10) the path returned doesn’t start from The root or only passes through the root.
  • G (-5 to -10) a logical error, like overriding previous results, concatenation of erroneous results to the solution
  • H(-5 to -15) partial solution which includes correct but unfinished code.