Skip to content

Commit

Permalink
Fixed typos
Browse files Browse the repository at this point in the history
  • Loading branch information
mdanilov committed Apr 7, 2024
1 parent 0fddfc0 commit 6038936
Show file tree
Hide file tree
Showing 14 changed files with 55 additions and 38 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
build
build
.DS_Store
20 changes: 19 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,25 @@
"streambuf": "cpp",
"cinttypes": "cpp",
"typeinfo": "cpp",
"stack": "cpp"
"stack": "cpp",
"__bit_reference": "cpp",
"__config": "cpp",
"__hash_table": "cpp",
"__locale": "cpp",
"__node_handle": "cpp",
"__split_buffer": "cpp",
"__threading_support": "cpp",
"__tree": "cpp",
"__verbose_abort": "cpp",
"bitset": "cpp",
"complex": "cpp",
"cstring": "cpp",
"execution": "cpp",
"ios": "cpp",
"locale": "cpp",
"mutex": "cpp",
"ratio": "cpp",
"variant": "cpp"
},
"editor.tabSize": 2
}
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
set(CMAKE_CXX_STANDARD 11)

enable_testing()
include(CTest)
include(GoogleTest)
include(PackageAddTest)

Expand Down
2 changes: 1 addition & 1 deletion src/01_arrays_and_strings/README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# Arrays and strings
# Arrays and strings
2 changes: 1 addition & 1 deletion src/02_linked_lists/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Linked Lists

1. Implemenet LinkedList class that wraps the Node class (just one member variable the head Node)
1. Implement LinkedList class that wraps the Node class (just one member variable the head Node)
will help to resolve issues with multiple references to the linked list.

2. The "runner" (or second pointer) technique is used in many linked list problems. The "fast" node
Expand Down
27 changes: 12 additions & 15 deletions src/03_stacks_and_queues/README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
# Stacks and Queues

1. A stack uses LIFO (last-in first-out) ordering. It uses the following operations:
- pop(): Remove the top item from the stack.
- push(item): Add an item to the top of the stack.
- peek(): Return the top of the stack.
- isEmpty(): Return true if and only if the stack is empty.

2. Unlike an array, a stack does not offer constant-time access to the ith item. However, it does allow constant-
time adds and removes.

3. One case where stacks are often useful is in certain recursive algorithms. A stack can also be used to implement a recursive algorithm iteratively.

- pop(): Remove the top item from the stack.
- push(item): Add an item to the top of the stack.
- peek(): Return the top of the stack.
- isEmpty(): Return true if and only if the stack is empty.
2. Unlike an array, a stack does not offer constant-time access to the ith item. However, it does
allow constant-time adds and removes.
3. One case where stacks are often useful is in certain recursive algorithms. A stack can also be used
to implement a recursive algorithm iteratively.
4. A queue implements FIFO (first-in first-out) ordering. It uses the following operations:
- add(item): Add an item to the end of the list.
- remove(): Remove the first item in the list.
- peek(): Return the top of the queue.
- isEmpty(): Return true if and only ifthe queue is empty.

- add(item): Add an item to the end of the list.
- remove(): Remove the first item in the list.
- peek(): Return the top of the queue.
- isEmpty(): Return true if and only if the queue is empty.
5. One place where queues are often used is in breadth-first search or in implementing a cache.
2 changes: 1 addition & 1 deletion src/03_stacks_and_queues/animal_shelter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// "oldest" (based on arrival time) of all animals at the shelter, or they can
// select whether they would prefer a dog or a cat (and will receive the oldest
// animal of that type). They cannot select which specific animal they would
// like. Create the data structures to maintai n this system and implement
// like. Create the data structures to maintain this system and implement
// operations such as enqueue, dequeueAny, dequeueDog, and dequeueCat. You may
// use the built-in LinkedList data structure.

Expand Down
8 changes: 4 additions & 4 deletions src/03_stacks_and_queues/three_in_one.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

// Solution #1
// ------------------------------------------------------------------------------------------------
class FixedMulitStack {
class FixedMultiStack {
public:
explicit FixedMulitStack(size_t stack_size)
explicit FixedMultiStack(size_t stack_size)
: values(stack_size * kNumberOfStacks), sizes(kNumberOfStacks) {
stack_capacity = stack_size;
}
Expand Down Expand Up @@ -111,7 +111,7 @@ class MultiStack {
throw std::runtime_error("Stack is empty");
}

/* Remove last elemen. */
/* Remove last element. */
int value = values[stack.lastElementIndex()];
values[stack.lastElementIndex()] = 0; // Clear item
stack.size--; // Shrink size
Expand Down Expand Up @@ -228,7 +228,7 @@ class MultiStack {

TEST(FreeInOneTest, Trivial) {
{
FixedMulitStack stack(3);
FixedMultiStack stack(3);

for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
Expand Down
12 changes: 6 additions & 6 deletions src/04_trees_and_graphs/check_subtree.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Check Subtree: T1 and T2 are two very large binary trees, with Tl much bigger
// than T2. Create an algorith m to determine if T2 is a subtree of Tl . A tree
// than T2. Create an algorithm m to determine if T2 is a subtree of Tl . A tree
// T2 is a subtree ofTi if there exists a node n in Ti such that the subtree of
// n is identical to T2. That is, if you cut off the tree at node n, the two
// trees would be identical. Hints: #4, #11, #18, #31, #37
Expand All @@ -14,22 +14,22 @@ using namespace utils;
// Complexity: time O(n + m), space O(n + m), where n and m are the number of
// nodes in T1 and T2, respectively.
// ------------------------------------------------------------------------------------------------
void getOrderstring(TreeNodePtr node, std::string &s) {
void getOrderString(TreeNodePtr node, std::string &s) {
if (node == nullptr) {
s.append("X"); // Add null indicator
return;
}
s.append(std::to_string(node->value)); // Add root
getOrderstring(node->left, s); // Add left
getOrderstring(node->right, s); // Add right
getOrderString(node->left, s); // Add left
getOrderString(node->right, s); // Add right
}

bool containsTree_1(TreeNodePtr t1, TreeNodePtr t2) {
std::string string1;
std::string string2;

getOrderstring(t1, string1);
getOrderstring(t2, string2);
getOrderString(t1, string1);
getOrderString(t2, string2);

return string1.find(string2) != std::string::npos;
}
Expand Down
2 changes: 1 addition & 1 deletion src/04_trees_and_graphs/minimal_tree.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Minimal Tree: Given a sorted (increasing order) array with unique integer
// elements, write an algo- rithm to create a binary search tree with minimal
// elements, write an algorithm to create a binary search tree with minimal
// height. Hints: #19, #73, #176

#include <memory>
Expand Down
2 changes: 1 addition & 1 deletion src/04_trees_and_graphs/random_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class TreeNode : public std::enable_shared_from_this<TreeNode> {
} else if (i == leftSize) {
return shared_from_this();
} else {
/* Skipping over leftSize + 1 nodes, to substract them */
/* Skipping over leftSize + 1 nodes, to subtract them */
return right->getIthNode(i - (leftSize + 1));
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/04_trees_and_graphs/successor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ TreeNodePtr leftMostChild(TreeNodePtr n) {
return n;
}

TreeNodePtr inorderSucc(TreeNodePtr n) {
TreeNodePtr inOrderSucc(TreeNodePtr n) {
if (n == nullptr) {
return nullptr;
}
Expand Down Expand Up @@ -59,7 +59,7 @@ TEST(SuccessorTest, Trivial) {
root->left->right = std::make_shared<TreeNode>(2);
root->left->right->parent = root->left;

EXPECT_EQ(root->left->right->value, inorderSucc(root->left)->value);
EXPECT_EQ(root->value, inorderSucc(root->left->right)->value);
EXPECT_EQ(nullptr, inorderSucc(root->right)); // no successor for node 4
EXPECT_EQ(root->left->right->value, inOrderSucc(root->left)->value);
EXPECT_EQ(root->value, inOrderSucc(root->left->right)->value);
EXPECT_EQ(nullptr, inOrderSucc(root->right)); // no successor for node 4
}
2 changes: 1 addition & 1 deletion src/05_bit_manipulation/insertion.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Insertion: You are given two 32-bit numbers, Nand M, and two bit positions, i
// and j. Write a method to insert Minto N such that M starts at bit j and ends
// and j. Write a method to insert M into N such that M starts at bit j and ends
// at bit i. You can assume that the bits j through i have enough space to fit
// all of M. That is, if M = 10011, you can assume that there are at least 5
// bits between j and i. You would not, for example, have j = 3 and i = 2,
Expand Down
2 changes: 1 addition & 1 deletion src/05_bit_manipulation/pairwise_swap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ int swapOddEvenBits(int x) {

#include "gtest/gtest.h"

TEST(PairwaiseSwapTest, Trivial) {
TEST(PairwiseSwapTest, Trivial) {
EXPECT_EQ(swapOddEvenBits(0b01111010001101), 0b10110101001110);
}

0 comments on commit 6038936

Please sign in to comment.