mirror of
https://github.com/donnemartin/interactive-coding-challenges
synced 2026-01-05 00:48:03 +00:00
Fix typos (#191)
This commit is contained in:
committed by
Donne Martin
parent
cd9e9654bc
commit
9f89a51aba
@@ -26,7 +26,7 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"* [Constraits](#Constraint)\n",
|
||||
"* [Constraints](#Constraints)\n",
|
||||
"* [Test Cases](#Test-Cases)\n",
|
||||
"* [Algorithm](#Algorithm)\n",
|
||||
"* [Code](#Code)\n",
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"* [Constraits](#Constraint)\n",
|
||||
"* [Constraints](#Constraints)\n",
|
||||
"* [Test Cases](#Test-Cases)\n",
|
||||
"* [Algorithm](#Algorithm)\n",
|
||||
"* [Code](#Code)\n",
|
||||
|
||||
@@ -75,25 +75,25 @@ class BinaryTree (object):
|
||||
parent.rightChild = current.rightChild
|
||||
|
||||
else:
|
||||
succesor = current.rightChild
|
||||
succesorParent = current
|
||||
successor = current.rightChild
|
||||
successorParent = current
|
||||
|
||||
while succesor.leftChild is not None:
|
||||
succesorParent = succesor
|
||||
succesor = succesor.leftChild
|
||||
while successor.leftChild is not None:
|
||||
successorParent = successor
|
||||
successor = successor.leftChild
|
||||
|
||||
if current is self.root:
|
||||
self.root = succesor
|
||||
self.root = successor
|
||||
elif isLeft:
|
||||
parent.leftChild = succesor
|
||||
parent.leftChild = successor
|
||||
else:
|
||||
parent.rightChild = succesor
|
||||
parent.rightChild = successor
|
||||
|
||||
succesor.leftChild = current.leftChild
|
||||
successor.leftChild = current.leftChild
|
||||
|
||||
if succesor is not current.rightChild:
|
||||
succesorParent.leftChild = succesor.rightChild
|
||||
succesor.rightChild = current.rightChild
|
||||
if successor is not current.rightChild:
|
||||
successorParent.leftChild = successor.rightChild
|
||||
successor.rightChild = current.rightChild
|
||||
|
||||
return True
|
||||
|
||||
|
||||
@@ -63,12 +63,12 @@
|
||||
"* Here are some basic [instructions](http://www.algolist.net/Data_structures/Binary_search_tree/Removal)\n",
|
||||
"* If the value to delete isn't on the tree return False\n",
|
||||
"\n",
|
||||
"### Traverals \n",
|
||||
"### Traversals \n",
|
||||
"\n",
|
||||
"* In order traversal -left, center, right\n",
|
||||
"* In order traversal - left, center, right\n",
|
||||
"* Pre order traversal - center, left, right\n",
|
||||
"* Post order traversal - left, right, center\n",
|
||||
"* Return list for all traverals \n",
|
||||
"* Return list for all traversals \n",
|
||||
"\n",
|
||||
"### Max & Min\n",
|
||||
"* Find the max node in the binary search tree\n",
|
||||
|
||||
@@ -64,12 +64,12 @@
|
||||
"* If the value to delete isn't on the tree return False\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"### Traverals \n",
|
||||
"### Traversals \n",
|
||||
"\n",
|
||||
"* In order traversal -left, center, right\n",
|
||||
"* In order traversal - left, center, right\n",
|
||||
"* Pre order traversal - center, left, right\n",
|
||||
"* Post order traversal - left, right, center\n",
|
||||
"* Return list for all traverals \n",
|
||||
"* Return list for all traversals \n",
|
||||
"\n",
|
||||
"### Max & Min\n",
|
||||
"* Find the max node in the binary search tree\n",
|
||||
@@ -152,7 +152,7 @@
|
||||
" * If node is left child\n",
|
||||
" * Find the biggest value in all the node's children and replace it with it\n",
|
||||
" * If node is right child\n",
|
||||
" * Find the smalles value in all the node's children and replace it with it\n",
|
||||
" * Find the smallest value in all the node's children and replace it with it\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"* Time complexity: O(log(n))\n",
|
||||
@@ -261,25 +261,25 @@
|
||||
"\t\t\t\tparent.rightChild = current.rightChild\n",
|
||||
"\n",
|
||||
"\t\telse:\n",
|
||||
"\t\t\tsuccesor = current.rightChild\n",
|
||||
"\t\t\tsuccesorParent = current\n",
|
||||
"\t\t\tsuccessor = current.rightChild\n",
|
||||
"\t\t\tsuccessorParent = current\n",
|
||||
"\n",
|
||||
"\t\t\twhile succesor.leftChild is not None:\n",
|
||||
"\t\t\t\tsuccesorParent = succesor\n",
|
||||
"\t\t\t\tsuccesor = succesor.leftChild\n",
|
||||
"\t\t\twhile successor.leftChild is not None:\n",
|
||||
"\t\t\t\tsuccessorParent = successor\n",
|
||||
"\t\t\t\tsuccessor = successor.leftChild\n",
|
||||
"\n",
|
||||
"\t\t\tif current is self.root:\n",
|
||||
"\t\t\t\tself.root = succesor\n",
|
||||
"\t\t\t\tself.root = successor\n",
|
||||
"\t\t\telif isLeft:\n",
|
||||
"\t\t\t\tparent.leftChild = succesor\n",
|
||||
"\t\t\t\tparent.leftChild = successor\n",
|
||||
"\t\t\telse:\n",
|
||||
"\t\t\t\tparent.rightChild = succesor\n",
|
||||
"\t\t\t\tparent.rightChild = successor\n",
|
||||
"\n",
|
||||
"\t\t\tsuccesor.leftChild = current.leftChild\n",
|
||||
"\t\t\tsuccessor.leftChild = current.leftChild\n",
|
||||
"\n",
|
||||
"\t\t\tif succesor is not current.rightChild:\n",
|
||||
"\t\t\t\tsuccesorParent.leftChild = succesor.rightChild\n",
|
||||
"\t\t\t\tsuccesor.rightChild = current.rightChild\n",
|
||||
"\t\t\tif successor is not current.rightChild:\n",
|
||||
"\t\t\t\tsuccessorParent.leftChild = successor.rightChild\n",
|
||||
"\t\t\t\tsuccessor.rightChild = current.rightChild\n",
|
||||
"\n",
|
||||
"\t\treturn True \n",
|
||||
"\n",
|
||||
|
||||
@@ -59,7 +59,7 @@
|
||||
"source": [
|
||||
"## Algorithm: Modified Selection Sort\n",
|
||||
"\n",
|
||||
"* Save the relative position of the first-occurence of each item in a list.\n",
|
||||
"* Save the relative position of the first-occurrence of each item in a list.\n",
|
||||
"* Iterate through list of unique items.\n",
|
||||
" * Keep an outer index; scan rest of list, swapping matching items with outer index and incrementing outer index each time. \n",
|
||||
" \n",
|
||||
|
||||
Reference in New Issue
Block a user