The 5 attached questions need to be completed in Java. Except question 3 which is an illustration with some text. That question also references an exercise which can be found...

1 answer below »
The 5 attached questions need to be completed in Java. Except question 3 which is an illustration with some text. That question also references an exercise which can be found herehttps://opendatastructures.org/newhtml/ods/latex/scapegoat.html#tex2htm-92.
For each of the questions on the assignment, a reflection needs to be completed which should include some of the following:


  • Significant types of errors/warnings you faced when coding programs




  • Whether you were able to correct these errors/warnings quickly




  • What debugging strategy you used, e.g., searched the Web for a solution, contacted tutor, solved by self, used a debugging tool, posted in forum, talked to a friend, . . .




  • What commenting strategy you used, eg., Javadoc or inline commenting of key methods and variables, . . .




  • What testing strategy you used, eg., JUnit, tested for typical inputs, extensively tested the code, . . .




  • What code optimization techniques you followed, if any (e.g., unused local variables, parameters, and private methods; wasteful string/stringbuffer usage; unnecessary if statements and for loops that could be while loops; duplicate code; . . .




  • Resources that you referred to (online resources, book references, discussions, . . .)




  • Other comments that reflect on the process of your learning to program






Computer Science 272: Data Structures and Algorithms Page 1 of 1 Assignment 2 Answer all questions – maximum 100 marks. You must score at least 50 to pass the assignment. 1. (15 marks) Design an algorithm for the following operations for a binary tree BT, and show the worst-case running times for each implementation: preorderNext(x): return the node visited after node x in a pre-order traversal of BT. postorderNext(x): return the node visited after node x in a post-order traversal of BT. inorderNext(x): return the node visited after node x in an in-order traversal of BT. 2. (25 marks) Design a recursive linear-time algorithm that tests whether a binary tree satisfies the search tree order property at every node. 3. (20 marks) Exercise 8.2. Illustrate what happens when the sequence 1, 5, 2, 4, 3 is added to an empty ScapegoatTree, and show where the credits described in the proof of Lemma 8.3 go, and how they are used during this sequence of additions. 4. (20 marks) Implement a commonly used hash table in a program that handles collision using linear probing. Using (K mod 13) as the hash function, store the following elements in the table: {1, 5, 21, 26, 39, 14, 15, 16, 17, 18, 19, 20, 111, 145, 146}. 5. (20 marks) Exercise 6.7. Create a subclass of BinaryTree whose nodes have fields for storing preorder, post-order, and in-order numbers. Write methods preOrderNumber(), inOrderNumber(), and postOrderNumbers() that assign these numbers correctly. These methods should each run in O(n) time. Assignment 2
Answered 3 days AfterMar 22, 2021

Answer To: The 5 attached questions need to be completed in Java. Except question 3 which is an illustration...

Kshitij answered on Mar 23 2021
152 Votes
Ques 1
Node class
public class Node {
public Node rightDir;
public int value;
public Node leftDir;
public Node(int value) {
this.value = value;
this.rightDir =null;
this.leftDir =null;
}
}
Class BinarySearchTree
public class BinarySear
chTree {
public Node root;
public BinarySearchTree() {
this.root = null;
}
public void insertTheValue(int d) {
root = insertTheValue(root, d);
}
public void inorderPrinting() {
inorderPrinting(root);
}
private void inorderPrinting(Node node) {
if (node != null) {
inorderPrinting(node.leftDir);
System.out.print(node.value + " ");
inorderPrinting(node.rightDir);
}
}
private Node insertTheValue(Node newNode, int d) {
if (newNode == null) {
newNode = new Node(d);
} else {
if (d <= newNode.value) {
newNode.leftDir = insertTheValue(newNode.leftDir, d);
} else {
newNode.rightDir = insertTheValue(newNode.rightDir, d);
}
}
return newNode;
}
public void postorderPrinting() {
postorderPrinting(root);
}
private void postorderPrinting(Node node) {
if (node != null) {
postorderPrinting(node.leftDir);
postorderPrinting(node.rightDir);
System.out.print(node.value + " ");
}
}
public void preorderPrinting() {
preorderPrinting(root);
}
private void preorderPrinting(Node node) {
if (node != null) {
System.out.print(node.value + " ");
preorderPrinting(node.leftDir);
preorderPrinting(node.rightDir);
}
}
}
Main class
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
BinarySearchTree btree = new BinarySearchTree();
btree.insertTheValue(98);
btree.insertTheValue(45);
btree.insertTheValue(32);
btree.insertTheValue(65);
btree.insertTheValue(10);
btree.insertTheValue(3);
btree.insertTheValue(8);
btree.insertTheValue(7);
System.out.printf("==== Postorder traversal ===="+'\n');
btree.postorderPrinting();
System.out.println();
System.out.printf("===== Preorder traversal ===="+'\n');
btree.preorderPrinting();
System.out.println();
System.out.printf("==== Inorder traversal ===="+'\n');
btree.inorderPrinting();
}
}
Ques 2
Node class
public class Node {
Node leftDir, rightDir;
public int value;
public Node(int data) {
this.value = data;
this.leftDir = null;
this.rightDir = null;
}
}
BinarySearchClass
public class BinarySearchTree {
public Node root;...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here