Skip to content

Commit 1b35849

Browse files
ClémentClément
authored andcommitted
Added project on AVL tree.
1 parent 37aa18c commit 1b35849

2 files changed

Lines changed: 71 additions & 0 deletions

File tree

source/order

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,4 @@
115115
./projects/file_displayer.md
116116
./projects/texfilehelper.md
117117
./projects/alist.md
118+
./projects/avltree.md

source/projects/avltree.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# AVL Trees
2+
3+
## Description
4+
5+
### Purpose
6+
7+
This project is designed to help you develop a better understanding of binary search trees and AVL trees.
8+
It requires you to manipulate trees in various ways, and to understand the different cases requiring re-balancing a tree.
9+
10+
### Challenge
11+
12+
#### In short
13+
14+
Our goal is improve the [second implementation of AVL tree](https://princomp.github.io/lectures/data/AVLtrees#computing-the-height-on-the-fly) and to understand it better.
15+
You will be asked to write additional methods, develop new examples, and comment your code.
16+
17+
#### In more details
18+
19+
We want to implement a more pedagogical version of AVL trees, where operations such as re-balancing are easier to observe step-by-step.
20+
21+
- [Start by downloading the existing implementation](https://princomp.github.io/code/projects/AVLTree_I.zip),
22+
- Add your name in a delimited comment at the top of `Program.cs`,
23+
- Observe how there is currently some illustration as to how `RotateleftChild` and `DoubleleftChild` operate, using the `public` methods `Rotateleft` and `Doubleleft`, when trees are unbalanced after insertion.
24+
25+
Your goal is to edit and expand the solution as follows:
26+
27+
- Inside `Program.cs`, illustrate similarly with `Rotateright` and `Doubleright` from `IBtree` how `RotaterightChild` and `DoublerightChild` operate. Create a tree by inserting values, note (in the comments) why it becomes un-balanced, and how it is possible to re-balance it using one of the aforementioned method. Create another example to illustrate the other method.
28+
- Inside `Program.cs`, create a `BSTree` tree object that is "overall" balanced, but that has sub-tree(s) with a balance greater than or equal to 2 or less than or equal to -2.
29+
- Create an "Improved" AVL tree class called `IAVLTree` that inherits from `AVLTree`, and contains a `Depth` method that computes the depth of a value: given a value of type `T`, the method should return the depth of the node containing this value, or `-1` if this value is not in the tree.
30+
[Remember](https://stackoverflow.com/questions/2603692/what-is-the-difference-between-depth-and-height-in-a-tree) that
31+
32+
> The depth of a node is the number of edges from the node to the tree's root node.
33+
34+
- Inside `Program.cs`, write a snippet of code that
35+
- Create an `IAVLTree` containing `int`s,
36+
- Insert 10 random values between 1 and 49 inside of it,
37+
- Ask the user to enter a number,
38+
- Displays the depth of the number in the tree.
39+
40+
**Pay attention to details**:
41+
42+
- Your program should catch possible exceptions.
43+
- **Do not modify any file other than `Program.cs`, do not create any file other than `IAVLTree.cs`**. If you *really* need to edit some other file, *please indicate it very clearly at the beginning of `Program.cs`.*
44+
- **Do not load any additional libraries**, in particular, **do not use C# native lists or LINQ**.
45+
46+
### Bonuses
47+
48+
Bonus points will be given if:
49+
50+
- (easy) Illustrate how
51+
- `RotaterightChild`,
52+
- `RotateleftChild`,
53+
- `DoublerightChild` or
54+
- `DoubleleftChild`
55+
56+
operate after a tree becomes unbalanced after a **deletion** (the examples above had trees unbalanced following an **insertion**).
57+
- (medium) Override the `Insert` from `AVLTree` in your `IAVLTree` class so that it uses `SubtreeBalance` (like `Delete` do). Write good test cases to make sure your method behaves as expected.
58+
59+
### Submission
60+
61+
Please, follow our [guideline on project submission](./projects/submission).
62+
In particular, make sure you write your name and the date in a delimited comment at the beginning of your file.
63+
64+
<!--
65+
## Solution
66+
67+
A possible solution is shared [in this archive](./code/projects/AList.zip).
68+
69+
Note that it does not use a "counter" to keep track of how many elements are in the list, but instead resize the array and create a new array of the appropriate size when needed: this is less efficient, since copying the array is linear in its size, but gives a more compact code.
70+
-->

0 commit comments

Comments
 (0)