Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
ff2d0ad
broken stuff
gatilogo Feb 20, 2020
554b331
traits finally work
gatilogo Feb 20, 2020
d7c8528
cleanup
gatilogo Feb 20, 2020
f14a2d0
progress
gatilogo Feb 20, 2020
c30312e
fix_insert_color alsmot done it's 3am yay
gatilogo Feb 20, 2020
cd3579d
fix tiny bug before sleep
gatilogo Feb 20, 2020
7251f43
INSERT WORKSSSSSSSSSSSSSSSSSS
gatilogo Feb 20, 2020
381ed65
print done
gatilogo Feb 20, 2020
6aa5e7e
small change + some testing
gatilogo Feb 20, 2020
22a5d3d
kinda done height
raysarinas Feb 21, 2020
b9e3e07
maybe fix height
gatilogo Feb 21, 2020
fef6da2
moved in_order_traversal to treenode
gatilogo Feb 21, 2020
243f75b
fix insert and rotate done
gatilogo Feb 21, 2020
d788317
rename
gatilogo Feb 21, 2020
2438d26
done search for nodes
raysarinas Feb 22, 2020
236ae14
start cli
gatilogo Feb 22, 2020
3aaaf7e
cleanup cli
gatilogo Feb 22, 2020
3c5cbb9
fix insert bug
gatilogo Feb 22, 2020
7e1c63e
refactor rotate i guess
gatilogo Feb 22, 2020
51b6dbb
delete sort of
raysarinas Feb 22, 2020
e98bbb5
replaced stuff with break statements
gatilogo Feb 23, 2020
4a788ea
todos and start counting leaves
raysarinas Feb 23, 2020
769b1a9
add comments
gatilogo Feb 23, 2020
e674862
done counting leaves
raysarinas Feb 24, 2020
4d4842e
delete maybe
raysarinas Feb 26, 2020
a5945ea
delete without fixing color maybe work?
raysarinas Feb 27, 2020
cbec0c5
avl node done?
jacobwong98 Feb 27, 2020
fb318fe
Merge branch 'trishia-branch' of https://github.com/raysarinas/trees …
jacobwong98 Feb 27, 2020
249259c
fix deleting root lol
raysarinas Feb 27, 2020
bb73533
done bst delete i guess
raysarinas Feb 27, 2020
5aaffec
some cleanup
gatilogo Feb 27, 2020
b58a4dc
delete?
raysarinas Feb 27, 2020
c19a7ca
Merge branch 'trishia-branch' of https://github.com/raysarinas/trees …
raysarinas Feb 27, 2020
5ad98a1
testing delete
raysarinas Feb 27, 2020
e7e5d8b
fixed bug
jacobwong98 Feb 27, 2020
19b26d7
DELETE 🤮
raysarinas Feb 27, 2020
7e3bcf7
clean up + make avl TODOs
raysarinas Feb 28, 2020
d8d41d2
BST for avl insert
raysarinas Feb 28, 2020
2aa72dd
i guess rotate might work
jacobwong98 Feb 28, 2020
03639c3
clean up comments
raysarinas Feb 28, 2020
0bdac44
Merge branch 'trishia-branch' of https://github.com/raysarinas/trees …
raysarinas Feb 28, 2020
38aac10
add rbt benchmark + contains
raysarinas Feb 28, 2020
5914dc5
stack overflow
jacobwong98 Feb 28, 2020
ce510c3
add contains and benchmark for avl
raysarinas Feb 28, 2020
1a37592
add draft of design doc
raysarinas Feb 28, 2020
c93cdf1
found problem yay
gatilogo Feb 28, 2020
db776ab
add resuable delete code to avl?
raysarinas Feb 29, 2020
d6cda0b
add benchmarks to cli
raysarinas Feb 29, 2020
ea85108
insert might be done
raysarinas Mar 1, 2020
bfa3f37
add benchmark results
raysarinas Mar 1, 2020
1dc4ec4
cleanup rbt and fix some bugs
gatilogo Mar 1, 2020
f70a208
delete should be good now
gatilogo Mar 1, 2020
08c95c5
delete maybe done and avl menu
jacobwong98 Mar 1, 2020
01dbcea
fixed height and count_leaves
gatilogo Mar 1, 2020
8db73b7
Merge branch 'trishia-branch' of https://github.com/raysarinas/trees …
gatilogo Mar 1, 2020
cf3f2f4
clean up + fix count_leaves
raysarinas Mar 1, 2020
2cc0e03
fix stack overflow i guess
raysarinas Mar 1, 2020
70ec33c
child thing
gatilogo Mar 1, 2020
b3d49c2
maybe avl delete i guess
jacobwong98 Mar 2, 2020
abb1ca4
no more overflow
raysarinas Mar 2, 2020
69a6190
remove comments
raysarinas Mar 2, 2020
76a96ec
add size and hopefully avl done
gatilogo Mar 2, 2020
25532bb
moved stuff around
gatilogo Mar 2, 2020
f59f20e
rename
gatilogo Mar 2, 2020
e14e0d9
work on design doc i guess
raysarinas Mar 2, 2020
a927312
refactor delete fix
raysarinas Mar 2, 2020
04a8653
get depth but need to refactor so not completely copying song
raysarinas Mar 2, 2020
6d5d84e
rename depth stuff
raysarinas Mar 2, 2020
10fd260
cleaned up tests
jacobwong98 Mar 2, 2020
7e5eca6
start to make general thingies
raysarinas Mar 2, 2020
ce54214
updated cli
gatilogo Mar 2, 2020
a3d27f4
Merge branch 'trishia-branch' of https://github.com/raysarinas/trees …
gatilogo Mar 2, 2020
c0bd9d2
temporarily commented out stuff for video
gatilogo Mar 2, 2020
fc664bc
done refactor i think
raysarinas Mar 2, 2020
3f148e6
clean up + add comments
raysarinas Mar 3, 2020
0bdda08
PAIN 😭
raysarinas Mar 3, 2020
4c67bb1
add lib.rs
raysarinas Mar 3, 2020
c6e1cd7
fix rbt benchmark LAG
raysarinas Mar 3, 2020
67e647b
clean up
raysarinas Mar 3, 2020
f4288f4
Merge branch 'trishia-branch' into refactor-branch
raysarinas Mar 3, 2020
c0a3f95
clean up rbt tests (commented)
raysarinas Mar 3, 2020
b4d0cce
clean up
gatilogo Mar 3, 2020
d18552e
Merge pull request #4 from raysarinas/refactor-branch
gatilogo Mar 3, 2020
dfc422f
clean benchmarks
raysarinas Mar 3, 2020
422d23c
done deepest
raysarinas Mar 3, 2020
50ff77d
for dessert, we have assert
jacobwong98 Mar 3, 2020
3c9f83c
testy vibes
raysarinas Mar 3, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 110 additions & 0 deletions design_doc_draft.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
A design document outlining:
- Major innovations – Additional to the project specification.
- A detailed rationale for your augmented decisions with regard to the above design
questions.
- A list of known errors, faults, defects, missing functionality, etc. Telling us about
your system’s limitations will score better than letting us find them! o A user manual


Design Rationale

We designed our implementation of red-black trees and AVL trees with the goal of providing a reusable crates that could be used as a means of something idk. In particular, one of the major innovations of our design involved the user traits, reusable code, and encapsulating functionality associated with smart pointers and their respective operations. [need more detail here on crate stuff, and we actually need to do the crate stuff]

>> Talk about the traits + struct stuff and impl blocks here like using traits to extend and implement commonalities between the RBT and AVL

>> Talk about the different operations here
- inserting - start with binary search insert for both
- deleting - start with binary search delete for both, but with slight modification in each binary search (talk about what's a lil different in avl vs rbt)
- leaf counting (this is the same for both)
- height of a tree (same code for both)
- in-order print traversal (same code, only difference is indicating color)
- is empty? (Same code for both, just a wrapper around root.is_none())

Our decision to have wrapper functions around operations that involved dealing with smart pointers was ..... Talk about encapsulating functionality with handling/managing smart pointers here because it made code easier to read, maintain, and cleaner. Helped with reducing the amount of repeated code that would have had to be written without. Also talk about how we handled borrows and reference counting stuff with the wrapper functions to access the different nodes of a tree/subtree.


- Talk about how we specifically chose to implement a top-down approach for insertion in both types of trees so that we could re-use code. Talk about how bottom-up approach maybe for AVL Tree insertion could improve run-time speed with regards to benchmarking.

>> Talk about command line interface - why we do it the way we have it?
- CLI only takes in numerical values - we can talk about how this decision was made for simple usage but the CLI can be extended to any type of generic value and this could include characters/strings/etc that can be partially ordered, depending on the traits said type implements.


ANSWER FOLLOWING QUESTIONS (maybe combine them with design rationale above?):
- What does a red-black tree provide that cannot be accomplished with ordinary binary
search trees?


- Do you need to apply any kind of error handling in your system (e.g., panic macro,
Option<T>, Result<T, E>, etc..)

Unless somehow erroneous data is injected into the system, for the most part error handling is not necessarily required. Incorrect or erroneous data that is normally inputted to the system will typically be rejected and would not be allowed to be used in the system, particularly when performing operations on either tree, attempts to insert erroneous data simply will not be handled and will just be rejected/prompt user to attempt to correct themselves.

- What components do the Red-black tree and AVL tree have in common? Don’t Repeat
Yourself! Never, ever repeat yourself – a fundamental idea in programming.

Many of the required components to have had been implemented were identical. The main difference between red-black tree nodes and AVL tree nodes are one field unique to either one. For red-black tree, the color of each node is kept track of, while in AVL, each node keeps track of its height with respect to its depth/distance from the root node. Other than this, both nodes maintain values, and said node's parent and left and right children. Additionally, many of operations that were implemented were simply reused for both tree types. Particularly, counting the number of leaves in a tree, checking if a tree was empty and in-order traversal were essentially identical operations. And although the insert and delete operations for both trees did differ, both implementations required a typical binary search insert and delete respectively, with only a slight modification to either tree at the end which has to do with how both trees self-balance (in red-black tree's case, the color is fixed at the end of inserting/deleting, while for AVL tree, the height of each node is recursively checked to ensure a maintained balance).

- How do we construct our design to “allow it to be efficiently and effectively extended”? For example. Could your code be reused to build a 2-3-4 tree or B tree?

We can construct our design by having the code implement functionality and/or fields that are common between various types of search trees. In the case of binary search trees, the code could be constructed and designed in such a way that the typical binary search insertion and deletion operations are generic and could be extendable such that if there a property/field in a certain type of tree that is to be maintained, that at these operations could still be called/re-used and maintaining whatever said property that is could simply be done after calling the respective binary search operation. This could also be said for the other operations binary search trees have in common (i.e. counting leaves, checking if the tree is empty, and printing via in-order traversal).

- 2-3-4 trees are essentially an alternate form of red-black trees (i.e. that is, they are equivalent data structures and there is at least 1 analogous red-black tree for every 2-3-4 tree implementation). That being said, it could be possible that our red-black tree code could very much so be re-used to implement a 2-3-4 tree though this could prove to be much more difficult (read more on wikipedia page later lol)
- B trees are unlikely to be able to use our code. Since B trees are a generalized binary search trees in that something about there being allowed to have >2 child nodes.

PART 3

RED BLACK TREE BENCHMARK RESULTS:
Elapsed time for 10000: 6 ms
Elapsed time for 40000: 31 ms
Elapsed time for 70000: 57 ms
Elapsed time for 100000: 87 ms
Elapsed time for 130000: 121 ms
==
Elapsed time for 10000: 6 ms
Elapsed time for 40000: 29 ms
Elapsed time for 70000: 58 ms
Elapsed time for 100000: 86 ms
Elapsed time for 130000: 116 ms
==
Elapsed time for 10000: 6 ms
Elapsed time for 40000: 31 ms
Elapsed time for 70000: 58 ms
Elapsed time for 100000: 88 ms
Elapsed time for 130000: 114 ms
==
Elapsed time for 10000: 6 ms
Elapsed time for 40000: 30 ms
Elapsed time for 70000: 57 ms
Elapsed time for 100000: 87 ms
Elapsed time for 130000: 113 ms

AVL TREE BENCHMARK RESULTS:
Elapsed time for 10000: 8 ms
Elapsed time for 40000: 37 ms
Elapsed time for 70000: 65 ms
Elapsed time for 100000: 101 ms
Elapsed time for 130000: 129 ms
==
Elapsed time for 10000: 7 ms
Elapsed time for 40000: 34 ms
Elapsed time for 70000: 64 ms
Elapsed time for 100000: 98 ms
Elapsed time for 130000: 140 ms
==
Elapsed time for 10000: 7 ms
Elapsed time for 40000: 34 ms
Elapsed time for 70000: 64 ms
Elapsed time for 100000: 98 ms
Elapsed time for 130000: 130 ms
==
Elapsed time for 10000: 7 ms
Elapsed time for 40000: 34 ms
Elapsed time for 70000: 64 ms
Elapsed time for 100000: 98 ms
Elapsed time for 130000: 129 ms

- AVL is probably going to be more efficient because of height rebalancing factor.
- AVL apparently not as efficient (likely to due top-bottom implementation)
- Other test cases should be accommodated including random insertions of varying numbers instead of in-order insertion. Could also consider decreasing numbers for inserting. Also consider deleting operations as a means of measuring efficiency.
- Yes probably good idea to include other data structures as a baseline. BST might be good baseline since it is essentially an RBT/AVL Tree that like doesn't balance itself or whatever we can figure out what to say later.

Loading