Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • cse332-22au/ex08-verifyavl-public
  • sxu4/ex08-verifyavl-public
  • cse332-22sp/ex08-verifyavl-public
  • cse332-22su/ex08-verifyavl-public
  • cse332-23wi/ex08-verifyavl-public
  • cse332-23sp/ex08-verifyavl-public
  • cse332-23su/ex08-verifyavl-public
  • cse332-23au/ex-05-verifyavl-public
  • cse332-24wi/ex-05-verifyavl-public
  • cse332-24sp/ex-05-verifyavl-public
10 results
Show changes
Commits on Source (15)
......@@ -2,57 +2,58 @@
## Setting up
Clone this repo, edit it locally, and push and upload to Gradescope, exactly as in P1. You should use Java 11 when
working on this.
Clone your student repo, edit it locally, commit and push to GitLab, and submit to Gradescope, exactly as in P1. When working on this, you should use Java 11 by changing your [Project SDK](https://www.jetbrains.com/help/idea/project-settings-and-structure.html#project-sdk) and [Project Language Level](https://www.jetbrains.com/help/idea/project-settings-and-structure.html#language-level) in the Project Structure of IntelliJ.
You should only edit `verifyavl.VerifyAVL.java` and do not change the method signature. Though, feel free to add private
methods as you see fit.
You should only edit `VerifyAVL.java` and do not change the method signature. Though, feel free to add private methods as you see fit.
## The assignment
Write Java code for an Θ(n) worst-case algorithm that verifies that a tree is actually an AVL tree
in `src/main/java/verifyavl.VerifyAVL.java`.
Write Java code for an $`\Theta(n)`$ worst-case algorithm that verifies that a tree is actually an AVL tree in `VerifyAVL.java`.
You may assume the nodes of the tree have the following definition given in `src/main/java/verifyavl/AVLNode.java`.
You may assume the nodes of the tree have the following definition given in `AVLNode.java`.
You must verify the BST Property, the AVL Balance Condition, and the correctness of the height information. If it
fails *any* of these properties, return `false`. Otherwise, return `true`.
When examining a tree, you must verify:
- the BST Property
- the AVL Balance Condition
- the correctness of the height information.
If it fails *any* of these properties, return `false`. Otherwise, return `true`.
You can assume that the keys and heights will not exceed `Integer.MAX_VALUE`.
## Grading
We will be running an autograder with **many hidden test cases** to grade your submission. You will receive points for
each test case you pass. The points will be weighted more heavily on our stress tests, so note that the majority of the
points you can get require that your code works without question.
We will be running an autograder to grade your submission. All the tests are visible, so your final grade on Gradescope will be what goes into the gradebook. The points will be weighted more heavily on our stress tests, so note that the majority of the points you can get require that your code works without question.
As a motivation for you to get this assignment 100% correct, your Verify AVL code will be used to guarantee a correct implementation for `AVLTree` in P2.
## Testing
We've given you a testing harness in `src/test/java/VerifyAVLTests.java`. It reads in `tests.json` and tests your
verifyavl.VerifyAVL method on the given tree.
We've given you a testing harness in `VerifyAVLTests.java`. It reads in `tests.json` and tests your VerifyAVL method on the given tree.
The `tests.json` file contains as many test cases as you wish to add, where each case is on a separate line with the
following format:
`{"answer": true, "tree": [5,1,[2,0,null,null], [6,0,null,null]]}`
Note that the array representation of an verifyavl.AVLNode is as follows:
Note that the array representation of an `verifyavl.AVLNode` is as follows:
`[int key, int height, [verifyavl.AVLNode left], [verifyavl.AVLNode right]]`
Note that this representation is recursive i.e. `verifyavl.AVLNode left` and `verifyavl.AVLNode right` is another `verifyavl.AVLNode`
So the example above is of a tree with a root node with key 5, a left child node with a key 2, and a right child node
with a key 6.
e.g. `[int key, int height, [int key, int height, [verifyavl.AVLNode left], [verifyavl.AVLNode right]], [int key, int height, [verifyavl.AVLNode left], [verifyavl.AVLNode right]]]`
So the example above is of a tree with a root node with key 5, a left child node with a key 2, and a right child node with a key 6.
We have provided you with 4 basic test cases:
- A correct AVL tree: `[5,1,[2,0,null,null], [6,0,null,null]]`
![Correct AVL](./img/correct.png)
- A tree that violates the BST property: `[1,1,[2,0,null,null],null]`
![Incorrect BST](./img/bst.png)
- A tree with incorrect height labels: `[2,1,[1,0,null,null],[4,1,[3,0,null,null],null]]`
![Incorrect heights](./img/height.png)
- A tree that violates the AVL balance
property: `[2,3,[1,0,null,null],[4,2,[3,0,null,null],[5,1,null,[6,0,null,null]]]]`
![Incorrect AVL](./img/avl.png)
- A tree that violates the AVL balance property: `[2,3,[1,0,null,null],[4,2,[3,0,null,null],[5,1,null,[6,0,null,null]]]]`
**Note: You should add as many test cases as you need to convince yourself that your solution works. Think about edge
cases! Your tests will not be graded, but if your code does not work, testing will help you find the problems before we
grade it.**
\ No newline at end of file
![Incorrect AVL](./img/avl.png)
......@@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>edu.washington.cs.cse332</groupId>
<artifactId>verifyavl-public-21au</artifactId>
<artifactId>verifyavl</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
......@@ -24,10 +24,8 @@
<version>1.1.1</version>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
</project>
\ No newline at end of file
</project>
package verifyavl;
/***
* Do not modify anything here.
*/
public class AVLNode {
public AVLNode left;
public AVLNode right;
public int key; // The data element stored at this node.
public int key;
public int height;
public AVLNode(int key, int height, AVLNode left, AVLNode right) {
......
......@@ -13,6 +13,10 @@ import static org.junit.Assert.*;
public class VerifyAVLTests {
/***
* Run this to test every tree in the json
*/
@Test
public void verifyAVLTest() throws IOException, ParseException {
// Parse the tests.json file as a json object
......