From 9a321b9f151b5877894cc788c3dad9eacc069b1c Mon Sep 17 00:00:00 2001 From: Donne Martin Date: Mon, 14 Nov 2016 06:39:16 -0500 Subject: [PATCH] Update graph bfs challenge Add more detail to algorithm space complexity. --- graphs_trees/graph_bfs/bfs_solution.ipynb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/graphs_trees/graph_bfs/bfs_solution.ipynb b/graphs_trees/graph_bfs/bfs_solution.ipynb index b4b098b..feed2c5 100644 --- a/graphs_trees/graph_bfs/bfs_solution.ipynb +++ b/graphs_trees/graph_bfs/bfs_solution.ipynb @@ -83,7 +83,12 @@ "\n", "Complexity:\n", "* Time: O(V + E), where V = number of vertices and E = number of edges\n", - "* Space: O(V + E)" + "* Space: O(V)\n", + "\n", + "Note on space complexity from [Wikipedia](https://en.wikipedia.org/wiki/Breadth-first_search):\n", + "* When the number of vertices in the graph is known ahead of time, and additional data structures are used to determine which vertices have already been added to the queue, the space complexity can be expressed as O(V) \n", + "* If the graph is represented by an adjacency list it occupies O(V + E) space in memory\n", + "* If the graph is represented by an adjacency matrix representation, it occupies O(V^2)" ] }, {