Skip to content

Commit

Permalink
Added code to graph traversal using BFS, DFS and code to calculate mi…
Browse files Browse the repository at this point in the history
…nimum number of coins to get target
  • Loading branch information
asesh committed Oct 26, 2023
1 parent 7bb4e34 commit 8f0cb29
Show file tree
Hide file tree
Showing 8 changed files with 348 additions and 43 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
filePath = "algorithm/main.cpp"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "345"
endingLineNumber = "345"
startingLineNumber = "350"
endingLineNumber = "350"
landmarkName = "main(argc, argv)"
landmarkType = "9">
</BreakpointContent>
Expand All @@ -30,8 +30,8 @@
filePath = "algorithm/main.cpp"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "311"
endingLineNumber = "311"
startingLineNumber = "316"
endingLineNumber = "316"
landmarkName = "main(argc, argv)"
landmarkType = "9">
</BreakpointContent>
Expand All @@ -46,8 +46,8 @@
filePath = "algorithm/main.cpp"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "236"
endingLineNumber = "236"
startingLineNumber = "241"
endingLineNumber = "241"
landmarkName = "main(argc, argv)"
landmarkType = "9">
</BreakpointContent>
Expand All @@ -62,8 +62,8 @@
filePath = "algorithm/main.cpp"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "204"
endingLineNumber = "204"
startingLineNumber = "209"
endingLineNumber = "209"
landmarkName = "main(argc, argv)"
landmarkType = "9">
</BreakpointContent>
Expand Down Expand Up @@ -174,8 +174,8 @@
filePath = "algorithm/main.cpp"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "162"
endingLineNumber = "162"
startingLineNumber = "167"
endingLineNumber = "167"
landmarkName = "main(argc, argv)"
landmarkType = "9">
</BreakpointContent>
Expand All @@ -190,8 +190,8 @@
filePath = "algorithm/main.cpp"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "125"
endingLineNumber = "125"
startingLineNumber = "130"
endingLineNumber = "130"
landmarkName = "main(argc, argv)"
landmarkType = "9">
</BreakpointContent>
Expand All @@ -206,8 +206,8 @@
filePath = "algorithm/main.cpp"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "84"
endingLineNumber = "84"
startingLineNumber = "89"
endingLineNumber = "89"
landmarkName = "main(argc, argv)"
landmarkType = "9">
</BreakpointContent>
Expand Down Expand Up @@ -238,8 +238,8 @@
filePath = "algorithm/main.cpp"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "73"
endingLineNumber = "73"
startingLineNumber = "78"
endingLineNumber = "78"
landmarkName = "main(argc, argv)"
landmarkType = "9">
</BreakpointContent>
Expand All @@ -254,26 +254,163 @@
filePath = "algorithm/main.cpp"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "59"
endingLineNumber = "59"
startingLineNumber = "64"
endingLineNumber = "64"
landmarkName = "main(argc, argv)"
landmarkType = "9">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "91321F11-789E-45E7-A015-8191DD95FFD7"
shouldBeEnabled = "No"
uuid = "818BACD0-EE82-4A6C-89D6-F241C11E02D7"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "algorithm/main.cpp"
filePath = "algorithm/graph_algorithm.cpp"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "32"
endingLineNumber = "32"
landmarkName = "main(argc, argv)"
startingLineNumber = "92"
endingLineNumber = "92"
landmarkName = "create_directed_graph()"
landmarkType = "9">
<Locations>
<Location
uuid = "818BACD0-EE82-4A6C-89D6-F241C11E02D7 - a11c77d68fafdabb"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "create_directed_graph()"
moduleName = "algorithm"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/aseshshrestha/Code/Xcode%20Projects/algorithm/algorithm/graph_algorithm.cpp"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "99"
endingLineNumber = "99"
offsetFromSymbolStart = "1652">
</Location>
<Location
uuid = "818BACD0-EE82-4A6C-89D6-F241C11E02D7 - a11c77d68fafdb41"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "create_directed_graph()"
moduleName = "algorithm"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/aseshshrestha/Code/Xcode%20Projects/algorithm/algorithm/graph_algorithm.cpp"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "105"
endingLineNumber = "105"
offsetFromSymbolStart = "1652">
</Location>
<Location
uuid = "818BACD0-EE82-4A6C-89D6-F241C11E02D7 - a11c77d68fafdba2"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "create_directed_graph()"
moduleName = "algorithm"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/aseshshrestha/Code/Xcode%20Projects/algorithm/algorithm/graph_algorithm.cpp"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "106"
endingLineNumber = "106"
offsetFromSymbolStart = "1652">
</Location>
<Location
uuid = "818BACD0-EE82-4A6C-89D6-F241C11E02D7 - a11c77d68fafdb83"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "create_directed_graph()"
moduleName = "algorithm"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/aseshshrestha/Code/Xcode%20Projects/algorithm/algorithm/graph_algorithm.cpp"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "107"
endingLineNumber = "107"
offsetFromSymbolStart = "1656">
</Location>
<Location
uuid = "818BACD0-EE82-4A6C-89D6-F241C11E02D7 - a11c77d68fafda9c"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "create_directed_graph()"
moduleName = "algorithm"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/aseshshrestha/Code/Xcode%20Projects/algorithm/algorithm/graph_algorithm.cpp"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "100"
endingLineNumber = "100"
offsetFromSymbolStart = "1656">
</Location>
<Location
uuid = "818BACD0-EE82-4A6C-89D6-F241C11E02D7 - a11c77d68fafdb3f"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "create_directed_graph()"
moduleName = "algorithm"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/aseshshrestha/Code/Xcode%20Projects/algorithm/algorithm/graph_algorithm.cpp"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "103"
endingLineNumber = "103"
offsetFromSymbolStart = "1656">
</Location>
<Location
uuid = "818BACD0-EE82-4A6C-89D6-F241C11E02D7 - a11c77d68fafdc49"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "create_directed_graph()"
moduleName = "algorithm"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/aseshshrestha/Code/Xcode%20Projects/algorithm/algorithm/graph_algorithm.cpp"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "113"
endingLineNumber = "113"
offsetFromSymbolStart = "1656">
</Location>
<Location
uuid = "818BACD0-EE82-4A6C-89D6-F241C11E02D7 - a11c77d68fafd9f5"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "create_directed_graph()"
moduleName = "algorithm"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/aseshshrestha/Code/Xcode%20Projects/algorithm/algorithm/graph_algorithm.cpp"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "93"
endingLineNumber = "93"
offsetFromSymbolStart = "1656">
</Location>
<Location
uuid = "818BACD0-EE82-4A6C-89D6-F241C11E02D7 - a11c77d68fafd994"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "create_directed_graph()"
moduleName = "algorithm"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/aseshshrestha/Code/Xcode%20Projects/algorithm/algorithm/graph_algorithm.cpp"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "92"
endingLineNumber = "92"
offsetFromSymbolStart = "1656">
</Location>
</Locations>
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
Expand Down
80 changes: 68 additions & 12 deletions algorithm/graph_algorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,85 @@
#include "header.h"
#include "graph_algorithm.h"

void create_directed_graph() {
// Adjanceny list representation of graph
void create_undirected_graph() {
// Adjacency list representation of graph
/*
3 - 8 - 6 - 9 - 11 - 10
| | | |
1 - 7 - 0 - 12 - 19 - 17
| | | |
4 - 5 - 13 - 18 - 20
*/
std::unordered_map<int, std::list<int>> undirected_graph = {
{3, {1, 8}},
{8, {3, 6}},
{6, {8, 9, 0}},
{9, {6, 11, 12}},
{11, {9, 10}},
{10, {11, 17}},
{1, {3, 7}},
{7, {0, 1, 5}},
{0, {6, 7, 12, 13}},
{12, {0, 9, 18, 19}},
{19, {12, 17, 20}},
{17, {10, 19}},
{4, {5}},
{5, {4, 7, 13}},
{13, {0, 5, 18}},
{18, {12, 13, 20}},
{20, {18, 19}}
};

CBaseGraph<int> undi_graph(std::move(undirected_graph));
undi_graph.traverse_bfs(3);
undi_graph.traverse_dfs(7);
}

void create_directed_graph() {
// Adjanceny list representation of directed graph
/*
3 -> 8 -> 6 -> 9 -> 11 -> 10
| | | |
1 -> 7 -> 0 -> 12 -> 19 -> 17
| | | |
4 <- 5 <- 13 <- 18 <- 20
Adjacency list:
Node Adjacent nodes
3 8 - 1
8 3 - 6
6 8 - 9 - 0
0 6 - 7 - 12 - 13
...
20 18 - 19
8 6
6 9 - 0
9 11 - 12
11 10
10 17
1 7
7 0 - 5
0 12 - 13
12 18 - 19
19 17 - 20
4
5 4
13 5
18 13
20 18
*/
std::unordered_map<int, std::list<int>> directed_graph = {
{1, {3, 7}},
{3, {1, 8}}
{3, {1, 8}},
{8, {6}},
{6, {9, 0}},
{9, {11, 12}},
{11, {10}},
{10, {17}},
{1, {7}},
{7, {0, 5}},
{0, {12, 13}},
{12, {18, 19}},
{19, {17, 20}},
{5, {4}},
{13, {5}},
{18, {13}},
{20, {18}}
};
CDirectedGraph<int, int> di_graph(directed_graph);

CDirectedGraph<int, int> di_graph(std::move(directed_graph));
di_graph.traverse_bfs();
}
Loading

0 comments on commit 8f0cb29

Please sign in to comment.