Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ SPDX-License-Identifier: CC-BY-4.0
- [`Box<T>`](smart-pointers/box.md)
- [`Rc`](smart-pointers/rc.md)
- [Owned Trait Objects](smart-pointers/trait-objects.md)
- [Exercise: Binary Tree](smart-pointers/exercise.md)
- [Exercise: Binary Search Tree](smart-pointers/exercise.md)
- [Solution](smart-pointers/solution.md)

# Day 3: Afternoon
Expand Down
14 changes: 8 additions & 6 deletions src/smart-pointers/exercise.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ Copyright 2023 Google LLC
SPDX-License-Identifier: CC-BY-4.0
-->

# Exercise: Binary Tree
# Exercise: Binary Search Tree

A binary tree is a tree-type data structure where every node has two children
(left and right). We will create a tree where each node stores a value. For a
given node N, all nodes in a N's left subtree contain smaller values, and all
nodes in N's right subtree will contain larger values. A given value should only
be stored in the tree once, i.e. no duplicate nodes.
A _binary tree_ is a tree-type data structure where each node has at most two
children (left and right). In this exercise, we will implement a _binary search
tree_, which maintains an ordering invariant: for every node, all values in its
left subtree are smaller than its value, and all values in its right subtree are
larger. The `insert` and `has` methods rely on this ordering to decide which
subtree to visit. A given value should only be stored in the tree once, i.e. no
duplicate nodes.

Implement the following types, so that the given tests pass.

Expand Down
4 changes: 2 additions & 2 deletions src/smart-pointers/exercise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use std::cmp::Ordering;

// ANCHOR: types
/// A node in the binary tree.
/// A node in the binary search tree.
#[derive(Debug)]
struct Node<T: Ord> {
value: T,
Expand All @@ -30,7 +30,7 @@ struct Node<T: Ord> {
#[derive(Debug)]
struct Subtree<T: Ord>(Option<Box<Node<T>>>);

/// A container storing a set of values, using a binary tree.
/// A container storing a set of values, using a binary search tree.
///
/// If the same value is added multiple times, it is only stored once.
#[derive(Debug)]
Expand Down
Loading