diff --git a/annotated.html b/annotated.html index d86facf53..6cf25bee6 100644 --- a/annotated.html +++ b/annotated.html @@ -160,7 +160,7 @@ $(function(){initNavTree('annotated.html',''); initResizable(true); });  CSkipList  CStackClass representation of a stack  CtrieTrie implementation for small-case English alphabets a-z - Ndivide_and_conquerFor std::vector + Ndivide_and_conquerFor IO operations  Nstrassens_multiplication  CMatrixMatrix class  Ndouble_hashingAn implementation of hash table using double hashing algorithm diff --git a/d0/d2c/karatsuba__algorithm__for__fast__multiplication_8cpp__incl.map b/d0/d2c/karatsuba__algorithm__for__fast__multiplication_8cpp__incl.map index cdb53aabf..330293825 100644 --- a/d0/d2c/karatsuba__algorithm__for__fast__multiplication_8cpp__incl.map +++ b/d0/d2c/karatsuba__algorithm__for__fast__multiplication_8cpp__incl.map @@ -1,11 +1,9 @@ - + - + - + - - - + diff --git a/d0/d2c/karatsuba__algorithm__for__fast__multiplication_8cpp__incl.md5 b/d0/d2c/karatsuba__algorithm__for__fast__multiplication_8cpp__incl.md5 index 213e0e571..c3d9dac55 100644 --- a/d0/d2c/karatsuba__algorithm__for__fast__multiplication_8cpp__incl.md5 +++ b/d0/d2c/karatsuba__algorithm__for__fast__multiplication_8cpp__incl.md5 @@ -1 +1 @@ -88881fac6f8f3d3d5e858306308180ca \ No newline at end of file +0e7cb995e918479c83e5f4c704176fe9 \ No newline at end of file diff --git a/d0/d2c/karatsuba__algorithm__for__fast__multiplication_8cpp__incl.svg b/d0/d2c/karatsuba__algorithm__for__fast__multiplication_8cpp__incl.svg index 068b4f124..41daa7540 100644 --- a/d0/d2c/karatsuba__algorithm__for__fast__multiplication_8cpp__incl.svg +++ b/d0/d2c/karatsuba__algorithm__for__fast__multiplication_8cpp__incl.svg @@ -4,8 +4,8 @@ - + @@ -23,10 +23,10 @@ Node1 - -divide_and_conquer -/karatsuba_algorithm -_for_fast_multiplication.cpp + +divide_and_conquer +/karatsuba_algorithm +_for_fast_multiplication.cpp @@ -43,8 +43,8 @@ Node1->Node2 - - + + @@ -61,8 +61,8 @@ Node1->Node3 - - + + @@ -79,26 +79,8 @@ Node1->Node4 - - - - - - - -Node5 - - -vector - - - - - -Node1->Node5 - - - + + diff --git a/d0/d2c/karatsuba__algorithm__for__fast__multiplication_8cpp__incl_org.svg b/d0/d2c/karatsuba__algorithm__for__fast__multiplication_8cpp__incl_org.svg index d049c2726..702dff287 100644 --- a/d0/d2c/karatsuba__algorithm__for__fast__multiplication_8cpp__incl_org.svg +++ b/d0/d2c/karatsuba__algorithm__for__fast__multiplication_8cpp__incl_org.svg @@ -4,18 +4,18 @@ - + divide_and_conquer/karatsuba_algorithm_for_fast_multiplication.cpp Node1 - -divide_and_conquer -/karatsuba_algorithm -_for_fast_multiplication.cpp + +divide_and_conquer +/karatsuba_algorithm +_for_fast_multiplication.cpp @@ -32,8 +32,8 @@ Node1->Node2 - - + + @@ -50,8 +50,8 @@ Node1->Node3 - - + + @@ -68,26 +68,8 @@ Node1->Node4 - - - - - - - -Node5 - - -vector - - - - - -Node1->Node5 - - - + + diff --git a/d0/d3e/classdata__structures_1_1trie.html b/d0/d3e/classdata__structures_1_1trie.html index 60bc17da4..753afbe11 100644 --- a/d0/d3e/classdata__structures_1_1trie.html +++ b/d0/d3e/classdata__structures_1_1trie.html @@ -173,7 +173,7 @@ Static Private Attributes

Detailed Description

Trie implementation for small-case English alphabets a-z

-

Definition at line 25 of file trie_tree.cpp.

+

Definition at line 24 of file trie_tree.cpp.

Member Function Documentation

◆ char_to_int()

@@ -207,19 +207,19 @@ Static Private Attributes
Returns
unsigned integer index
-

Definition at line 38 of file trie_tree.cpp.

-
38 {
-
39 if (ch >= 'A' && ch <= 'Z') {
-
40 return ch - 'A';
-
41 } else if (ch >= 'a' && ch <= 'z') {
-
42 return ch - 'a' + NUM_CHARS;
-
43 }
-
44
-
45 std::cerr << "Invalid character present. Exiting...";
-
46 std::exit(EXIT_FAILURE);
-
47 return 0;
-
48 }
-
static constexpr uint8_t NUM_CHARS
Number of alphabets.
Definition trie_tree.cpp:27
+

Definition at line 37 of file trie_tree.cpp.

+
37 {
+
38 if (ch >= 'A' && ch <= 'Z') {
+
39 return ch - 'A';
+
40 } else if (ch >= 'a' && ch <= 'z') {
+
41 return ch - 'a' + NUM_CHARS;
+
42 }
+
43
+
44 std::cerr << "Invalid character present. Exiting...";
+
45 std::exit(EXIT_FAILURE);
+
46 return 0;
+
47 }
+
static constexpr uint8_t NUM_CHARS
Number of alphabets.
Definition trie_tree.cpp:26
@@ -262,48 +262,48 @@ Static Private Attributes
false if unsuccessful
-

Definition at line 134 of file trie_tree.cpp.

-
134 {
-
135 if (index == str.length()) {
-
136 if (!isEndofWord) {
-
137 return false;
-
138 }
-
139 isEndofWord = false;
-
140 // following lines - possible source of error?
-
141 // for (int i = 0; i < NUM_CHARS; i++)
-
142 // if (!arr[i])
-
143 // return false;
-
144 return true;
-
145 }
-
146 int j = char_to_int(str[index]);
-
147 if (!arr[j]) {
-
148 return false;
-
149 }
-
150 bool var = deleteString(str, index + 1);
-
151 if (var) {
-
152 arr[j].reset();
-
153 if (isEndofWord) {
-
154 return false;
-
155 } else {
-
156 int i = 0;
-
157 for (i = 0; i < NUM_CHARS; i++) {
-
158 if (arr[i]) {
-
159 return false;
-
160 }
-
161 }
-
162 return true;
-
163 }
-
164 }
-
165
-
166 /* should not return here */
-
167 std::cout << __func__ << ":" << __LINE__
-
168 << "Should not reach this line\n";
-
169 return false;
-
170 }
-
std::array< std::shared_ptr< trie >, NUM_CHARS<< 1 > arr
Recursive tree nodes as an array of shared-pointers.
Definition trie_tree.cpp:29
-
bool isEndofWord
identifier if a node is terminal node
Definition trie_tree.cpp:30
-
uint8_t char_to_int(const char &ch) const
Convert a character to integer for indexing.
Definition trie_tree.cpp:38
-
bool deleteString(const std::string &str, int index)
+

Definition at line 133 of file trie_tree.cpp.

+
133 {
+
134 if (index == str.length()) {
+
135 if (!isEndofWord) {
+
136 return false;
+
137 }
+
138 isEndofWord = false;
+
139 // following lines - possible source of error?
+
140 // for (int i = 0; i < NUM_CHARS; i++)
+
141 // if (!arr[i])
+
142 // return false;
+
143 return true;
+
144 }
+
145 int j = char_to_int(str[index]);
+
146 if (!arr[j]) {
+
147 return false;
+
148 }
+
149 bool var = deleteString(str, index + 1);
+
150 if (var) {
+
151 arr[j].reset();
+
152 if (isEndofWord) {
+
153 return false;
+
154 } else {
+
155 int i = 0;
+
156 for (i = 0; i < NUM_CHARS; i++) {
+
157 if (arr[i]) {
+
158 return false;
+
159 }
+
160 }
+
161 return true;
+
162 }
+
163 }
+
164
+
165 /* should not return here */
+
166 std::cout << __func__ << ":" << __LINE__
+
167 << "Should not reach this line\n";
+
168 return false;
+
169 }
+
std::array< std::shared_ptr< trie >, NUM_CHARS<< 1 > arr
Recursive tree nodes as an array of shared-pointers.
Definition trie_tree.cpp:28
+
bool isEndofWord
identifier if a node is terminal node
Definition trie_tree.cpp:29
+
uint8_t char_to_int(const char &ch) const
Convert a character to integer for indexing.
Definition trie_tree.cpp:37
+
bool deleteString(const std::string &str, int index)
@@ -336,30 +336,30 @@ Static Private Attributes -

Definition at line 77 of file trie_tree.cpp.

-
77 {
-
78 std::shared_ptr<trie> root(nullptr);
-
79
-
80 for (const char& ch : str) {
-
81 int j = char_to_int(ch);
-
82 if (root) {
-
83 if (root->arr[j]) {
-
84 root = root->arr[j];
-
85 } else {
-
86 std::shared_ptr<trie> temp(new trie());
-
87 root->arr[j] = temp;
-
88 root = temp;
-
89 }
-
90 } else if (arr[j]) {
-
91 root = arr[j];
-
92 } else {
-
93 std::shared_ptr<trie> temp(new trie());
-
94 arr[j] = temp;
-
95 root = temp;
-
96 }
-
97 }
-
98 root->isEndofWord = true;
-
99 }
+

Definition at line 76 of file trie_tree.cpp.

+
76 {
+
77 std::shared_ptr<trie> root(nullptr);
+
78
+
79 for (const char& ch : str) {
+
80 int j = char_to_int(ch);
+
81 if (root) {
+
82 if (root->arr[j]) {
+
83 root = root->arr[j];
+
84 } else {
+
85 std::shared_ptr<trie> temp(new trie());
+
86 root->arr[j] = temp;
+
87 root = temp;
+
88 }
+
89 } else if (arr[j]) {
+
90 root = arr[j];
+
91 } else {
+
92 std::shared_ptr<trie> temp(new trie());
+
93 arr[j] = temp;
+
94 root = temp;
+
95 }
+
96 }
+
97 root->isEndofWord = true;
+
98 }
trie()=default
Class default constructor.
@@ -406,21 +406,21 @@ Static Private Attributes
false if not found
-

Definition at line 56 of file trie_tree.cpp.

-
57 {
-
58 if (index == str.length()) {
-
59 if (!root->isEndofWord) {
-
60 return false;
-
61 }
-
62 return true;
-
63 }
-
64 int j = char_to_int(str[index]);
-
65 if (!root->arr[j]) {
-
66 return false;
-
67 }
-
68 return search(root->arr[j], str, index + 1);
-
69 }
-
bool search(const std::shared_ptr< trie > &root, const std::string &str, int index)
Definition trie_tree.cpp:56
+

Definition at line 55 of file trie_tree.cpp.

+
56 {
+
57 if (index == str.length()) {
+
58 if (!root->isEndofWord) {
+
59 return false;
+
60 }
+
61 return true;
+
62 }
+
63 int j = char_to_int(str[index]);
+
64 if (!root->arr[j]) {
+
65 return false;
+
66 }
+
67 return search(root->arr[j], str, index + 1);
+
68 }
+
bool search(const std::shared_ptr< trie > &root, const std::string &str, int index)
Definition trie_tree.cpp:55
@@ -461,20 +461,20 @@ Static Private Attributes
false if not found
-

Definition at line 107 of file trie_tree.cpp.

-
107 {
-
108 if (index == str.length()) {
-
109 if (!isEndofWord) {
-
110 return false;
-
111 }
-
112 return true;
-
113 }
-
114 int j = char_to_int(str[index]);
-
115 if (!arr[j]) {
-
116 return false;
-
117 }
-
118 return search(arr[j], str, index + 1);
-
119 }
+

Definition at line 106 of file trie_tree.cpp.

+
106 {
+
107 if (index == str.length()) {
+
108 if (!isEndofWord) {
+
109 return false;
+
110 }
+
111 return true;
+
112 }
+
113 int j = char_to_int(str[index]);
+
114 if (!arr[j]) {
+
115 return false;
+
116 }
+
117 return search(arr[j], str, index + 1);
+
118 }
@@ -501,7 +501,7 @@ Static Private Attributes

Recursive tree nodes as an array of shared-pointers.

-

Definition at line 29 of file trie_tree.cpp.

+

Definition at line 28 of file trie_tree.cpp.

@@ -527,7 +527,7 @@ Static Private Attributes

identifier if a node is terminal node

-

Definition at line 30 of file trie_tree.cpp.

+

Definition at line 29 of file trie_tree.cpp.

@@ -553,7 +553,7 @@ Static Private Attributes

Number of alphabets.

-

Definition at line 27 of file trie_tree.cpp.

+

Definition at line 26 of file trie_tree.cpp.

diff --git a/d0/dea/strassen__matrix__multiplication_8cpp_source.html b/d0/dea/strassen__matrix__multiplication_8cpp_source.html index 7158121f8..cce8a84ac 100644 --- a/d0/dea/strassen__matrix__multiplication_8cpp_source.html +++ b/d0/dea/strassen__matrix__multiplication_8cpp_source.html @@ -516,7 +516,7 @@ $(function(){initNavTree('d0/dea/strassen__matrix__multiplication_8cpp_source.ht
test
static void test()
Self-test implementations.
Definition generate_parentheses.cpp:82
main
int main()
Main function.
Definition generate_parentheses.cpp:110
operator<<
static std::ostream & operator<<(std::ostream &out, matrix< T > const &v)
Definition hill_cipher.cpp:55
-
divide_and_conquer
for std::vector
+
divide_and_conquer
for IO operations
strassens_multiplication
Namespace for performing strassen's multiplication.
diff --git a/d3/d40/graph__coloring_8cpp.html b/d3/d40/graph__coloring_8cpp.html index 3f0bf519d..5da6532dd 100644 --- a/d3/d40/graph__coloring_8cpp.html +++ b/d3/d40/graph__coloring_8cpp.html @@ -132,11 +132,10 @@ $(function(){initNavTree('d3/d40/graph__coloring_8cpp.html','../../'); initResiz More...

#include <array>
#include <iostream>
-#include <vector>
Include dependency graph for graph_coloring.cpp:
-
+

Go to the source code of this file.

@@ -225,30 +224,30 @@ template<size_t V> -

Definition at line 82 of file graph_coloring.cpp.

-
83 {
-
84 // base case:
-
85 // If all vertices are assigned a color then return true
-
86 if (v == V) {
-
87 printSolution<V>(color);
-
88 return;
-
89 }
-
90
-
91 // Consider this vertex v and try different colors
-
92 for (int c = 1; c <= m; c++) {
-
93 // Check if assignment of color c to v is fine
-
94 if (isSafe<V>(v, graph, color, c)) {
-
95 color[v] = c;
-
96
-
97 // recur to assign colors to rest of the vertices
-
98 graphColoring<V>(graph, m, color, v + 1);
-
99
-
100 // If assigning color c doesn't lead to a solution then remove it
-
101 color[v] = 0;
-
102 }
-
103 }
-
104}
-
void printSolution(const std::array< int, V > &color)
A utility function to print the solution.
+

Definition at line 81 of file graph_coloring.cpp.

+
82 {
+
83 // base case:
+
84 // If all vertices are assigned a color then return true
+
85 if (v == V) {
+
86 printSolution<V>(color);
+
87 return;
+
88 }
+
89
+
90 // Consider this vertex v and try different colors
+
91 for (int c = 1; c <= m; c++) {
+
92 // Check if assignment of color c to v is fine
+
93 if (isSafe<V>(v, graph, color, c)) {
+
94 color[v] = c;
+
95
+
96 // recur to assign colors to rest of the vertices
+
97 graphColoring<V>(graph, m, color, v + 1);
+
98
+
99 // If assigning color c doesn't lead to a solution then remove it
+
100 color[v] = 0;
+
101 }
+
102 }
+
103}
+
void printSolution(const std::array< int, V > &color)
A utility function to print the solution.
Graph Algorithms.
@@ -304,15 +303,15 @@ template<size_t V>
false if the color is not safe to be assigned to the node
-

Definition at line 62 of file graph_coloring.cpp.

-
63 {
-
64 for (int i = 0; i < V; i++) {
-
65 if (graph[v][i] && c == color[i]) {
-
66 return false;
-
67 }
-
68 }
-
69 return true;
-
70}
+

Definition at line 61 of file graph_coloring.cpp.

+
62 {
+
63 for (int i = 0; i < V; i++) {
+
64 if (graph[v][i] && c == color[i]) {
+
65 return false;
+
66 }
+
67 }
+
68 return true;
+
69}
@@ -334,27 +333,27 @@ template<size_t V>

Main function.

Returns
0 on exit
-

Definition at line 112 of file graph_coloring.cpp.

-
112 {
-
113 // Create following graph and test whether it is 3 colorable
-
114 // (3)---(2)
-
115 // | / |
-
116 // | / |
-
117 // | / |
-
118 // (0)---(1)
-
119
-
120 const int V = 4; // number of vertices in the graph
-
121 std::array<std::array<int, V>, V> graph = {
-
122 std::array<int, V>({0, 1, 1, 1}), std::array<int, V>({1, 0, 1, 0}),
-
123 std::array<int, V>({1, 1, 0, 1}), std::array<int, V>({1, 0, 1, 0})};
-
124
-
125 int m = 3; // Number of colors
-
126 std::array<int, V> color{};
-
127
-
128 backtracking::graph_coloring::graphColoring<V>(graph, m, color, 0);
-
129 return 0;
-
130}
-
void graphColoring(const std::array< std::array< int, V >, V > &graph, int m, std::array< int, V > color, int v)
Recursive utility function to solve m coloring problem.
+

Definition at line 111 of file graph_coloring.cpp.

+
111 {
+
112 // Create following graph and test whether it is 3 colorable
+
113 // (3)---(2)
+
114 // | / |
+
115 // | / |
+
116 // | / |
+
117 // (0)---(1)
+
118
+
119 const int V = 4; // number of vertices in the graph
+
120 std::array<std::array<int, V>, V> graph = {
+
121 std::array<int, V>({0, 1, 1, 1}), std::array<int, V>({1, 0, 1, 0}),
+
122 std::array<int, V>({1, 1, 0, 1}), std::array<int, V>({1, 0, 1, 0})};
+
123
+
124 int m = 3; // Number of colors
+
125 std::array<int, V> color{};
+
126
+ +
128 return 0;
+
129}
+
void graphColoring(const std::array< std::array< int, V >, V > &graph, int m, std::array< int, V > color, int v)
Recursive utility function to solve m coloring problem.
@@ -389,14 +388,14 @@ template<size_t V> -

Definition at line 42 of file graph_coloring.cpp.

-
42 {
-
43 std::cout << "Following are the assigned colors\n";
-
44 for (auto& col : color) {
-
45 std::cout << col;
-
46 }
-
47 std::cout << "\n";
-
48}
+

Definition at line 41 of file graph_coloring.cpp.

+
41 {
+
42 std::cout << "Following are the assigned colors\n";
+
43 for (auto& col : color) {
+
44 std::cout << col;
+
45 }
+
46 std::cout << "\n";
+
47}
diff --git a/d3/d40/graph__coloring_8cpp_source.html b/d3/d40/graph__coloring_8cpp_source.html index f5d25f431..ffb7d053a 100644 --- a/d3/d40/graph__coloring_8cpp_source.html +++ b/d3/d40/graph__coloring_8cpp_source.html @@ -128,88 +128,87 @@ $(function(){initNavTree('d3/d40/graph__coloring_8cpp_source.html','../../'); in
20
21#include <array>
22#include <iostream>
-
23#include <vector>
-
24
-
29namespace backtracking {
-
35namespace graph_coloring {
-
41template <size_t V>
-
-
42void printSolution(const std::array<int, V>& color) {
-
43 std::cout << "Following are the assigned colors\n";
-
44 for (auto& col : color) {
-
45 std::cout << col;
-
46 }
-
47 std::cout << "\n";
-
48}
+
23
+
28namespace backtracking {
+
34namespace graph_coloring {
+
40template <size_t V>
+
+
41void printSolution(const std::array<int, V>& color) {
+
42 std::cout << "Following are the assigned colors\n";
+
43 for (auto& col : color) {
+
44 std::cout << col;
+
45 }
+
46 std::cout << "\n";
+
47}
-
49
-
61template <size_t V>
-
-
62bool isSafe(int v, const std::array<std::array<int, V>, V>& graph,
-
63 const std::array<int, V>& color, int c) {
-
64 for (int i = 0; i < V; i++) {
-
65 if (graph[v][i] && c == color[i]) {
-
66 return false;
-
67 }
-
68 }
-
69 return true;
-
70}
+
48
+
60template <size_t V>
+
+
61bool isSafe(int v, const std::array<std::array<int, V>, V>& graph,
+
62 const std::array<int, V>& color, int c) {
+
63 for (int i = 0; i < V; i++) {
+
64 if (graph[v][i] && c == color[i]) {
+
65 return false;
+
66 }
+
67 }
+
68 return true;
+
69}
-
71
-
81template <size_t V>
-
-
82void graphColoring(const std::array<std::array<int, V>, V>& graph, int m,
-
83 std::array<int, V> color, int v) {
-
84 // base case:
-
85 // If all vertices are assigned a color then return true
-
86 if (v == V) {
-
87 printSolution<V>(color);
-
88 return;
-
89 }
-
90
-
91 // Consider this vertex v and try different colors
-
92 for (int c = 1; c <= m; c++) {
-
93 // Check if assignment of color c to v is fine
-
94 if (isSafe<V>(v, graph, color, c)) {
-
95 color[v] = c;
-
96
-
97 // recur to assign colors to rest of the vertices
-
98 graphColoring<V>(graph, m, color, v + 1);
-
99
-
100 // If assigning color c doesn't lead to a solution then remove it
-
101 color[v] = 0;
-
102 }
-
103 }
-
104}
+
70
+
80template <size_t V>
+
+
81void graphColoring(const std::array<std::array<int, V>, V>& graph, int m,
+
82 std::array<int, V> color, int v) {
+
83 // base case:
+
84 // If all vertices are assigned a color then return true
+
85 if (v == V) {
+
86 printSolution<V>(color);
+
87 return;
+
88 }
+
89
+
90 // Consider this vertex v and try different colors
+
91 for (int c = 1; c <= m; c++) {
+
92 // Check if assignment of color c to v is fine
+
93 if (isSafe<V>(v, graph, color, c)) {
+
94 color[v] = c;
+
95
+
96 // recur to assign colors to rest of the vertices
+
97 graphColoring<V>(graph, m, color, v + 1);
+
98
+
99 // If assigning color c doesn't lead to a solution then remove it
+
100 color[v] = 0;
+
101 }
+
102 }
+
103}
-
105} // namespace graph_coloring
-
106} // namespace backtracking
-
107
-
-
112int main() {
-
113 // Create following graph and test whether it is 3 colorable
-
114 // (3)---(2)
-
115 // | / |
-
116 // | / |
-
117 // | / |
-
118 // (0)---(1)
-
119
-
120 const int V = 4; // number of vertices in the graph
-
121 std::array<std::array<int, V>, V> graph = {
-
122 std::array<int, V>({0, 1, 1, 1}), std::array<int, V>({1, 0, 1, 0}),
-
123 std::array<int, V>({1, 1, 0, 1}), std::array<int, V>({1, 0, 1, 0})};
-
124
-
125 int m = 3; // Number of colors
-
126 std::array<int, V> color{};
-
127
- -
129 return 0;
-
130}
+
104} // namespace graph_coloring
+
105} // namespace backtracking
+
106
+
+
111int main() {
+
112 // Create following graph and test whether it is 3 colorable
+
113 // (3)---(2)
+
114 // | / |
+
115 // | / |
+
116 // | / |
+
117 // (0)---(1)
+
118
+
119 const int V = 4; // number of vertices in the graph
+
120 std::array<std::array<int, V>, V> graph = {
+
121 std::array<int, V>({0, 1, 1, 1}), std::array<int, V>({1, 0, 1, 0}),
+
122 std::array<int, V>({1, 1, 0, 1}), std::array<int, V>({1, 0, 1, 0})};
+
123
+
124 int m = 3; // Number of colors
+
125 std::array<int, V> color{};
+
126
+ +
128 return 0;
+
129}
-
void graphColoring(const std::array< std::array< int, V >, V > &graph, int m, std::array< int, V > color, int v)
Recursive utility function to solve m coloring problem.
-
void printSolution(const std::array< int, V > &color)
A utility function to print the solution.
-
bool isSafe(int v, const std::array< std::array< int, V >, V > &graph, const std::array< int, V > &color, int c)
Utility function to check if the current color assignment is safe for vertex v.
-
int main()
Main function.
+
void graphColoring(const std::array< std::array< int, V >, V > &graph, int m, std::array< int, V > color, int v)
Recursive utility function to solve m coloring problem.
+
void printSolution(const std::array< int, V > &color)
A utility function to print the solution.
+
bool isSafe(int v, const std::array< std::array< int, V >, V > &graph, const std::array< int, V > &color, int c)
Utility function to check if the current color assignment is safe for vertex v.
+
int main()
Main function.
for vector container
Functions for the Graph Coloring algorithm,.
Graph Algorithms.
diff --git a/d6/dec/breadth__first__search_8cpp__incl.map b/d6/dec/breadth__first__search_8cpp__incl.map index cb1159b75..6b17007a3 100644 --- a/d6/dec/breadth__first__search_8cpp__incl.map +++ b/d6/dec/breadth__first__search_8cpp__incl.map @@ -1,19 +1,17 @@ - + - + - + - + - + - + - + - - - + diff --git a/d6/dec/breadth__first__search_8cpp__incl.md5 b/d6/dec/breadth__first__search_8cpp__incl.md5 index 6df073f58..4e1b76d3f 100644 --- a/d6/dec/breadth__first__search_8cpp__incl.md5 +++ b/d6/dec/breadth__first__search_8cpp__incl.md5 @@ -1 +1 @@ -bdd0a49cd06946011c73edf0774d83de \ No newline at end of file +b6309b94241bfb1d9aa0df99347985bb \ No newline at end of file diff --git a/d6/dec/breadth__first__search_8cpp__incl.svg b/d6/dec/breadth__first__search_8cpp__incl.svg index 63f89888c..ae1ed042b 100644 --- a/d6/dec/breadth__first__search_8cpp__incl.svg +++ b/d6/dec/breadth__first__search_8cpp__incl.svg @@ -4,8 +4,8 @@ - + @@ -23,9 +23,9 @@ Node1 - -graph/breadth_first -_search.cpp + +graph/breadth_first +_search.cpp @@ -42,8 +42,8 @@ Node1->Node2 - - + + @@ -60,8 +60,8 @@ Node1->Node3 - - + + @@ -78,8 +78,8 @@ Node1->Node4 - - + + @@ -96,8 +96,8 @@ Node1->Node5 - - + + @@ -114,8 +114,8 @@ Node1->Node6 - - + + @@ -132,8 +132,8 @@ Node1->Node7 - - + + @@ -150,26 +150,8 @@ Node1->Node8 - - - - - - - -Node9 - - -vector - - - - - -Node1->Node9 - - - + + diff --git a/d6/dec/breadth__first__search_8cpp__incl_org.svg b/d6/dec/breadth__first__search_8cpp__incl_org.svg index 76cf0b30d..157d7134a 100644 --- a/d6/dec/breadth__first__search_8cpp__incl_org.svg +++ b/d6/dec/breadth__first__search_8cpp__incl_org.svg @@ -4,17 +4,17 @@ - + graph/breadth_first_search.cpp Node1 - -graph/breadth_first -_search.cpp + +graph/breadth_first +_search.cpp @@ -31,8 +31,8 @@ Node1->Node2 - - + + @@ -49,8 +49,8 @@ Node1->Node3 - - + + @@ -67,8 +67,8 @@ Node1->Node4 - - + + @@ -85,8 +85,8 @@ Node1->Node5 - - + + @@ -103,8 +103,8 @@ Node1->Node6 - - + + @@ -121,8 +121,8 @@ Node1->Node7 - - + + @@ -139,26 +139,8 @@ Node1->Node8 - - - - - - - -Node9 - - -vector - - - - - -Node1->Node9 - - - + + diff --git a/d7/d83/trie__tree_8cpp.html b/d7/d83/trie__tree_8cpp.html index e634d43f4..e790dfabe 100644 --- a/d7/d83/trie__tree_8cpp.html +++ b/d7/d83/trie__tree_8cpp.html @@ -136,11 +136,10 @@ $(function(){initNavTree('d7/d83/trie__tree_8cpp.html','../../'); initResizable( #include <iostream>
#include <memory>
#include <string>
-#include <vector>
Include dependency graph for trie_tree.cpp:
-
+

Go to the source code of this file.

@@ -194,13 +193,13 @@ Functions

Main function.

Returns
0 on exit
-

Definition at line 205 of file trie_tree.cpp.

-
205 {
-
206 test();
-
207
-
208 return 0;
-
209}
-
static void test()
Testing function.
+

Definition at line 204 of file trie_tree.cpp.

+
204 {
+
205 test();
+
206
+
207 return 0;
+
208}
+
static void test()
Testing function.
@@ -230,31 +229,31 @@ Functions

Testing function.

Returns
void
-

Definition at line 178 of file trie_tree.cpp.

-
178 {
- -
180 root.insert("Hello");
-
181 root.insert("World");
-
182
-
183 assert(!root.search("hello", 0));
-
184 std::cout << "hello - " << root.search("hello", 0) << "\n";
-
185
-
186 assert(root.search("Hello", 0));
-
187 std::cout << "Hello - " << root.search("Hello", 0) << "\n";
-
188
-
189 assert(!root.search("Word", 0));
-
190 std::cout << "Word - " << root.search("Word", 0) << "\n";
-
191
-
192 assert(root.search("World", 0));
-
193 std::cout << "World - " << root.search("World", 0) << "\n";
-
194
-
195 // Following lines of code give erroneous output
-
196 // root.deleteString("hello", 0);
-
197 // assert(!root.search("hello", 0));
-
198 // std::cout << "hello - " << root.search("world", 0) << "\n";
-
199}
-
Trie implementation for small-case English alphabets a-z
Definition trie_tree.cpp:25
-
void insert(const std::string &str)
Definition trie_tree.cpp:77
+

Definition at line 177 of file trie_tree.cpp.

+
177 {
+ +
179 root.insert("Hello");
+
180 root.insert("World");
+
181
+
182 assert(!root.search("hello", 0));
+
183 std::cout << "hello - " << root.search("hello", 0) << "\n";
+
184
+
185 assert(root.search("Hello", 0));
+
186 std::cout << "Hello - " << root.search("Hello", 0) << "\n";
+
187
+
188 assert(!root.search("Word", 0));
+
189 std::cout << "Word - " << root.search("Word", 0) << "\n";
+
190
+
191 assert(root.search("World", 0));
+
192 std::cout << "World - " << root.search("World", 0) << "\n";
+
193
+
194 // Following lines of code give erroneous output
+
195 // root.deleteString("hello", 0);
+
196 // assert(!root.search("hello", 0));
+
197 // std::cout << "hello - " << root.search("world", 0) << "\n";
+
198}
+
Trie implementation for small-case English alphabets a-z
Definition trie_tree.cpp:24
+
void insert(const std::string &str)
Definition trie_tree.cpp:76
diff --git a/d7/d83/trie__tree_8cpp_source.html b/d7/d83/trie__tree_8cpp_source.html index add8d4150..1d9349465 100644 --- a/d7/d83/trie__tree_8cpp_source.html +++ b/d7/d83/trie__tree_8cpp_source.html @@ -130,181 +130,180 @@ $(function(){initNavTree('d7/d83/trie__tree_8cpp_source.html','../../'); initRes
12#include <iostream>
13#include <memory>
14#include <string>
-
15#include <vector>
-
16
-
20namespace data_structures {
-
-
25class trie {
-
26 private:
-
27 static constexpr uint8_t NUM_CHARS = 26;
-
29 std::array<std::shared_ptr<trie>, NUM_CHARS << 1> arr;
-
30 bool isEndofWord = false;
-
31
-
-
38 uint8_t char_to_int(const char& ch) const {
-
39 if (ch >= 'A' && ch <= 'Z') {
-
40 return ch - 'A';
-
41 } else if (ch >= 'a' && ch <= 'z') {
-
42 return ch - 'a' + NUM_CHARS;
-
43 }
-
44
-
45 std::cerr << "Invalid character present. Exiting...";
-
46 std::exit(EXIT_FAILURE);
-
47 return 0;
-
48 }
+
15
+
19namespace data_structures {
+
+
24class trie {
+
25 private:
+
26 static constexpr uint8_t NUM_CHARS = 26;
+
28 std::array<std::shared_ptr<trie>, NUM_CHARS << 1> arr;
+
29 bool isEndofWord = false;
+
30
+
+
37 uint8_t char_to_int(const char& ch) const {
+
38 if (ch >= 'A' && ch <= 'Z') {
+
39 return ch - 'A';
+
40 } else if (ch >= 'a' && ch <= 'z') {
+
41 return ch - 'a' + NUM_CHARS;
+
42 }
+
43
+
44 std::cerr << "Invalid character present. Exiting...";
+
45 std::exit(EXIT_FAILURE);
+
46 return 0;
+
47 }
-
49
-
-
56 bool search(const std::shared_ptr<trie>& root, const std::string& str,
-
57 int index) {
-
58 if (index == str.length()) {
-
59 if (!root->isEndofWord) {
-
60 return false;
-
61 }
-
62 return true;
-
63 }
-
64 int j = char_to_int(str[index]);
-
65 if (!root->arr[j]) {
-
66 return false;
-
67 }
-
68 return search(root->arr[j], str, index + 1);
-
69 }
+
48
+
+
55 bool search(const std::shared_ptr<trie>& root, const std::string& str,
+
56 int index) {
+
57 if (index == str.length()) {
+
58 if (!root->isEndofWord) {
+
59 return false;
+
60 }
+
61 return true;
+
62 }
+
63 int j = char_to_int(str[index]);
+
64 if (!root->arr[j]) {
+
65 return false;
+
66 }
+
67 return search(root->arr[j], str, index + 1);
+
68 }
-
70
-
71 public:
-
72 trie() = default;
-
73
-
-
77 void insert(const std::string& str) {
-
78 std::shared_ptr<trie> root(nullptr);
-
79
-
80 for (const char& ch : str) {
-
81 int j = char_to_int(ch);
-
82 if (root) {
-
83 if (root->arr[j]) {
-
84 root = root->arr[j];
-
85 } else {
-
86 std::shared_ptr<trie> temp(new trie());
-
87 root->arr[j] = temp;
-
88 root = temp;
-
89 }
-
90 } else if (arr[j]) {
-
91 root = arr[j];
-
92 } else {
-
93 std::shared_ptr<trie> temp(new trie());
-
94 arr[j] = temp;
-
95 root = temp;
-
96 }
-
97 }
-
98 root->isEndofWord = true;
-
99 }
+
69
+
70 public:
+
71 trie() = default;
+
72
+
+
76 void insert(const std::string& str) {
+
77 std::shared_ptr<trie> root(nullptr);
+
78
+
79 for (const char& ch : str) {
+
80 int j = char_to_int(ch);
+
81 if (root) {
+
82 if (root->arr[j]) {
+
83 root = root->arr[j];
+
84 } else {
+
85 std::shared_ptr<trie> temp(new trie());
+
86 root->arr[j] = temp;
+
87 root = temp;
+
88 }
+
89 } else if (arr[j]) {
+
90 root = arr[j];
+
91 } else {
+
92 std::shared_ptr<trie> temp(new trie());
+
93 arr[j] = temp;
+
94 root = temp;
+
95 }
+
96 }
+
97 root->isEndofWord = true;
+
98 }
-
100
-
-
107 bool search(const std::string& str, int index) {
-
108 if (index == str.length()) {
-
109 if (!isEndofWord) {
-
110 return false;
-
111 }
-
112 return true;
-
113 }
-
114 int j = char_to_int(str[index]);
-
115 if (!arr[j]) {
-
116 return false;
-
117 }
-
118 return search(arr[j], str, index + 1);
-
119 }
+
99
+
+
106 bool search(const std::string& str, int index) {
+
107 if (index == str.length()) {
+
108 if (!isEndofWord) {
+
109 return false;
+
110 }
+
111 return true;
+
112 }
+
113 int j = char_to_int(str[index]);
+
114 if (!arr[j]) {
+
115 return false;
+
116 }
+
117 return search(arr[j], str, index + 1);
+
118 }
-
120
-
-
134 bool deleteString(const std::string& str, int index) {
-
135 if (index == str.length()) {
-
136 if (!isEndofWord) {
-
137 return false;
-
138 }
-
139 isEndofWord = false;
-
140 // following lines - possible source of error?
-
141 // for (int i = 0; i < NUM_CHARS; i++)
-
142 // if (!arr[i])
-
143 // return false;
-
144 return true;
-
145 }
-
146 int j = char_to_int(str[index]);
-
147 if (!arr[j]) {
-
148 return false;
-
149 }
-
150 bool var = deleteString(str, index + 1);
-
151 if (var) {
-
152 arr[j].reset();
-
153 if (isEndofWord) {
-
154 return false;
-
155 } else {
-
156 int i = 0;
-
157 for (i = 0; i < NUM_CHARS; i++) {
-
158 if (arr[i]) {
-
159 return false;
-
160 }
-
161 }
-
162 return true;
-
163 }
-
164 }
-
165
-
166 /* should not return here */
-
167 std::cout << __func__ << ":" << __LINE__
-
168 << "Should not reach this line\n";
-
169 return false;
-
170 }
+
119
+
+
133 bool deleteString(const std::string& str, int index) {
+
134 if (index == str.length()) {
+
135 if (!isEndofWord) {
+
136 return false;
+
137 }
+
138 isEndofWord = false;
+
139 // following lines - possible source of error?
+
140 // for (int i = 0; i < NUM_CHARS; i++)
+
141 // if (!arr[i])
+
142 // return false;
+
143 return true;
+
144 }
+
145 int j = char_to_int(str[index]);
+
146 if (!arr[j]) {
+
147 return false;
+
148 }
+
149 bool var = deleteString(str, index + 1);
+
150 if (var) {
+
151 arr[j].reset();
+
152 if (isEndofWord) {
+
153 return false;
+
154 } else {
+
155 int i = 0;
+
156 for (i = 0; i < NUM_CHARS; i++) {
+
157 if (arr[i]) {
+
158 return false;
+
159 }
+
160 }
+
161 return true;
+
162 }
+
163 }
+
164
+
165 /* should not return here */
+
166 std::cout << __func__ << ":" << __LINE__
+
167 << "Should not reach this line\n";
+
168 return false;
+
169 }
-
171};
+
170};
-
172} // namespace data_structures
-
173
-
-
178static void test() {
- -
180 root.insert("Hello");
-
181 root.insert("World");
-
182
-
183 assert(!root.search("hello", 0));
-
184 std::cout << "hello - " << root.search("hello", 0) << "\n";
-
185
-
186 assert(root.search("Hello", 0));
-
187 std::cout << "Hello - " << root.search("Hello", 0) << "\n";
-
188
-
189 assert(!root.search("Word", 0));
-
190 std::cout << "Word - " << root.search("Word", 0) << "\n";
-
191
-
192 assert(root.search("World", 0));
-
193 std::cout << "World - " << root.search("World", 0) << "\n";
-
194
-
195 // Following lines of code give erroneous output
-
196 // root.deleteString("hello", 0);
-
197 // assert(!root.search("hello", 0));
-
198 // std::cout << "hello - " << root.search("world", 0) << "\n";
-
199}
+
171} // namespace data_structures
+
172
+
+
177static void test() {
+ +
179 root.insert("Hello");
+
180 root.insert("World");
+
181
+
182 assert(!root.search("hello", 0));
+
183 std::cout << "hello - " << root.search("hello", 0) << "\n";
+
184
+
185 assert(root.search("Hello", 0));
+
186 std::cout << "Hello - " << root.search("Hello", 0) << "\n";
+
187
+
188 assert(!root.search("Word", 0));
+
189 std::cout << "Word - " << root.search("Word", 0) << "\n";
+
190
+
191 assert(root.search("World", 0));
+
192 std::cout << "World - " << root.search("World", 0) << "\n";
+
193
+
194 // Following lines of code give erroneous output
+
195 // root.deleteString("hello", 0);
+
196 // assert(!root.search("hello", 0));
+
197 // std::cout << "hello - " << root.search("world", 0) << "\n";
+
198}
-
200
-
-
205int main() {
-
206 test();
-
207
-
208 return 0;
-
209}
+
199
+
+
204int main() {
+
205 test();
+
206
+
207 return 0;
+
208}
-
Trie implementation for small-case English alphabets a-z
Definition trie_tree.cpp:25
-
void insert(const std::string &str)
Definition trie_tree.cpp:77
-
std::array< std::shared_ptr< trie >, NUM_CHARS<< 1 > arr
Recursive tree nodes as an array of shared-pointers.
Definition trie_tree.cpp:29
-
bool search(const std::string &str, int index)
-
static constexpr uint8_t NUM_CHARS
Number of alphabets.
Definition trie_tree.cpp:27
-
bool isEndofWord
identifier if a node is terminal node
Definition trie_tree.cpp:30
+
Trie implementation for small-case English alphabets a-z
Definition trie_tree.cpp:24
+
void insert(const std::string &str)
Definition trie_tree.cpp:76
+
std::array< std::shared_ptr< trie >, NUM_CHARS<< 1 > arr
Recursive tree nodes as an array of shared-pointers.
Definition trie_tree.cpp:28
+
bool search(const std::string &str, int index)
+
static constexpr uint8_t NUM_CHARS
Number of alphabets.
Definition trie_tree.cpp:26
+
bool isEndofWord
identifier if a node is terminal node
Definition trie_tree.cpp:29
trie()=default
Class default constructor.
-
bool search(const std::shared_ptr< trie > &root, const std::string &str, int index)
Definition trie_tree.cpp:56
-
uint8_t char_to_int(const char &ch) const
Convert a character to integer for indexing.
Definition trie_tree.cpp:38
-
bool deleteString(const std::string &str, int index)
+
bool search(const std::shared_ptr< trie > &root, const std::string &str, int index)
Definition trie_tree.cpp:55
+
uint8_t char_to_int(const char &ch) const
Convert a character to integer for indexing.
Definition trie_tree.cpp:37
+
bool deleteString(const std::string &str, int index)
for IO operations
for std::assert
-
static void test()
Testing function.
-
int main()
Main function.
+
static void test()
Testing function.
+
int main()
Main function.
diff --git a/d7/dce/graph__coloring_8cpp__incl.map b/d7/dce/graph__coloring_8cpp__incl.map index d679d068e..fd92f761d 100644 --- a/d7/dce/graph__coloring_8cpp__incl.map +++ b/d7/dce/graph__coloring_8cpp__incl.map @@ -1,9 +1,7 @@ - + - + - - - + diff --git a/d7/dce/graph__coloring_8cpp__incl.md5 b/d7/dce/graph__coloring_8cpp__incl.md5 index 02d2c76d7..859827923 100644 --- a/d7/dce/graph__coloring_8cpp__incl.md5 +++ b/d7/dce/graph__coloring_8cpp__incl.md5 @@ -1 +1 @@ -6b4447c47cb5fa9b64b269a138599c1e \ No newline at end of file +c54670a67c3cf0b4b7dd0f8523d86bcd \ No newline at end of file diff --git a/d7/dce/graph__coloring_8cpp__incl.svg b/d7/dce/graph__coloring_8cpp__incl.svg index 2884cc759..78fc9d82f 100644 --- a/d7/dce/graph__coloring_8cpp__incl.svg +++ b/d7/dce/graph__coloring_8cpp__incl.svg @@ -4,8 +4,8 @@ - + @@ -23,9 +23,9 @@ Node1 - -backtracking/graph -_coloring.cpp + +backtracking/graph +_coloring.cpp @@ -42,8 +42,8 @@ Node1->Node2 - - + + @@ -60,26 +60,8 @@ Node1->Node3 - - - - - - - -Node4 - - -vector - - - - - -Node1->Node4 - - - + + diff --git a/d7/dce/graph__coloring_8cpp__incl_org.svg b/d7/dce/graph__coloring_8cpp__incl_org.svg index 4e45987ea..b545c4655 100644 --- a/d7/dce/graph__coloring_8cpp__incl_org.svg +++ b/d7/dce/graph__coloring_8cpp__incl_org.svg @@ -4,17 +4,17 @@ - + backtracking/graph_coloring.cpp Node1 - -backtracking/graph -_coloring.cpp + +backtracking/graph +_coloring.cpp @@ -31,8 +31,8 @@ Node1->Node2 - - + + @@ -49,26 +49,8 @@ Node1->Node3 - - - - - - - -Node4 - - -vector - - - - - -Node1->Node4 - - - + + diff --git a/da/dd3/karatsuba__algorithm__for__fast__multiplication_8cpp.html b/da/dd3/karatsuba__algorithm__for__fast__multiplication_8cpp.html index d48601fa0..f4706df3f 100644 --- a/da/dd3/karatsuba__algorithm__for__fast__multiplication_8cpp.html +++ b/da/dd3/karatsuba__algorithm__for__fast__multiplication_8cpp.html @@ -133,11 +133,10 @@ $(function(){initNavTree('da/dd3/karatsuba__algorithm__for__fast__multiplication
#include <cassert>
#include <cstring>
#include <iostream>
-#include <vector>
Include dependency graph for karatsuba_algorithm_for_fast_multiplication.cpp:
-
+

Go to the source code of this file.

@@ -145,7 +144,7 @@ Include dependency graph for karatsuba_algorithm_for_fast_multiplication.cpp:

Namespaces

namespace  divide_and_conquer - for std::vector
+ for IO operations
  namespace  karatsuba_algorithm  Functions for the Karatsuba algorithm for fast multiplication implementation.
@@ -206,46 +205,46 @@ Functions
Returns
the sum binary string
-

Definition at line 37 of file karatsuba_algorithm_for_fast_multiplication.cpp.

-
37 {
-
38 std::string result; // to store the resulting sum bits
-
39
-
40 // make the string lengths equal
-
41 int64_t len1 = first.size();
-
42 int64_t len2 = second.size();
-
43 std::string zero = "0";
-
44 if (len1 < len2) {
-
45 for (int64_t i = 0; i < len2 - len1; i++) {
-
46 zero += first;
-
47 first = zero;
-
48 zero = "0"; // Prevents CI from failing
-
49 }
-
50 } else if (len1 > len2) {
-
51 for (int64_t i = 0; i < len1 - len2; i++) {
-
52 zero += second;
-
53 second = zero;
-
54 zero = "0"; // Prevents CI from failing
-
55 }
-
56 }
-
57
-
58 int64_t length = std::max(len1, len2);
-
59 int64_t carry = 0;
-
60 for (int64_t i = length - 1; i >= 0; i--) {
-
61 int64_t firstBit = first.at(i) - '0';
-
62 int64_t secondBit = second.at(i) - '0';
-
63
-
64 int64_t sum = (char(firstBit ^ secondBit ^ carry)) + '0'; // sum of 3 bits
-
65 result.insert(result.begin(), sum);
-
66
-
67 carry = char((firstBit & secondBit) | (secondBit & carry) |
-
68 (firstBit & carry)); // sum of 3 bits
-
69 }
-
70
-
71 if (carry) {
-
72 result.insert(result.begin(), '1'); // adding 1 incase of overflow
-
73 }
-
74 return result;
-
75}
+

Definition at line 36 of file karatsuba_algorithm_for_fast_multiplication.cpp.

+
36 {
+
37 std::string result; // to store the resulting sum bits
+
38
+
39 // make the string lengths equal
+
40 int64_t len1 = first.size();
+
41 int64_t len2 = second.size();
+
42 std::string zero = "0";
+
43 if (len1 < len2) {
+
44 for (int64_t i = 0; i < len2 - len1; i++) {
+
45 zero += first;
+
46 first = zero;
+
47 zero = "0"; // Prevents CI from failing
+
48 }
+
49 } else if (len1 > len2) {
+
50 for (int64_t i = 0; i < len1 - len2; i++) {
+
51 zero += second;
+
52 second = zero;
+
53 zero = "0"; // Prevents CI from failing
+
54 }
+
55 }
+
56
+
57 int64_t length = std::max(len1, len2);
+
58 int64_t carry = 0;
+
59 for (int64_t i = length - 1; i >= 0; i--) {
+
60 int64_t firstBit = first.at(i) - '0';
+
61 int64_t secondBit = second.at(i) - '0';
+
62
+
63 int64_t sum = (char(firstBit ^ secondBit ^ carry)) + '0'; // sum of 3 bits
+
64 result.insert(result.begin(), sum);
+
65
+
66 carry = char((firstBit & secondBit) | (secondBit & carry) |
+
67 (firstBit & carry)); // sum of 3 bits
+
68 }
+
69
+
70 if (carry) {
+
71 result.insert(result.begin(), '1'); // adding 1 incase of overflow
+
72 }
+
73 return result;
+
74}
uint64_t result(uint64_t n)
T sum(const std::vector< std::valarray< T > > &A)
@@ -280,41 +279,41 @@ Functions
Returns
the product number value
-

Definition at line 112 of file karatsuba_algorithm_for_fast_multiplication.cpp.

-
112 {
-
113 int64_t len1 = str1.size();
-
114 int64_t len2 = str2.size();
-
115 int64_t n = std::max(len1, len2);
-
116
-
117 if (n == 0) {
-
118 return 0;
-
119 }
-
120 if (n == 1) {
-
121 return (str1[0] - '0') * (str2[0] - '0');
-
122 }
-
123
-
124 int64_t fh = n / 2; // first half of string
-
125 int64_t sh = n - fh; // second half of string
-
126
-
127 std::string Xl = divide_and_conquer::karatsuba_algorithm::safe_substr(str1, 0, fh, n); // first half of first string
-
128 std::string Xr = divide_and_conquer::karatsuba_algorithm::safe_substr(str1, fh, sh, n); // second half of first string
-
129
-
130 std::string Yl = divide_and_conquer::karatsuba_algorithm::safe_substr(str2, 0, fh, n); // first half of second string
-
131 std::string Yr = divide_and_conquer::karatsuba_algorithm::safe_substr(str2, fh, sh, n); // second half of second string
-
132
-
133 // calculating the three products of inputs of size n/2 recursively
-
134 int64_t product1 = karatsuba_algorithm(Xl, Yl);
-
135 int64_t product2 = karatsuba_algorithm(Xr, Yr);
-
136 int64_t product3 = karatsuba_algorithm(
- - -
139
-
140 return product1 * (1 << (2 * sh)) +
-
141 (product3 - product1 - product2) * (1 << sh) +
-
142 product2; // combining the three products to get the final result.
-
143}
-
std::string safe_substr(const std::string &str, int64_t x1, int64_t x2, int64_t n)
Wrapper function for substr that considers leading zeros.
-
std::string add_strings(std::string first, std::string second)
Binary addition.
+

Definition at line 111 of file karatsuba_algorithm_for_fast_multiplication.cpp.

+
111 {
+
112 int64_t len1 = str1.size();
+
113 int64_t len2 = str2.size();
+
114 int64_t n = std::max(len1, len2);
+
115
+
116 if (n == 0) {
+
117 return 0;
+
118 }
+
119 if (n == 1) {
+
120 return (str1[0] - '0') * (str2[0] - '0');
+
121 }
+
122
+
123 int64_t fh = n / 2; // first half of string
+
124 int64_t sh = n - fh; // second half of string
+
125
+
126 std::string Xl = divide_and_conquer::karatsuba_algorithm::safe_substr(str1, 0, fh, n); // first half of first string
+
127 std::string Xr = divide_and_conquer::karatsuba_algorithm::safe_substr(str1, fh, sh, n); // second half of first string
+
128
+
129 std::string Yl = divide_and_conquer::karatsuba_algorithm::safe_substr(str2, 0, fh, n); // first half of second string
+
130 std::string Yr = divide_and_conquer::karatsuba_algorithm::safe_substr(str2, fh, sh, n); // second half of second string
+
131
+
132 // calculating the three products of inputs of size n/2 recursively
+
133 int64_t product1 = karatsuba_algorithm(Xl, Yl);
+
134 int64_t product2 = karatsuba_algorithm(Xr, Yr);
+
135 int64_t product3 = karatsuba_algorithm(
+ + +
138
+
139 return product1 * (1 << (2 * sh)) +
+
140 (product3 - product1 - product2) * (1 << sh) +
+
141 product2; // combining the three products to get the final result.
+
142}
+
std::string safe_substr(const std::string &str, int64_t x1, int64_t x2, int64_t n)
Wrapper function for substr that considers leading zeros.
+
std::string add_strings(std::string first, std::string second)
Binary addition.
Functions for the Karatsuba algorithm for fast multiplication implementation.
@@ -337,12 +336,12 @@ Functions

Main function.

Returns
0 on exit
-

Definition at line 181 of file karatsuba_algorithm_for_fast_multiplication.cpp.

-
181 {
-
182 test(); // run self-test implementations
-
183 return 0;
-
184}
-
static void test()
Self-test implementations.
+

Definition at line 180 of file karatsuba_algorithm_for_fast_multiplication.cpp.

+
180 {
+
181 test(); // run self-test implementations
+
182 return 0;
+
183}
+
static void test()
Self-test implementations.
@@ -389,25 +388,25 @@ Functions
"0" if substring spans to leading zeros only
-

Definition at line 86 of file karatsuba_algorithm_for_fast_multiplication.cpp.

-
86 {
-
87 int64_t len = str.size();
-
88
-
89 if (len >= n) {
-
90 return str.substr(x1, x2);
-
91 }
-
92
-
93 int64_t y1 = x1 - (n - len); // index in str of first char of substring of "whole" string
-
94 int64_t y2 = (x1 + x2 - 1) - (n - len); // index in str of last char of substring of "whole" string
-
95
-
96 if (y2 < 0) {
-
97 return "0";
-
98 } else if (y1 < 0) {
-
99 return str.substr(0, y2 + 1);
-
100 } else {
-
101 return str.substr(y1, x2);
-
102 }
-
103}
+

Definition at line 85 of file karatsuba_algorithm_for_fast_multiplication.cpp.

+
85 {
+
86 int64_t len = str.size();
+
87
+
88 if (len >= n) {
+
89 return str.substr(x1, x2);
+
90 }
+
91
+
92 int64_t y1 = x1 - (n - len); // index in str of first char of substring of "whole" string
+
93 int64_t y2 = (x1 + x2 - 1) - (n - len); // index in str of last char of substring of "whole" string
+
94
+
95 if (y2 < 0) {
+
96 return "0";
+
97 } else if (y1 < 0) {
+
98 return str.substr(0, y2 + 1);
+
99 } else {
+
100 return str.substr(y1, x2);
+
101 }
+
102}
@@ -437,33 +436,33 @@ Functions

Self-test implementations.

Returns
void
-

Definition at line 151 of file karatsuba_algorithm_for_fast_multiplication.cpp.

-
151 {
-
152 // 1st test
-
153 std::string s11 = "1"; // 1
-
154 std::string s12 = "1010"; // 10
-
155 std::cout << "1st test... ";
- -
157 s11, s12) == 10);
-
158 std::cout << "passed" << std::endl;
-
159
-
160 // 2nd test
-
161 std::string s21 = "11"; // 3
-
162 std::string s22 = "1010"; // 10
-
163 std::cout << "2nd test... ";
- -
165 s21, s22) == 30);
-
166 std::cout << "passed" << std::endl;
-
167
-
168 // 3rd test
-
169 std::string s31 = "110"; // 6
-
170 std::string s32 = "1010"; // 10
-
171 std::cout << "3rd test... ";
- -
173 s31, s32) == 60);
-
174 std::cout << "passed" << std::endl;
-
175}
-
int64_t karatsuba_algorithm(std::string str1, std::string str2)
The main function implements Karatsuba's algorithm for fast multiplication.
+

Definition at line 150 of file karatsuba_algorithm_for_fast_multiplication.cpp.

+
150 {
+
151 // 1st test
+
152 std::string s11 = "1"; // 1
+
153 std::string s12 = "1010"; // 10
+
154 std::cout << "1st test... ";
+ +
156 s11, s12) == 10);
+
157 std::cout << "passed" << std::endl;
+
158
+
159 // 2nd test
+
160 std::string s21 = "11"; // 3
+
161 std::string s22 = "1010"; // 10
+
162 std::cout << "2nd test... ";
+ +
164 s21, s22) == 30);
+
165 std::cout << "passed" << std::endl;
+
166
+
167 // 3rd test
+
168 std::string s31 = "110"; // 6
+
169 std::string s32 = "1010"; // 10
+
170 std::cout << "3rd test... ";
+ +
172 s31, s32) == 60);
+
173 std::cout << "passed" << std::endl;
+
174}
+
int64_t karatsuba_algorithm(std::string str1, std::string str2)
The main function implements Karatsuba's algorithm for fast multiplication.
diff --git a/da/dd3/karatsuba__algorithm__for__fast__multiplication_8cpp_source.html b/da/dd3/karatsuba__algorithm__for__fast__multiplication_8cpp_source.html index b287991d4..c59bd6656 100644 --- a/da/dd3/karatsuba__algorithm__for__fast__multiplication_8cpp_source.html +++ b/da/dd3/karatsuba__algorithm__for__fast__multiplication_8cpp_source.html @@ -129,150 +129,149 @@ $(function(){initNavTree('da/dd3/karatsuba__algorithm__for__fast__multiplication
15#include <cassert>
16#include <cstring>
17#include <iostream>
-
18#include <vector>
-
19
-
24namespace divide_and_conquer {
-
30namespace karatsuba_algorithm {
-
-
37std::string add_strings(std::string first, std::string second) {
-
38 std::string result; // to store the resulting sum bits
-
39
-
40 // make the string lengths equal
-
41 int64_t len1 = first.size();
-
42 int64_t len2 = second.size();
-
43 std::string zero = "0";
-
44 if (len1 < len2) {
-
45 for (int64_t i = 0; i < len2 - len1; i++) {
-
46 zero += first;
-
47 first = zero;
-
48 zero = "0"; // Prevents CI from failing
-
49 }
-
50 } else if (len1 > len2) {
-
51 for (int64_t i = 0; i < len1 - len2; i++) {
-
52 zero += second;
-
53 second = zero;
-
54 zero = "0"; // Prevents CI from failing
-
55 }
-
56 }
-
57
-
58 int64_t length = std::max(len1, len2);
-
59 int64_t carry = 0;
-
60 for (int64_t i = length - 1; i >= 0; i--) {
-
61 int64_t firstBit = first.at(i) - '0';
-
62 int64_t secondBit = second.at(i) - '0';
-
63
-
64 int64_t sum = (char(firstBit ^ secondBit ^ carry)) + '0'; // sum of 3 bits
-
65 result.insert(result.begin(), sum);
-
66
-
67 carry = char((firstBit & secondBit) | (secondBit & carry) |
-
68 (firstBit & carry)); // sum of 3 bits
-
69 }
-
70
-
71 if (carry) {
-
72 result.insert(result.begin(), '1'); // adding 1 incase of overflow
-
73 }
-
74 return result;
-
75}
+
18
+
23namespace divide_and_conquer {
+
29namespace karatsuba_algorithm {
+
+
36std::string add_strings(std::string first, std::string second) {
+
37 std::string result; // to store the resulting sum bits
+
38
+
39 // make the string lengths equal
+
40 int64_t len1 = first.size();
+
41 int64_t len2 = second.size();
+
42 std::string zero = "0";
+
43 if (len1 < len2) {
+
44 for (int64_t i = 0; i < len2 - len1; i++) {
+
45 zero += first;
+
46 first = zero;
+
47 zero = "0"; // Prevents CI from failing
+
48 }
+
49 } else if (len1 > len2) {
+
50 for (int64_t i = 0; i < len1 - len2; i++) {
+
51 zero += second;
+
52 second = zero;
+
53 zero = "0"; // Prevents CI from failing
+
54 }
+
55 }
+
56
+
57 int64_t length = std::max(len1, len2);
+
58 int64_t carry = 0;
+
59 for (int64_t i = length - 1; i >= 0; i--) {
+
60 int64_t firstBit = first.at(i) - '0';
+
61 int64_t secondBit = second.at(i) - '0';
+
62
+
63 int64_t sum = (char(firstBit ^ secondBit ^ carry)) + '0'; // sum of 3 bits
+
64 result.insert(result.begin(), sum);
+
65
+
66 carry = char((firstBit & secondBit) | (secondBit & carry) |
+
67 (firstBit & carry)); // sum of 3 bits
+
68 }
+
69
+
70 if (carry) {
+
71 result.insert(result.begin(), '1'); // adding 1 incase of overflow
+
72 }
+
73 return result;
+
74}
-
76
-
-
86std::string safe_substr(const std::string &str, int64_t x1, int64_t x2, int64_t n) {
-
87 int64_t len = str.size();
-
88
-
89 if (len >= n) {
-
90 return str.substr(x1, x2);
-
91 }
-
92
-
93 int64_t y1 = x1 - (n - len); // index in str of first char of substring of "whole" string
-
94 int64_t y2 = (x1 + x2 - 1) - (n - len); // index in str of last char of substring of "whole" string
-
95
-
96 if (y2 < 0) {
-
97 return "0";
-
98 } else if (y1 < 0) {
-
99 return str.substr(0, y2 + 1);
-
100 } else {
-
101 return str.substr(y1, x2);
-
102 }
-
103}
+
75
+
+
85std::string safe_substr(const std::string &str, int64_t x1, int64_t x2, int64_t n) {
+
86 int64_t len = str.size();
+
87
+
88 if (len >= n) {
+
89 return str.substr(x1, x2);
+
90 }
+
91
+
92 int64_t y1 = x1 - (n - len); // index in str of first char of substring of "whole" string
+
93 int64_t y2 = (x1 + x2 - 1) - (n - len); // index in str of last char of substring of "whole" string
+
94
+
95 if (y2 < 0) {
+
96 return "0";
+
97 } else if (y1 < 0) {
+
98 return str.substr(0, y2 + 1);
+
99 } else {
+
100 return str.substr(y1, x2);
+
101 }
+
102}
-
104
-
-
112int64_t karatsuba_algorithm(std::string str1, std::string str2) {
-
113 int64_t len1 = str1.size();
-
114 int64_t len2 = str2.size();
-
115 int64_t n = std::max(len1, len2);
-
116
-
117 if (n == 0) {
-
118 return 0;
-
119 }
-
120 if (n == 1) {
-
121 return (str1[0] - '0') * (str2[0] - '0');
-
122 }
-
123
-
124 int64_t fh = n / 2; // first half of string
-
125 int64_t sh = n - fh; // second half of string
-
126
-
127 std::string Xl = divide_and_conquer::karatsuba_algorithm::safe_substr(str1, 0, fh, n); // first half of first string
-
128 std::string Xr = divide_and_conquer::karatsuba_algorithm::safe_substr(str1, fh, sh, n); // second half of first string
-
129
-
130 std::string Yl = divide_and_conquer::karatsuba_algorithm::safe_substr(str2, 0, fh, n); // first half of second string
-
131 std::string Yr = divide_and_conquer::karatsuba_algorithm::safe_substr(str2, fh, sh, n); // second half of second string
-
132
-
133 // calculating the three products of inputs of size n/2 recursively
-
134 int64_t product1 = karatsuba_algorithm(Xl, Yl);
-
135 int64_t product2 = karatsuba_algorithm(Xr, Yr);
-
136 int64_t product3 = karatsuba_algorithm(
- - -
139
-
140 return product1 * (1 << (2 * sh)) +
-
141 (product3 - product1 - product2) * (1 << sh) +
-
142 product2; // combining the three products to get the final result.
-
143}
+
103
+
+
111int64_t karatsuba_algorithm(std::string str1, std::string str2) {
+
112 int64_t len1 = str1.size();
+
113 int64_t len2 = str2.size();
+
114 int64_t n = std::max(len1, len2);
+
115
+
116 if (n == 0) {
+
117 return 0;
+
118 }
+
119 if (n == 1) {
+
120 return (str1[0] - '0') * (str2[0] - '0');
+
121 }
+
122
+
123 int64_t fh = n / 2; // first half of string
+
124 int64_t sh = n - fh; // second half of string
+
125
+
126 std::string Xl = divide_and_conquer::karatsuba_algorithm::safe_substr(str1, 0, fh, n); // first half of first string
+
127 std::string Xr = divide_and_conquer::karatsuba_algorithm::safe_substr(str1, fh, sh, n); // second half of first string
+
128
+
129 std::string Yl = divide_and_conquer::karatsuba_algorithm::safe_substr(str2, 0, fh, n); // first half of second string
+
130 std::string Yr = divide_and_conquer::karatsuba_algorithm::safe_substr(str2, fh, sh, n); // second half of second string
+
131
+
132 // calculating the three products of inputs of size n/2 recursively
+
133 int64_t product1 = karatsuba_algorithm(Xl, Yl);
+
134 int64_t product2 = karatsuba_algorithm(Xr, Yr);
+
135 int64_t product3 = karatsuba_algorithm(
+ + +
138
+
139 return product1 * (1 << (2 * sh)) +
+
140 (product3 - product1 - product2) * (1 << sh) +
+
141 product2; // combining the three products to get the final result.
+
142}
-
144} // namespace karatsuba_algorithm
-
145} // namespace divide_and_conquer
-
146
-
-
151static void test() {
-
152 // 1st test
-
153 std::string s11 = "1"; // 1
-
154 std::string s12 = "1010"; // 10
-
155 std::cout << "1st test... ";
- -
157 s11, s12) == 10);
-
158 std::cout << "passed" << std::endl;
-
159
-
160 // 2nd test
-
161 std::string s21 = "11"; // 3
-
162 std::string s22 = "1010"; // 10
-
163 std::cout << "2nd test... ";
- -
165 s21, s22) == 30);
-
166 std::cout << "passed" << std::endl;
-
167
-
168 // 3rd test
-
169 std::string s31 = "110"; // 6
-
170 std::string s32 = "1010"; // 10
-
171 std::cout << "3rd test... ";
- -
173 s31, s32) == 60);
-
174 std::cout << "passed" << std::endl;
-
175}
+
143} // namespace karatsuba_algorithm
+
144} // namespace divide_and_conquer
+
145
+
+
150static void test() {
+
151 // 1st test
+
152 std::string s11 = "1"; // 1
+
153 std::string s12 = "1010"; // 10
+
154 std::cout << "1st test... ";
+ +
156 s11, s12) == 10);
+
157 std::cout << "passed" << std::endl;
+
158
+
159 // 2nd test
+
160 std::string s21 = "11"; // 3
+
161 std::string s22 = "1010"; // 10
+
162 std::cout << "2nd test... ";
+ +
164 s21, s22) == 30);
+
165 std::cout << "passed" << std::endl;
+
166
+
167 // 3rd test
+
168 std::string s31 = "110"; // 6
+
169 std::string s32 = "1010"; // 10
+
170 std::cout << "3rd test... ";
+ +
172 s31, s32) == 60);
+
173 std::cout << "passed" << std::endl;
+
174}
-
176
-
-
181int main() {
-
182 test(); // run self-test implementations
-
183 return 0;
-
184}
+
175
+
+
180int main() {
+
181 test(); // run self-test implementations
+
182 return 0;
+
183}
-
int64_t karatsuba_algorithm(std::string str1, std::string str2)
The main function implements Karatsuba's algorithm for fast multiplication.
-
static void test()
Self-test implementations.
-
std::string safe_substr(const std::string &str, int64_t x1, int64_t x2, int64_t n)
Wrapper function for substr that considers leading zeros.
-
std::string add_strings(std::string first, std::string second)
Binary addition.
- -
for std::vector
+
int64_t karatsuba_algorithm(std::string str1, std::string str2)
The main function implements Karatsuba's algorithm for fast multiplication.
+
static void test()
Self-test implementations.
+
std::string safe_substr(const std::string &str, int64_t x1, int64_t x2, int64_t n)
Wrapper function for substr that considers leading zeros.
+
std::string add_strings(std::string first, std::string second)
Binary addition.
+ +
for IO operations
Functions for the Karatsuba algorithm for fast multiplication implementation.
diff --git a/db/dc0/namespacebacktracking.html b/db/dc0/namespacebacktracking.html index 5e9f36575..a20edcd27 100644 --- a/db/dc0/namespacebacktracking.html +++ b/db/dc0/namespacebacktracking.html @@ -149,11 +149,8 @@ Functions

for assert

Backtracking algorithms.

for IO operations

-

for std::vector

for assert for I/O operation

Backtracking algorithms

-

for std::array for IO operations

-

Backtracking algorithms

for std::array

Backtracking algorithms

for std::count for assert for IO operations for std::list for std::accumulate for std::vector

diff --git a/dc/d61/classgraph_1_1_graph.html b/dc/d61/classgraph_1_1_graph.html index de7ef95bf..416ba49b2 100644 --- a/dc/d61/classgraph_1_1_graph.html +++ b/dc/d61/classgraph_1_1_graph.html @@ -167,7 +167,7 @@ Private Attributes
template<typename T>
class graph::Graph< T >

Class for representing a graph as an adjacency list. Its vertices are indexed 0, 1, ..., N - 1.

-

Definition at line 64 of file breadth_first_search.cpp.

+

Definition at line 63 of file breadth_first_search.cpp.

Constructor & Destructor Documentation

◆ Graph()

@@ -215,7 +215,7 @@ template<typename T>
66 neighbors[edge.second].push_back(edge.first);
67 }
68 }
- +
std::vector< std::vector< int > > neighbors
for each vertex it stores a list indicies of its neighbors
@@ -257,15 +257,15 @@ template<typename T>

add_edge(u,v,bidir) is used to add an edge between node u and node v by default , bidir is made true , i.e graph is bidirectional . It means if edge(u,v) is added then u-->v and v-->u both edges exist.

to make the graph unidirectional pass the third parameter of add_edge as false which will

-

Definition at line 74 of file breadth_first_search.cpp.

-
74 {
-
84 adjacency_list[u].push_back(v); // u-->v edge added
-
85 if (bidir == true) {
-
86 // if graph is bidirectional
-
87 adjacency_list[v].push_back(u); // v-->u edge added
-
88 }
-
89 }
-
std::map< T, std::list< T > > adjacency_list
+

Definition at line 73 of file breadth_first_search.cpp.

+
73 {
+
83 adjacency_list[u].push_back(v); // u-->v edge added
+
84 if (bidir == true) {
+
85 // if graph is bidirectional
+
86 adjacency_list[v].push_back(u); // v-->u edge added
+
87 }
+
88 }
+
std::map< T, std::list< T > > adjacency_list
@@ -305,32 +305,32 @@ template<typename T>

if the neighbour is unvisited , push it into the queue

mark the neighbour as visited

-

Definition at line 96 of file breadth_first_search.cpp.

-
96 {
-
98 std::map<T, bool> visited;
-
101 for (auto const &adjlist : adjacency_list) {
-
102 visited[adjlist.first] = false;
-
103 for (auto const &node : adjacency_list[adjlist.first]) {
-
104 visited[node] = false;
-
105 }
-
106 }
-
107
-
109 std::queue<T> tracker;
-
110
-
112 tracker.push(src);
-
114 visited[src] = true;
-
115 while (!tracker.empty()) {
-
118 T node = tracker.front();
-
120 tracker.pop();
-
121 for (T const &neighbour : adjacency_list[node]) {
-
124 if (!visited[neighbour]) {
-
126 tracker.push(neighbour);
-
128 visited[neighbour] = true;
-
129 }
-
130 }
-
131 }
-
132 return visited;
-
133 }
+

Definition at line 95 of file breadth_first_search.cpp.

+
95 {
+ +
100 for (auto const &adjlist : adjacency_list) {
+
101 visited[adjlist.first] = false;
+
102 for (auto const &node : adjacency_list[adjlist.first]) {
+
103 visited[node] = false;
+
104 }
+
105 }
+
106
+ +
109
+
111 tracker.push(src);
+
113 visited[src] = true;
+
114 while (!tracker.empty()) {
+
117 T node = tracker.front();
+
119 tracker.pop();
+
120 for (T const &neighbour : adjacency_list[node]) {
+
123 if (!visited[neighbour]) {
+
125 tracker.push(neighbour);
+
127 visited[neighbour] = true;
+
128 }
+
129 }
+
130 }
+
131 return visited;
+
132 }
@@ -389,7 +389,7 @@ template<typename T>

adjacency_list maps every vertex to the list of its neighbours in the order in which they are added.

-

Definition at line 69 of file breadth_first_search.cpp.

+

Definition at line 68 of file breadth_first_search.cpp.

diff --git a/dd/dba/namespacedivide__and__conquer.html b/dd/dba/namespacedivide__and__conquer.html index 94493c948..5415b35ea 100644 --- a/dd/dba/namespacedivide__and__conquer.html +++ b/dd/dba/namespacedivide__and__conquer.html @@ -125,12 +125,12 @@ $(function(){initNavTree('dd/dba/namespacedivide__and__conquer.html','../../');
-

for std::vector +

for IO operations More...

Detailed Description

-

for std::vector

+

for IO operations

Strassen's algorithm is one of the methods for multiplying two matrices. It is one of the faster algorithms for larger matrices than naive multiplication method.

-

for assert for string for IO operations

+

for assert for string

Divide and Conquer algorithms

It involves dividing each matrices into 4 blocks, given they are evenly divisible, and are combined with new defined matrices involving 7 matrix multiplications instead of eight, yielding O(n^2.8073) complexity.

Author
AshishYUO For assert operation For std::chrono; time measurement For I/O operations For std::tuple For creating dynamic arrays
diff --git a/de/d99/trie__tree_8cpp__incl.map b/de/d99/trie__tree_8cpp__incl.map index b23c10442..8c05e991a 100644 --- a/de/d99/trie__tree_8cpp__incl.map +++ b/de/d99/trie__tree_8cpp__incl.map @@ -1,15 +1,13 @@ - + - + - + - + - + - - - + diff --git a/de/d99/trie__tree_8cpp__incl.md5 b/de/d99/trie__tree_8cpp__incl.md5 index 62c1997c4..9d58e1060 100644 --- a/de/d99/trie__tree_8cpp__incl.md5 +++ b/de/d99/trie__tree_8cpp__incl.md5 @@ -1 +1 @@ -1cf5791bbfd7e15df47212f7724835dd \ No newline at end of file +25563c9822626b8e6bcc2e85f96288f5 \ No newline at end of file diff --git a/de/d99/trie__tree_8cpp__incl.svg b/de/d99/trie__tree_8cpp__incl.svg index 9d0377c5e..4b9f0bc82 100644 --- a/de/d99/trie__tree_8cpp__incl.svg +++ b/de/d99/trie__tree_8cpp__incl.svg @@ -4,8 +4,8 @@ - + @@ -23,9 +23,9 @@ Node1 - -data_structures/trie -_tree.cpp + +data_structures/trie +_tree.cpp @@ -42,8 +42,8 @@ Node1->Node2 - - + + @@ -60,8 +60,8 @@ Node1->Node3 - - + + @@ -78,8 +78,8 @@ Node1->Node4 - - + + @@ -96,8 +96,8 @@ Node1->Node5 - - + + @@ -114,26 +114,8 @@ Node1->Node6 - - - - - - - -Node7 - - -vector - - - - - -Node1->Node7 - - - + + diff --git a/de/d99/trie__tree_8cpp__incl_org.svg b/de/d99/trie__tree_8cpp__incl_org.svg index 372845421..4ba7b9697 100644 --- a/de/d99/trie__tree_8cpp__incl_org.svg +++ b/de/d99/trie__tree_8cpp__incl_org.svg @@ -4,17 +4,17 @@ - + data_structures/trie_tree.cpp Node1 - -data_structures/trie -_tree.cpp + +data_structures/trie +_tree.cpp @@ -31,8 +31,8 @@ Node1->Node2 - - + + @@ -49,8 +49,8 @@ Node1->Node3 - - + + @@ -67,8 +67,8 @@ Node1->Node4 - - + + @@ -85,8 +85,8 @@ Node1->Node5 - - + + @@ -103,26 +103,8 @@ Node1->Node6 - - - - - - - -Node7 - - -vector - - - - - -Node1->Node7 - - - + + diff --git a/de/dde/lowest__common__ancestor_8cpp_source.html b/de/dde/lowest__common__ancestor_8cpp_source.html index 9633270c7..8d67aef49 100644 --- a/de/dde/lowest__common__ancestor_8cpp_source.html +++ b/de/dde/lowest__common__ancestor_8cpp_source.html @@ -283,7 +283,7 @@ $(function(){initNavTree('de/dde/lowest__common__ancestor_8cpp_source.html','../
257 return 0;
258}
- +
std::vector< std::vector< int > > neighbors
for each vertex it stores a list indicies of its neighbors
Graph(size_t N, const std::vector< std::pair< int, int > > &undirected_edges)
Populate the adjacency list for each vertex in the graph. Assumes that evey edge is a pair of valid v...
int number_of_vertices() const
diff --git a/df/d82/breadth__first__search_8cpp.html b/df/d82/breadth__first__search_8cpp.html index 84b49c484..07377f109 100644 --- a/df/d82/breadth__first__search_8cpp.html +++ b/df/d82/breadth__first__search_8cpp.html @@ -138,11 +138,10 @@ $(function(){initNavTree('df/d82/breadth__first__search_8cpp.html','../../'); in #include <map>
#include <queue>
#include <string>
-#include <vector>
Include dependency graph for breadth_first_search.cpp:
-
+

Go to the source code of this file.

@@ -209,28 +208,28 @@ Functions

Main function

-

Definition at line 186 of file breadth_first_search.cpp.

-
186 {
-
187 tests();
-
188 size_t edges = 0;
-
189 std::cout << "Enter the number of edges: ";
-
190 std::cin >> edges;
-
191
- -
193
-
194 std::cout << "Enter space-separated pairs of vertices that form edges: "
-
195 << std::endl;
-
196 while (edges--) {
-
197 int u = 0, v = 0;
-
198 std::cin >> u >> v;
-
199 g.add_edge(u, v);
-
200 }
-
201
-
202 g.breadth_first_search(0);
-
203 return 0;
-
204}
-
static void tests()
- +

Definition at line 185 of file breadth_first_search.cpp.

+
185 {
+
186 tests();
+
187 size_t edges = 0;
+
188 std::cout << "Enter the number of edges: ";
+
189 std::cin >> edges;
+
190
+ +
192
+
193 std::cout << "Enter space-separated pairs of vertices that form edges: "
+
194 << std::endl;
+
195 while (edges--) {
+
196 int u = 0, v = 0;
+
197 std::cin >> u >> v;
+
198 g.add_edge(u, v);
+
199 }
+
200
+
201 g.breadth_first_search(0);
+
202 return 0;
+
203}
+
static void tests()
+
double g(double x)
Another test function.
@@ -262,51 +261,51 @@ Functions

Test 2 Begin

Test 3 Begins

-

Definition at line 139 of file breadth_first_search.cpp.

-
139 {
- -
142 std::map<int, bool> correct_result;
-
143 g.add_edge(0, 1);
-
144 g.add_edge(1, 2);
-
145 g.add_edge(2, 3);
-
146 correct_result[0] = true;
-
147 correct_result[1] = true;
-
148 correct_result[2] = true;
-
149 correct_result[3] = true;
-
150
-
151 std::map<int, bool> returned_result = g.breadth_first_search(2);
-
152
-
153 assert(returned_result == correct_result);
-
154 std::cout << "Test 1 Passed..." << std::endl;
-
155
-
157 returned_result = g.breadth_first_search(0);
-
158
-
159 assert(returned_result == correct_result);
-
160 std::cout << "Test 2 Passed..." << std::endl;
-
161
- -
164
-
165 g2.add_edge("Gorakhpur", "Lucknow", false);
-
166 g2.add_edge("Gorakhpur", "Kanpur", false);
-
167 g2.add_edge("Lucknow", "Agra", false);
-
168 g2.add_edge("Kanpur", "Agra", false);
-
169 g2.add_edge("Lucknow", "Prayagraj", false);
-
170 g2.add_edge("Agra", "Noida", false);
-
171
-
172 std::map<std::string, bool> correct_res;
-
173 std::map<std::string, bool> returned_res =
-
174 g2.breadth_first_search("Kanpur");
-
175 correct_res["Gorakhpur"] = false;
-
176 correct_res["Lucknow"] = false;
-
177 correct_res["Kanpur"] = true;
-
178 correct_res["Agra"] = true;
-
179 correct_res["Prayagraj"] = false;
-
180 correct_res["Noida"] = true;
-
181 assert(correct_res == returned_res);
-
182 std::cout << "Test 3 Passed..." << std::endl;
-
183}
-
std::map< T, bool > breadth_first_search(T src)
-
void add_edge(T u, T v, bool bidir=true)
+

Definition at line 138 of file breadth_first_search.cpp.

+
138 {
+ +
141 std::map<int, bool> correct_result;
+
142 g.add_edge(0, 1);
+
143 g.add_edge(1, 2);
+
144 g.add_edge(2, 3);
+
145 correct_result[0] = true;
+
146 correct_result[1] = true;
+
147 correct_result[2] = true;
+
148 correct_result[3] = true;
+
149
+
150 std::map<int, bool> returned_result = g.breadth_first_search(2);
+
151
+
152 assert(returned_result == correct_result);
+
153 std::cout << "Test 1 Passed..." << std::endl;
+
154
+
156 returned_result = g.breadth_first_search(0);
+
157
+
158 assert(returned_result == correct_result);
+
159 std::cout << "Test 2 Passed..." << std::endl;
+
160
+ +
163
+
164 g2.add_edge("Gorakhpur", "Lucknow", false);
+
165 g2.add_edge("Gorakhpur", "Kanpur", false);
+
166 g2.add_edge("Lucknow", "Agra", false);
+
167 g2.add_edge("Kanpur", "Agra", false);
+
168 g2.add_edge("Lucknow", "Prayagraj", false);
+
169 g2.add_edge("Agra", "Noida", false);
+
170
+
171 std::map<std::string, bool> correct_res;
+
172 std::map<std::string, bool> returned_res =
+
173 g2.breadth_first_search("Kanpur");
+
174 correct_res["Gorakhpur"] = false;
+
175 correct_res["Lucknow"] = false;
+
176 correct_res["Kanpur"] = true;
+
177 correct_res["Agra"] = true;
+
178 correct_res["Prayagraj"] = false;
+
179 correct_res["Noida"] = true;
+
180 assert(correct_res == returned_res);
+
181 std::cout << "Test 3 Passed..." << std::endl;
+
182}
+
std::map< T, bool > breadth_first_search(T src)
+
void add_edge(T u, T v, bool bidir=true)
diff --git a/df/d82/breadth__first__search_8cpp_source.html b/df/d82/breadth__first__search_8cpp_source.html index 8ddcb928f..c89e7def3 100644 --- a/df/d82/breadth__first__search_8cpp_source.html +++ b/df/d82/breadth__first__search_8cpp_source.html @@ -132,132 +132,131 @@ $(function(){initNavTree('df/d82/breadth__first__search_8cpp_source.html','../..
52#include <map>
53#include <queue>
54#include <string>
-
55#include <vector>
-
56
-
61namespace graph {
-
62/* Class Graph definition */
-
63template <typename T>
-
-
64class Graph {
-
69 std::map<T, std::list<T> > adjacency_list;
-
70
-
71 public:
-
72 Graph() = default;
-
73 ;
-
-
74 void add_edge(T u, T v, bool bidir = true) {
-
84 adjacency_list[u].push_back(v); // u-->v edge added
-
85 if (bidir == true) {
-
86 // if graph is bidirectional
-
87 adjacency_list[v].push_back(u); // v-->u edge added
-
88 }
-
89 }
+
55
+
60namespace graph {
+
61/* Class Graph definition */
+
62template <typename T>
+
+
63class Graph {
+
68 std::map<T, std::list<T> > adjacency_list;
+
69
+
70 public:
+
71 Graph() = default;
+
72 ;
+
+
73 void add_edge(T u, T v, bool bidir = true) {
+
83 adjacency_list[u].push_back(v); // u-->v edge added
+
84 if (bidir == true) {
+
85 // if graph is bidirectional
+
86 adjacency_list[v].push_back(u); // v-->u edge added
+
87 }
+
88 }
-
90
-
-
96 std::map<T, bool> breadth_first_search(T src) {
-
98 std::map<T, bool> visited;
-
101 for (auto const &adjlist : adjacency_list) {
-
102 visited[adjlist.first] = false;
-
103 for (auto const &node : adjacency_list[adjlist.first]) {
-
104 visited[node] = false;
-
105 }
-
106 }
-
107
-
109 std::queue<T> tracker;
-
110
-
112 tracker.push(src);
-
114 visited[src] = true;
-
115 while (!tracker.empty()) {
-
118 T node = tracker.front();
-
120 tracker.pop();
-
121 for (T const &neighbour : adjacency_list[node]) {
-
124 if (!visited[neighbour]) {
-
126 tracker.push(neighbour);
-
128 visited[neighbour] = true;
-
129 }
-
130 }
-
131 }
-
132 return visited;
-
133 }
+
89
+
+
95 std::map<T, bool> breadth_first_search(T src) {
+
97 std::map<T, bool> visited;
+
100 for (auto const &adjlist : adjacency_list) {
+
101 visited[adjlist.first] = false;
+
102 for (auto const &node : adjacency_list[adjlist.first]) {
+
103 visited[node] = false;
+
104 }
+
105 }
+
106
+
108 std::queue<T> tracker;
+
109
+
111 tracker.push(src);
+
113 visited[src] = true;
+
114 while (!tracker.empty()) {
+
117 T node = tracker.front();
+
119 tracker.pop();
+
120 for (T const &neighbour : adjacency_list[node]) {
+
123 if (!visited[neighbour]) {
+
125 tracker.push(neighbour);
+
127 visited[neighbour] = true;
+
128 }
+
129 }
+
130 }
+
131 return visited;
+
132 }
-
134};
+
133};
-
135/* Class definition ends */
-
136} // namespace graph
-
137
-
-
139static void tests() {
- -
142 std::map<int, bool> correct_result;
-
143 g.add_edge(0, 1);
-
144 g.add_edge(1, 2);
-
145 g.add_edge(2, 3);
-
146 correct_result[0] = true;
-
147 correct_result[1] = true;
-
148 correct_result[2] = true;
-
149 correct_result[3] = true;
-
150
-
151 std::map<int, bool> returned_result = g.breadth_first_search(2);
-
152
-
153 assert(returned_result == correct_result);
-
154 std::cout << "Test 1 Passed..." << std::endl;
-
155
-
157 returned_result = g.breadth_first_search(0);
-
158
-
159 assert(returned_result == correct_result);
-
160 std::cout << "Test 2 Passed..." << std::endl;
-
161
- -
164
-
165 g2.add_edge("Gorakhpur", "Lucknow", false);
-
166 g2.add_edge("Gorakhpur", "Kanpur", false);
-
167 g2.add_edge("Lucknow", "Agra", false);
-
168 g2.add_edge("Kanpur", "Agra", false);
-
169 g2.add_edge("Lucknow", "Prayagraj", false);
-
170 g2.add_edge("Agra", "Noida", false);
-
171
-
172 std::map<std::string, bool> correct_res;
-
173 std::map<std::string, bool> returned_res =
-
174 g2.breadth_first_search("Kanpur");
-
175 correct_res["Gorakhpur"] = false;
-
176 correct_res["Lucknow"] = false;
-
177 correct_res["Kanpur"] = true;
-
178 correct_res["Agra"] = true;
-
179 correct_res["Prayagraj"] = false;
-
180 correct_res["Noida"] = true;
-
181 assert(correct_res == returned_res);
-
182 std::cout << "Test 3 Passed..." << std::endl;
-
183}
+
134/* Class definition ends */
+
135} // namespace graph
+
136
+
+
138static void tests() {
+ +
141 std::map<int, bool> correct_result;
+
142 g.add_edge(0, 1);
+
143 g.add_edge(1, 2);
+
144 g.add_edge(2, 3);
+
145 correct_result[0] = true;
+
146 correct_result[1] = true;
+
147 correct_result[2] = true;
+
148 correct_result[3] = true;
+
149
+
150 std::map<int, bool> returned_result = g.breadth_first_search(2);
+
151
+
152 assert(returned_result == correct_result);
+
153 std::cout << "Test 1 Passed..." << std::endl;
+
154
+
156 returned_result = g.breadth_first_search(0);
+
157
+
158 assert(returned_result == correct_result);
+
159 std::cout << "Test 2 Passed..." << std::endl;
+
160
+ +
163
+
164 g2.add_edge("Gorakhpur", "Lucknow", false);
+
165 g2.add_edge("Gorakhpur", "Kanpur", false);
+
166 g2.add_edge("Lucknow", "Agra", false);
+
167 g2.add_edge("Kanpur", "Agra", false);
+
168 g2.add_edge("Lucknow", "Prayagraj", false);
+
169 g2.add_edge("Agra", "Noida", false);
+
170
+
171 std::map<std::string, bool> correct_res;
+
172 std::map<std::string, bool> returned_res =
+
173 g2.breadth_first_search("Kanpur");
+
174 correct_res["Gorakhpur"] = false;
+
175 correct_res["Lucknow"] = false;
+
176 correct_res["Kanpur"] = true;
+
177 correct_res["Agra"] = true;
+
178 correct_res["Prayagraj"] = false;
+
179 correct_res["Noida"] = true;
+
180 assert(correct_res == returned_res);
+
181 std::cout << "Test 3 Passed..." << std::endl;
+
182}
-
184
-
-
186int main() {
-
187 tests();
-
188 size_t edges = 0;
-
189 std::cout << "Enter the number of edges: ";
-
190 std::cin >> edges;
-
191
- -
193
-
194 std::cout << "Enter space-separated pairs of vertices that form edges: "
-
195 << std::endl;
-
196 while (edges--) {
-
197 int u = 0, v = 0;
-
198 std::cin >> u >> v;
-
199 g.add_edge(u, v);
-
200 }
-
201
-
202 g.breadth_first_search(0);
-
203 return 0;
-
204}
+
183
+
+
185int main() {
+
186 tests();
+
187 size_t edges = 0;
+
188 std::cout << "Enter the number of edges: ";
+
189 std::cin >> edges;
+
190
+ +
192
+
193 std::cout << "Enter space-separated pairs of vertices that form edges: "
+
194 << std::endl;
+
195 while (edges--) {
+
196 int u = 0, v = 0;
+
197 std::cin >> u >> v;
+
198 g.add_edge(u, v);
+
199 }
+
200
+
201 g.breadth_first_search(0);
+
202 return 0;
+
203}
-
static void tests()
- - -
std::map< T, bool > breadth_first_search(T src)
-
void add_edge(T u, T v, bool bidir=true)
-
std::map< T, std::list< T > > adjacency_list
+
static void tests()
+ + +
std::map< T, bool > breadth_first_search(T src)
+
void add_edge(T u, T v, bool bidir=true)
+
std::map< T, std::list< T > > adjacency_list
Graph Algorithms.
diff --git a/namespaces.html b/namespaces.html index e72b1f285..bbffb5056 100644 --- a/namespaces.html +++ b/namespaces.html @@ -152,7 +152,7 @@ $(function(){initNavTree('namespaces.html',''); initResizable(true); });  NtreapFunctions for the Treap algorithm implementation  Ndepth_first_searchFunctions for Depth First Search algorithm  Ndisjoint_unionFunctions for Disjoint union implementation - Ndivide_and_conquerFor std::vector + Ndivide_and_conquerFor IO operations  Ndnf_sortFunctions for the DNF sort implementation  Ndouble_hashingAn implementation of hash table using double hashing algorithm  NdpFor std::vector