Categories: Uncategorized

Tree Transvering

Description

https://www.youtube.com/watch?v=-SF2e7cDev0&feature=youtu.be   Please look this video and start the work. Please do not modify the TreeNode.Java file and also please do not create any other java file. Just use the TreeNode and Autocomplete.java to complete question 1 2 3. but please look the video first. Fill it your code where it says “fill it here”   Here is the TreeNode.java file // DO NOT MODIFY THIS FILE // DO NOT MODIFY THIS FILE // DO NOT MODIFY THIS FILE // DO NOT MODIFY THIS FILE import java.util.*;   public class TreeNode<T> { private T value; private List<TreeNode<T>> children;   public TreeNode(T value) { this.value = value; this.children = new ArrayList<>(); }   public TreeNode(T value, List<TreeNode<T>> children) { assert children != null : “children cannot be null”; this.value = value; this.children = children; }   public T getValue() { return value; }   public List<TreeNode<T>> getChildren() { return children; }   public boolean isLeaf() { return children == null || children.size() == 0; } }   And here is the AutoComplete.Java file below    import java.util.*;   public class Autocomplete {     public static void main(String[] args) { TreeNode<Character> example = makeExample();   // Q1 Examples //TreeNode<Character> endNode = findNode(example, “acn”, 0); //System.out.println(endNode.getValue()); // should output ‘n’ //System.out.println(endNode.getChildren().get(0).getValue()); // should output ‘e’   //endNode = findNode(example, “notInTree”, 0); //System.out.println(endNode); // should output null   // Q2 Examples //List<String> exampleList = new ArrayList<>(); //collectWords(example.getChildren().get(1), “”, exampleList); //System.out.println(exampleList); // should output [“eam”, “eef”, “ees”]   // exampleList.clear(); //collectWords(example.getChildren().get(1), “b”, exampleList); //System.out.println(exampleList); // should output [“beam”, “beef”, “bees”]   // exampleList.clear(); //collectWords(example.getChildren().get(1), “mm”, exampleList); //System.out.println(exampleList); // should output [“mmeam”, “mmeef”, “mmees”]   // Q3 Examples //System.out.println(candidates(example, “c”)); // Outputs [“cat”, “cow”, “cut”] //System.out.println(candidates(example, “ca”)); // Outputs [“cat”] //System.out.println(candidates(example, “an”)); // Outputs [“and”, “andrew”]   //// Outputs [“ace”, “acne”, “and”, “andrew”, “beam”, “beef”, “bees”, “cat”, “cow”, “cut”] //System.out.println(candidates(example, “”)); //System.out.println(candidates(example, “deer”)); // Outputs [] //System.out.println(candidates(example, “bean”)); // Outputs [] }     /* * Q1. findNode * Add your key ideas to this comment. * How did you approach the problem? * Why does your code work? */ public static TreeNode<Character> findNode(TreeNode<Character> node, String prefix, int index) {  //fill it here your code   throw new UnsupportedOperationException(“findNode not yet written”);  //fill it here your code }   /* * Q2. collectWords * Add your key ideas to this comment. * How did you approach the problem? * Why does your code work? */ public static void collectWords(TreeNode<Character> node, String prefix, List<String> results) { // fill it here your code throw new UnsupportedOperationException(“collectWords not yet written”); //fill it here your code   }   /* * Q3. candidates * Add your key ideas to this comment. * How did you approach the problem? * Why does your code work? */ public static List<String> candidates(TreeNode<Character> root, String prefix) { //fill it here your code throw new UnsupportedOperationException(“candidates not yet written”); //fill it here your code }   private static TreeNode<Character> makeExample() { return new TreeNode(‘*’, Arrays.asList( new TreeNode(‘a’, Arrays.asList( new TreeNode(‘c’, Arrays.asList( new TreeNode(‘e’, Arrays.asList( new TreeNode(‘$’) )), new TreeNode(‘n’, Arrays.asList( new TreeNode(‘e’, Arrays.asList( new TreeNode(‘$’) )) )) )), new TreeNode(‘n’, Arrays.asList( new TreeNode(‘d’, Arrays.asList( new TreeNode(‘$’), new TreeNode(‘r’, Arrays.asList( new TreeNode(‘e’, Arrays.asList( new TreeNode(‘w’, Arrays.asList( new TreeNode(‘$’) )) )) )) )) )) )), new TreeNode(‘b’, Arrays.asList( new TreeNode(‘e’, Arrays.asList( new TreeNode(‘a’, Arrays.asList( new TreeNode(‘m’, Arrays.asList( new TreeNode(‘$’) )) )), new TreeNode(‘e’, Arrays.asList( new TreeNode(‘f’, Arrays.asList( new TreeNode(‘$’) )), new TreeNode(‘s’, Arrays.asList( new TreeNode(‘$’) )) )) )) )), new TreeNode(‘c’, Arrays.asList( new TreeNode(‘a’, Arrays.asList( new TreeNode(‘t’, Arrays.asList( new TreeNode(‘$’) )) )), new TreeNode(‘o’, Arrays.asList( new TreeNode(‘w’, Arrays.asList( new TreeNode(‘$’) )) )), new TreeNode(‘u’, Arrays.asList( new TreeNode(‘t’, Arrays.asList( new TreeNode(‘$’) )) )) )) )); }   }

Don't use plagiarized sources. Get Your Custom Essay on
Tree Transvering
This is a Snippet Preview, get a Complete Solution Here
Order Essay
Phyllis Mugure

Recent Posts

Introduction to psychology | Assignments Market

ASSIGNMENT 08 S01 Introduction to Psychology I Directions: Be sure to save an electronic copy…

3 years ago

Education | Assignments Market

Include a comprehensive, thoughtful and critical analysis to the arguments and perspectives of the readings…

3 years ago

Session 2 Discussion | Assignments Market

Discussion Prompt: Plagiarism As a writer, one of the gravest errors to make is to…

3 years ago

CJL Writing Questions | Assignments Market

Question 1: Write a Hypothetical. Write a legal memorandum analyzing what happened in the following…

3 years ago

short HW all the questions below | Assignments Market

You work at Happy Joe's family restaurant and want to see if customer meal satisfaction…

3 years ago

321 solve … | Assignments Market

The Assignment must be submitted on Blackboard (WORD format only) via allocated folder. Assignments submitted…

3 years ago