From 725176b5a69435ab7a4a2758e657d86d3d1ceb5d Mon Sep 17 00:00:00 2001
From: jahatehs
Date: Thu, 23 May 2024 13:45:39 -0400
Subject: [PATCH] Fixed issue #587 - Missing Matching section in cppds2,
chapter 6.
---
pretext/LinearBasic/ImplementingaStackCpp.ptx | 172 +++++++++---------
pretext/SearchHash/Matching.ptx | 30 +++
pretext/SearchHash/toctree.ptx | 1 +
3 files changed, 117 insertions(+), 86 deletions(-)
create mode 100644 pretext/SearchHash/Matching.ptx
diff --git a/pretext/LinearBasic/ImplementingaStackCpp.ptx b/pretext/LinearBasic/ImplementingaStackCpp.ptx
index f61d3bf6..dbf99966 100755
--- a/pretext/LinearBasic/ImplementingaStackCpp.ptx
+++ b/pretext/LinearBasic/ImplementingaStackCpp.ptx
@@ -9,93 +9,93 @@
type such as a stack is the creation of a new class. The stack
operations are implemented as methods. However, the STL already has a well
written implementation of the Stack class.
-
The following stack implementation () assumes that
- the end of the array will hold the top element of the stack. As the stack
- grows (as push operations occur), new items will be added on the end
- of the array. pop operations will manipulate that same end.
-
-
-
-
-
-//Tests the push, empty, size, pop, and top methods of the stack library.
-
-#include <iostream>
-#include <stack> // Calling Stack from the STL
-
-using namespace std;
-
-int main() {
- stack<int> newStack;
-
- newStack.push(3); //Adds 3 to the stack
- newStack.push(8);
- newStack.push(15);
-
- // returns a boolean response depending on if the stack is empty or not
- cout << "Stack Empty? " << newStack.empty() << endl;
-
- // returns the size of the stack itself
- cout << "Stack Size: " << newStack.size() << endl;
-
- // returns the topmost element of the stack
- cout << "Top Element of the Stack: " << newStack.top() << endl;
-
- // removes the topmost element of the stack
- newStack.pop();
-
- cout << "Top Element of the Stack: " << newStack.top() << endl;
-
- cout << "Stack Size: " << newStack.size() << endl;
-
- return 0;
-}
-
-
-
-
-
-
-#Tests the push, empty, size, pop, and top methods of the stack library.
-
-class Stack:
- def __init__(self): #initializes new stack instance
- self.items = []
-
- def isEmpty(self): #returns boolean
- return self.items == []
-
- def push(self, item): #pushes new item onto stack
- self.items.append(item)
-
- def pop(self): #removes topmost item from stack
- return self.items.pop()
-
- def top(self): #returns the topmost item from the stack
- return self.items[len(self.items)-1]
-
- def size(self): #returns the size of the stack
- return len(self.items)
-
-def main():
- newStack = Stack()
- newStack.push(4)
- newStack.push(8)
- newStack.push(15)
-
- print("Stack Empty? ", newStack.isEmpty())
-
- print("Stack Size: ", newStack.size())
-
- print("Top Element of the Stack: ", newStack.top())
-
- newStack.pop();
-
- print("Top Element of the Stack: ", newStack.top())
-main()
-
-
+
The following stack implementation ActiveCode - Stack Implementation assumes that the end of the array will hold the top element of the stack. As the stack grows (as push operations occur), new items will be added on the end of the array. pop operations will manipulate that same end. If the link is not working, please scroll down to the corresponding section manually or refer to the program ID: stack_1ac_cpp.
+
+
+
+
+
+ // Tests the push, empty, size, pop, and top methods of the stack library.
+
+ #include <iostream>
+ #include <stack> // Calling Stack from the STL
+
+ using namespace std;
+
+ int main() {
+ stack<int> newStack;
+
+ newStack.push(3); // Adds 3 to the stack
+ newStack.push(8);
+ newStack.push(15);
+
+ // Returns a boolean response depending on if the stack is empty or not
+ cout << "Stack Empty? " << newStack.empty() << endl;
+
+ // Returns the size of the stack itself
+ cout << "Stack Size: " << newStack.size() << endl;
+
+ // Returns the topmost element of the stack
+ cout << "Top Element of the Stack: " << newStack.top() << endl;
+
+ // Removes the topmost element of the stack
+ newStack.pop();
+
+ cout << "Top Element of the Stack: " << newStack.top() << endl;
+
+ cout << "Stack Size: " << newStack.size() << endl;
+
+ return 0;
+ }
+
+
+
+
+
+
+
+ # Tests the push, empty, size, pop, and top methods of the stack library.
+
+ class Stack:
+ def __init__(self): # Initializes new stack instance
+ self.items = []
+
+ def isEmpty(self): # Returns boolean
+ return self.items == []
+
+ def push(self, item): # Pushes new item onto stack
+ self.items.append(item)
+
+ def pop(self): # Removes topmost item from stack
+ return self.items.pop()
+
+ def top(self): # Returns the topmost item from the stack
+ return self.items[-1]
+
+ def size(self): # Returns the size of the stack
+ return len(self.items)
+
+ def main():
+ newStack = Stack()
+ newStack.push(4)
+ newStack.push(8)
+ newStack.push(15)
+
+ print("Stack Empty? ", newStack.isEmpty())
+
+ print("Stack Size: ", newStack.size())
+
+ print("Top Element of the Stack: ", newStack.top())
+
+ newStack.pop()
+
+ print("Top Element of the Stack: ", newStack.top())
+
+ main()
+
+
+
Reading Questions
diff --git a/pretext/SearchHash/Matching.ptx b/pretext/SearchHash/Matching.ptx
new file mode 100644
index 00000000..182b3c4b
--- /dev/null
+++ b/pretext/SearchHash/Matching.ptx
@@ -0,0 +1,30 @@
+
+ Matching
+
+
Drag the word on the left to its corresponding definition.
+
Review classes and their properties.
+
+ binary searchOne repeatedly divides a sorted data structure in half and determines if the item is in one half of it until the item is found or deemed not in the data.
+ chainingCollision resolution method, in which each slot in a hash table holds a reference to a collection of items.
+ collisionHaving two or more items sharing the same slot in a hash table.
+ collision resolutionSystematic method for solving hash table collisions.
+ clusteringItems being mapped in a hash table near each other resulting in items with collisions being put together.
+ folding methodConstructing a hash function by dividing the item into equally sized pieces, adding the pieces together to get a hash value, dividing by the size of the hash table, and the remainder becomes the slot for that item.
+ hashingCreating a value for an input that can be used to find the input by searching for the value.
+ hash functionMapping between an item and its slot in a hash table.
+ linear probingOpen addressing technique in which each slot is visited one at a time systematically.
+ load factorIt's the number of items in a hash table divided by the size of the table.
+ mapAssociate data type that stores key-data pairs.
+ mid-square methodMethod for constructing a hash function by squaring the item and then using some portion of the result.
+ open addressingCollision resolution that tries to find the next open slot/address in the hash table.
+ perfect hash functionHash function that maps each item to a unique hash slot.
+ quadratic probingVariation of linear probing in which rehashing is done using successive squared values.
+ rehashingPutting an item into a hash table after a collision.
+ searchingAlgorithmic process of finding a particular item in a collection of items.
+ sequential searchSearch method in which one follows the underlying ordering of items in a collection of data to find a specific item.
+ slotPosition in a hash table.
+
+
+
+
+
\ No newline at end of file
diff --git a/pretext/SearchHash/toctree.ptx b/pretext/SearchHash/toctree.ptx
index 49100009..0178072c 100755
--- a/pretext/SearchHash/toctree.ptx
+++ b/pretext/SearchHash/toctree.ptx
@@ -10,4 +10,5 @@
+