- public String getPath(Object data) {
- if (this.data.equals(data))
- return data.toString();
- String leftPath="",rightPath="";
- if (left!=null)
- leftPath=left.getPath(data);
- if (right!=null)
- rightPath=right.getPath(data);
- if (leftPath!="")
- return this.data+leftPath;
- if (rightPath!="")
- return this.data+rightPath;
- return "";
- }
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.