From 6f4a9ed721744e0fdcc2afa2b6406a75970fda63 Mon Sep 17 00:00:00 2001
From: Andrew Zaw <44329973+AndrewZaw@users.noreply.github.com>
Date: Thu, 20 Jun 2019 13:16:31 -0400
Subject: [PATCH] Reorganized instruction text on multiple challenges (#35912)
* Reorganized instruction text on multiple challenges
* Fixed spaces
* Fixed spaces again
* Update curriculum/challenges/english/08-coding-interview-prep/data-structures/add-elements-at-a-specific-index-in-a-linked-list.english.md
Co-Authored-By: Randell Dawson <5313213+RandellDawson@users.noreply.github.com>
* Update curriculum/challenges/english/08-coding-interview-prep/data-structures/find-the-minimum-and-maximum-height-of-a-binary-search-tree.english.md
Co-Authored-By: Randell Dawson <5313213+RandellDawson@users.noreply.github.com>
* fix: added code tags
---
...element-to-a-binary-search-tree.english.md | 168 ++++----
...specific-index-in-a-linked-list.english.md | 27 +-
.../data-structures/adjacency-list.english.md | 16 +-
.../adjacency-matrix.english.md | 19 +-
...present-in-a-binary-search-tree.english.md | 74 ++--
.../create-a-circular-queue.english.md | 7 -
.../create-a-doubly-linked-list.english.md | 2 -
.../create-a-hash-table.english.md | 36 +-
.../create-a-map-data-structure.english.md | 18 +-
.../create-a-priority-queue-class.english.md | 1 -
.../create-a-queue-class.english.md | 23 +-
.../create-a-set-class.english.md | 4 -
.../create-a-stack-class.english.md | 67 ++-
.../create-a-trie-search-tree.english.md | 13 +-
.../create-an-es6-javascript-map.english.md | 10 +-
.../create-and-add-to-sets-in-es6.english.md | 1 -
...af-node-in-a-binary-search-tree.english.md | 162 ++++----
...e-child-in-a-binary-search-tree.english.md | 156 ++++---
...hildren-in-a-binary-search-tree.english.md | 165 ++++----
...-height-of-a-binary-search-tree.english.md | 207 +++++----
...m-value-in-a-binary-search-tree.english.md | 393 +++++++++---------
...ement-heap-sort-with-a-min-heap.english.md | 12 +-
.../incidence-matrix.english.md | 1 -
...sert-an-element-into-a-max-heap.english.md | 4 -
.../invert-a-binary-tree.english.md | 2 -
.../learn-how-a-stack-works.english.md | 3 -
...-difference-on-two-sets-of-data.english.md | 4 -
...ubset-check-on-two-sets-of-data.english.md | 5 -
.../perform-a-union-on-two-sets.english.md | 5 -
...ntersection-on-two-sets-of-data.english.md | 4 -
...move-an-element-from-a-max-heap.english.md | 4 -
...nts-from-a-linked-list-by-index.english.md | 4 -
...ove-elements-from-a-linked-list.english.md | 1 -
.../remove-items-from-a-set-in-es6.english.md | 5 -
.../search-within-a-linked-list.english.md | 2 -
.../data-structures/typed-arrays.english.md | 3 -
...se-.has-and-.size-on-an-es6-set.english.md | 3 -
...-search-in-a-binary-search-tree.english.md | 73 ++--
...-search-in-a-binary-search-tree.english.md | 140 +++----
...d-notes-for-es5-set-integration.english.md | 2 -
...ork-with-nodes-in-a-linked-list.english.md | 15 +-
41 files changed, 845 insertions(+), 1016 deletions(-)
diff --git a/curriculum/challenges/english/08-coding-interview-prep/data-structures/add-a-new-element-to-a-binary-search-tree.english.md b/curriculum/challenges/english/08-coding-interview-prep/data-structures/add-a-new-element-to-a-binary-search-tree.english.md
index 9e03b049b3..46f3d4bca6 100644
--- a/curriculum/challenges/english/08-coding-interview-prep/data-structures/add-a-new-element-to-a-binary-search-tree.english.md
+++ b/curriculum/challenges/english/08-coding-interview-prep/data-structures/add-a-new-element-to-a-binary-search-tree.english.md
@@ -29,126 +29,120 @@ tests:
testString: assert((function() { var test = false; if (typeof BinarySearchTree !== 'undefined') { test = new BinarySearchTree() } else { return false; }; if (typeof test.add !== 'function') { return false; }; test.add(4); test.add(1); test.add(7); test.add(87); test.add(34); test.add(45); test.add(73); test.add(8); const expectedResult = [ 1, 4, 7, 8, 34, 45, 73, 87 ]; const result = test.inOrder(); return (expectedResult.toString() === result.toString()); })(), 'The add method adds elements according to the binary search tree rules.');
- text: Adding an element that already exists returns null
testString: assert((function() { var test = false; if (typeof BinarySearchTree !== 'undefined') { test = new BinarySearchTree() } else { return false; }; if (typeof test.add !== 'function') { return false; }; test.add(4); return test.add(4) == null; })(), 'Adding an element that already exists returns null
');
-
```
-
## Challenge Seed
addAt(index,element)
method that adds an element at a given index. Return false if an element could not be added.
+Note: Remember to check if the given index is a negative or is longer than the length of the linked list.
addAt
method should increase the length of the linked list by one for each new node added to the linked list.');
- text: Your addAt
method should return false
if a node was unable to be added.
testString: assert((function(){var test = new LinkedList(); test.add('cat'); test.add('dog'); return (test.addAt(4,'cat') === false); }()), 'Your addAt
method should return false
if a node was unable to be added.');
-
```
-
## Challenge Seed
Jill
and Jenny
.');
- text: There should be an edge between Jeff
and Jenny
.
testString: assert(undirectedAdjList.Jeff.indexOf("Jenny") !== -1 && undirectedAdjList.Jenny.indexOf("Jeff") !== -1, 'There should be an edge between Jeff
and Jenny
.');
-
```
-
## Challenge Seed
10
, 12
, 17
, 25
. Following our rules for a binary search tree, we will add 12
to the right of 10
, 17
to the right of this, and 25
to the right of this. Now our tree resembles a linked list and traversing it to find 25
would require us to traverse all the items in linear fashion. Hence, linear time in the worst case. The problem here is that the tree is unbalanced. We'll look a little more into what this means in the following challenges.
-Instructions: In this challenge, we will create a utility for our tree. Write a method isPresent
which takes an integer value as input and returns a boolean value for the presence or absence of that value in the binary search tree.
isPresent
which takes an integer value as input and returns a boolean value for the presence or absence of that value in the binary search tree.
isPresent
method correctly checks for the presence or absence of elements added to the tree.');
- text: isPresent
handles cases where the tree is empty.
testString: assert((function() { var test = false; if (typeof BinarySearchTree !== 'undefined') { test = new BinarySearchTree() } else { return false; }; if (typeof test.isPresent !== 'function') { return false; }; return test.isPresent(5) == false; })(), 'isPresent
handles cases where the tree is empty.');
-
```
-
## Challenge Seed
@@ -40,60 +37,59 @@ tests:
hash
and it will return a hashed value you can use as a key for storage. Store items based on this hashed value in the this.collection
object. Create these three methods: add
, remove
, and lookup
. The first should accept a key value pair to add to the hash table. The second should remove a key-value pair when passed a key. The third should accept a key and return the associated value or null
if the key is not present.
+Be sure to write your code to account for collisions!
Map
object provided here as a wrapper around a JavaScript object
. Create the following methods and operations on the Map object:
add
accepts a key, value
pair to add to the map.Map
object provided here as a wrapper around a JavaScript <
enqueue
method that pushes an element to the tail of the queue, a dequeue
method that removes and returns the front element, a front
method that lets us see the front element, a size
method that shows the length, and an isEmpty
method to check if the queue is empty.
size
method should return the length of the queue');
- text: The isEmpty
method should return false
if there are elements in the queue
testString: assert((function(){var test = new Queue(); test.enqueue('Smith'); return !(test.isEmpty())}()), 'The isEmpty
method should return false
if there are elements in the queue');
-
```
## Challenge Seed
+
push
and pop
method, stacks have other useful methods. Let's add a peek
, isEmpty
, and clear
method to our stack class.
-Instructions
-Write a push
method that pushes an element to the top of the stack, a pop
method that removes the element on the top of the stack, a peek
method that looks at the first element in the stack, an isEmpty
method that checks if the stack is empty, and a clear
method that removes all elements from the stack.
-Normally stacks don't have this, but we've added a print
helper method that console logs the collection.
## Instructions
push
method that pushes an element to the top of the stack, a pop
method that removes the element on the top of the stack, a peek
method that looks at the first element in the stack, an isEmpty
method that checks if the stack is empty, and a clear
method that removes all elements from the stack.
+Normally stacks don't have this, but we've added a print
helper method that console logs the collection.
isEmpty
method should return true if a stack does not contain any elements');
- text: The clear
method should remove all element from the stack
testString: assert((function(){var test = new Stack(); test.push('CS50'); test.clear(); return (test.isEmpty())}()), 'The clear
method should remove all element from the stack');
-
```
-
## Challenge Seed
add
method and store these in a trie data structure. It will also allow us to query if a given string is a word with an isWord
method, and retrieve all the words entered into the trie with a print
method. isWord
should return a boolean value and print should return an array of all these words as string values.
+In order for us to verify that this data structure is implemented correctly, we've provided a Node
structure for each node in the tree. Each node will be an object with a keys
property which is a JavaScript Map object. This will hold the individual letters that are valid keys of each node. We've also created an end
property on the nodes that can be set to true
if the node represents the termination of a word.
.clear()
removes all key, value pairs
.entries()
returns an array of all the keys in insertion order
.values()
returns an array of all the values in insertion order
-Instructions: Define a JavaScript Map object and assign to it a variable called myMap. Add the key, value pair freeCodeCamp
, Awesome!
to it.
## Instructions
freeCodeCamp
, Awesome!
to it.
freeCodeCamp
, Awesome!
.
testString: assert(myMap.get('freeCodeCamp') === 'Awesome!', 'myMap contains the key value pair freeCodeCamp
, Awesome!
.');
-
```
-
## Challenge Seed
remove
. We'll build the logic for our deletion operation in here. First, you'll want to create a function within remove that finds the node we are trying to delete in the current tree. If the node is not present in the tree, remove
should return null
. Now, if the target node is a leaf node with no children, then the parent reference to it should be set to null
. This effectively deletes the node from the tree. To do this, you will have to keep track of the parent of the node we are trying to delete as well. It will also be useful to create a way to track the number of children the target node has, as this will determine which case our deletion falls under.
-We will handle the second and third cases in the next challenges. Good luck!
remove
. We'll build the logic for our deletion operation in here. First, you'll want to create a function within remove that finds the node we are trying to delete in the current tree. If the node is not present in the tree, remove
should return null
. Now, if the target node is a leaf node with no children, then the parent reference to it should be set to null
. This effectively deletes the node from the tree. To do this, you will have to keep track of the parent of the node we are trying to delete as well. It will also be useful to create a way to track the number of children the target node has, as this will determine which case our deletion falls under.
+We will handle the second and third cases in the next challenges. Good luck!
null
.');
- text: The remove
method removes leaf nodes from the tree
testString: assert((function() { var test = false; if (typeof BinarySearchTree !== 'undefined') { test = new BinarySearchTree() } else { return false; }; if (typeof test.remove !== 'function') { return false; }; test.add(5); test.add(3); test.add(7); test.add(6); test.add(10); test.add(12); test.remove(3); test.remove(12); test.remove(10); return (test.inorder().join('') == '567'); })(), 'The remove
method removes leaf nodes from the tree');
-
```
-
remove
method that accomplishes the tasks from the last challenge. We find the target to delete and its parent and define the number of children the target node has. Let's add the next case here for target nodes with only one child. Here, we'll have to determine if the single child is a left or right branch in the tree and then set the correct reference in the parent to point to this node. In addition, let's account for the case where the target is the root node (this means the parent node will be null
). Feel free to replace all the starter code with your own as long as it passes the tests.
remove
method that accomplishes the tasks from the last challenge. We find the target to delete and its parent and define the number of children the target node has. Let's add the next case here for target nodes with only one child. Here, we'll have to determine if the single child is a left or right branch in the tree and then set the correct reference in the parent to point to this node. In addition, let's account for the case where the target is the root node (this means the parent node will be null
). Feel free to replace all the starter code with your own as long as it passes the tests.
remove
method removes nodes with one child.');
- text: Removing the root in a tree with two nodes sets the second to be the root.
testString: assert((function() { var test = false; if (typeof BinarySearchTree !== 'undefined') { test = new BinarySearchTree() } else { return false; }; if (typeof test.remove !== 'function') { return false; }; test.add(15); test.add(27); test.remove(15); return (test.inorder().join('') == '27'); })(), 'Removing the root in a tree with two nodes sets the second to be the root.');
-
```
-
## Challenge Seed
remove
method by handling the third case. We've provided some code again for the first two cases. Add some code now to handle target nodes with two children. Any edge cases to be aware of? What if the tree has only three nodes? Once you are finished this will complete our deletion operation for binary search trees. Nice job, this is a pretty hard problem!
remove
method by handling the third case. We've provided some code again for the first two cases. Add some code now to handle target nodes with two children. Any edge cases to be aware of? What if the tree has only three nodes? Once you are finished this will complete our deletion operation for binary search trees. Nice job, this is a pretty hard problem!
remove
.
testString: assert((function() { var test = false; if (typeof BinarySearchTree !== 'undefined') { test = new BinarySearchTree() } else { return false; }; return (typeof test.remove == 'function')})(), 'The binary search tree has a method called remove
.');
- text: Trying to remove an element that does not exist returns null
.
- testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() } else { return false; }; return (typeof test.remove == ''function'') ? (test.remove(100) == null) : false})(), ''Trying to remove an element that does not exist returns null
.'');'
+ testString: "assert((function() { var test = false; if (typeof BinarySearchTree !== 'undefined') { test = new BinarySearchTree() } else { return false; }; return (typeof test.remove == 'function') ? (test.remove(100) == null) : false})(), 'Trying to remove an element that does not exist returns null
.');"
- text: If the root node has no children, deleting it sets the root to null
.
- testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() } else { return false; }; test.add(500); test.remove(500); return (typeof test.remove == ''function'') ? (test.inorder() == null) : false})(), ''If the root node has no children, deleting it sets the root to null
.'');'
+ testString: "assert((function() { var test = false; if (typeof BinarySearchTree !== 'undefined') { test = new BinarySearchTree() } else { return false; }; test.add(500); test.remove(500); return (typeof test.remove == 'function') ? (test.inorder() == null) : false})(), 'If the root node has no children, deleting it sets the root to null
.');"
- text: The remove
method removes leaf nodes from the tree
- testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== ''undefined'') { test = new BinarySearchTree() } else { return false; }; test.add(5); test.add(3); test.add(7); test.add(6); test.add(10); test.add(12); test.remove(3); test.remove(12); test.remove(10); return (typeof test.remove == ''function'') ? (test.inorder().join('''') == ''567'') : false})(), ''The remove
method removes leaf nodes from the tree'');'
+ testString: "assert((function() { var test = false; if (typeof BinarySearchTree !== 'undefined') { test = new BinarySearchTree() } else { return false; }; test.add(5); test.add(3); test.add(7); test.add(6); test.add(10); test.add(12); test.remove(3); test.remove(12); test.remove(10); return (typeof test.remove == 'function') ? (test.inorder().join('') == '567') : false})(), 'The remove
method removes leaf nodes from the tree');"
- text: The remove
method removes nodes with one child.
testString: assert((function() { var test = false; if (typeof BinarySearchTree !== 'undefined') { test = new BinarySearchTree() } else { return false; }; if (typeof test.remove !== 'function') { return false; }; test.add(-1); test.add(3); test.add(7); test.add(16); test.remove(16); test.remove(7); test.remove(3); return (test.inorder().join('') == '-1'); })(), 'The remove
method removes nodes with one child.');
- text: Removing the root in a tree with two nodes sets the second to be the root.
@@ -39,18 +38,15 @@ tests:
testString: assert((function() { var test = false; if (typeof BinarySearchTree !== 'undefined') { test = new BinarySearchTree() } else { return false; }; if (typeof test.remove !== 'function') { return false; }; test.add(1); test.add(4); test.add(3); test.add(7); test.add(9); test.add(11); test.add(14); test.add(15); test.add(19); test.add(50); test.remove(9); if (!test.isBinarySearchTree()) { return false; }; test.remove(11); if (!test.isBinarySearchTree()) { return false; }; test.remove(14); if (!test.isBinarySearchTree()) { return false; }; test.remove(19); if (!test.isBinarySearchTree()) { return false; }; test.remove(3); if (!test.isBinarySearchTree()) { return false; }; test.remove(50); if (!test.isBinarySearchTree()) { return false; }; test.remove(15); if (!test.isBinarySearchTree()) { return false; }; return (test.inorder().join('') == '147'); })(), 'The remove
method removes nodes with two children while maintaining the binary search tree structure.');
- text: The root can be removed on a tree of three nodes.
testString: assert((function() { var test = false; if (typeof BinarySearchTree !== 'undefined') { test = new BinarySearchTree() } else { return false; }; if (typeof test.remove !== 'function') { return false; }; test.add(100); test.add(50); test.add(300); test.remove(100); return (test.inorder().join('') == 50300); })(), 'The root can be removed on a tree of three nodes.');
-
```
-
## Challenge Seed
findMinHeight
and findMaxHeight
. These methods should return an integer value for the minimum and maximum height within a given binary tree, respectively. If the node is empty let's assign it a height of -1
(that's the base case). Finally, add a third method isBalanced
which returns true
or false
depending on whether the tree is balanced or not. You can use the first two methods you just wrote to determine this.
+Note: A similar property to height is depth, which refers to how far a given node is from the root node.
findMinHeight
and findMaxHeight
. These methods should return an integer value for the minimum and maximum height within a given binary tree, respectively. If the node is empty let's assign it a height of -1
(that's the base case). Finally, add a third method isBalanced
which returns true
or false
depending on whether the tree is balanced or not. You can use the first two methods you just wrote to determine this.
-1
.');
- text: The isBalanced
method returns true if the tree is a balanced binary search tree.
testString: assert((function() { var test = false; if (typeof BinarySearchTree !== 'undefined') { test = new BinarySearchTree() } else { return false; }; if (typeof test.isBalanced !== 'function') { return false; }; test.add(4); test.add(1); test.add(7); test.add(87); test.add(34); test.add(45); test.add(73); test.add(8); return !test.isBalanced(); })(), 'The isBalanced
method returns true if the tree is a balanced binary search tree.');
-
```
## Challenge Seed
findMin
and findMax
. These methods should return the minimum and maximum value held in the binary search tree (don't worry about adding values to the tree for now, we have added some in the background). If you get stuck, reflect on the invariant that must be true for binary search trees: each left subtree is less than or equal to its parent and each right subtree is greater than or equal to its parent. Let's also say that our tree can only store integer values. If the tree is empty, either method should return null
.
## Instructions
findMin
and findMax
. These methods should return the minimum and maximum value held in the binary search tree (don't worry about adding values to the tree for now, we have added some in the background). If you get stuck, reflect on the invariant that must be true for binary search trees: each left subtree is less than or equal to its parent and each right subtree is greater than or equal to its parent. Let's also say that our tree can only store integer values. If the tree is empty, either method should return null
.
findMax
method returns the maximum value in the binary search tree.');
- text: The findMin
and findMax
methods return null
for an empty tree.
testString: assert((function() { var test = false; if (typeof BinarySearchTree !== 'undefined') { test = new BinarySearchTree() } else { return false; }; if (typeof test.findMin !== 'function') { return false; }; if (typeof test.findMax !== 'function') { return false; }; return (test.findMin() == null && test.findMax() == null) })(), 'The findMin
and findMax
methods return null
for an empty tree.');
-
```
@@ -48,60 +46,58 @@ tests:
MinHeap
with insert
, remove
, and sort
methods. The sort
method should return an array of all the elements in the min heap sorted from smallest to largest.
levelOrder
. This method should return an array containing the values of all the tree nodes, explored in a breadth-first manner. Be sure to return the values in the array, not the nodes themselves. A level should be traversed from left to right. Next, let's write a similar method called reverseLevelOrder
which performs the same search but in the reverse direction (right to left) at each level.
levelOrder
. This method should return an array containing the values of all the tree nodes, explored in a breadth-first manner. Be sure to return the values in the array, not the nodes themselves. A level should be traversed from left to right. Next, let's write a similar method called reverseLevelOrder
which performs the same search but in the reverse direction (right to left) at each level.
levelOrder
method returns null
for an empty tree.');
- text: The reverseLevelOrder
method returns null
for an empty tree.
testString: assert((function() { var test = false; if (typeof BinarySearchTree !== 'undefined') { test = new BinarySearchTree() } else { return false; }; if (typeof test.reverseLevelOrder !== 'function') { return false; }; return (test.reverseLevelOrder() == null); })(), 'The reverseLevelOrder
method returns null
for an empty tree.');
-
```
inorder
, preorder
, and postorder
methods on our tree. Each of these methods should return an array of items which represent the tree traversal. Be sure to return the integer values at each node in the array, not the nodes themselves. Finally, return null
if the tree is empty.
## Instructions
inorder
, preorder
, and postorder
methods on our tree. Each of these methods should return an array of items which represent the tree traversal. Be sure to return the integer values at each node in the array, not the nodes themselves. Finally, return null
if the tree is empty.
preorder
method returns null
for an empty tree.');
- text: The postorder
method returns null
for an empty tree.
testString: assert((function() { var test = false; if (typeof BinarySearchTree !== 'undefined') { test = new BinarySearchTree() } else { return false; }; if (typeof test.postorder !== 'function') { return false; }; return (test.postorder() == null); })(), 'The postorder
method returns null
for an empty tree.');
-
```
-
## Challenge Seed
@@ -56,105 +53,102 @@ tests:
Puppy
node should have a reference to a Cat
node.');
- text: Your Cat
node should have a reference to a Dog
node.
testString: assert(Cat.next.element === "Dog", 'Your Cat
node should have a reference to a Dog
node.');
-
```
@@ -36,12 +35,12 @@ tests: