Assume you have a JAVA Tree with the following node: class node { node left; nod
ID: 3886715 • Letter: A
Question
Assume you have a JAVA Tree with the following node:
class node {
node left;
node right;
int data; }
Also assume that you have a method defined (header shown below) which securely deletes data (overwrites it to prevent other processes from getting at the information) – this method takes a node reference and returns nothing (void); assume it has already been tested and works. You need to write a recursive method that will traverse a tree and process each node (by process, I mean calling SecureWipe for the erase).
[public static void SecureWipe (node target)] HINTS: Think first about the simplest tree case; focus on the ORDER that the processing needs to occur
Explanation / Answer
Please find my answer.
Given :
class node {
node left;
node right;
int data;
}
public static void SecureWipe (node target)
Now we need to process each node, since SecureWipe method process the node and
delte the node.
So, we need to traverse the tree in POST ORDER:
process left subtree
process right subtree
then process root
void traverse(node root) {
// base condition
if(root == null)
return;
SecureWipe(node.left);
SecureWipe(node.right);
SecureWipe(root);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.