From fa3acf7d52638fea78720e0ed3413091be9a2614 Mon Sep 17 00:00:00 2001 From: pyagnik12 <53314208+pyagnik1@users.noreply.github.com> Date: Sun, 12 Feb 2023 16:25:07 -0500 Subject: [PATCH] Added documentation for Prims algorithm Added documentation for Prims algorithm as well as links to all different Implementation. --- docs/en/Graphs/Prims.md | 32 ++++++++++++++++++++++++ docs/en/Tree/# AVL Tree Documentation.md | 2 +- 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 docs/en/Graphs/Prims.md diff --git a/docs/en/Graphs/Prims.md b/docs/en/Graphs/Prims.md new file mode 100644 index 00000000..11085ef6 --- /dev/null +++ b/docs/en/Graphs/Prims.md @@ -0,0 +1,32 @@ +# Prim's Algorithm Documentation +Prim's algorithm is a greedy algorithm used for finding the minimum spanning tree (MST) of a weighted graph. It starts with an arbitrary vertex and grows the tree by adding the minimum weight edge that connects a vertex in the tree to a vertex outside of the tree. The algorithm continues until all vertices are included in the tree. + +## Key Features of Prim's Algorithm + +- Greedy approach: Prim's algorithm follows a greedy approach by always selecting the edge with the minimum weight that connects a vertex in the tree to a vertex outside of the tree. + +- Minimum spanning tree: Prim's algorithm produces a minimum spanning tree, which is a tree that spans all vertices in the graph and has the minimum total edge weight among all such trees. + +## Algorithm Steps +1. Start with an arbitrary vertex as the root of the tree. + +2. Maintain a set of vertices in the tree and a set of vertices outside of the tree. + +3. Find the minimum weight edge that connects a vertex in the tree to a vertex outside of the tree, and add the edge and the new vertex to the tree. + +4. Repeat step 3 until all vertices are included in the tree. + +## Time and Space Complexity +The time complexity of Prim's algorithm is O(E log V), where E is the number of edges and V is the number of vertices. The space complexity is O(V), as the algorithm only needs to store the vertices that are in the tree and outside of the tree. + + +## Implementation +- [C](../../../algorithms/C/Graphs/Prim's-algorithm.c) +- [C++](../../../algorithms/CPlusPlus/Graphs/prim's_algorithm.cpp) +- [Java](../../../algorithms/Java/graphs/Prims.java) + +## Video URL +[Youtube Video about Prims Algorithm ](https://www.youtube.com/watch?v=ZtZaR7EcI5Y) + +## Others +[Wikipedia](https://en.wikipedia.org/wiki/Prim%27s_algorithm) \ No newline at end of file diff --git a/docs/en/Tree/# AVL Tree Documentation.md b/docs/en/Tree/# AVL Tree Documentation.md index 1d20feb3..3d6ff284 100644 --- a/docs/en/Tree/# AVL Tree Documentation.md +++ b/docs/en/Tree/# AVL Tree Documentation.md @@ -8,7 +8,7 @@ An AVL tree is a self-balancing binary search tree that maintains a height-balan ## Basic Components of an AVL Tree -An AVL tree consists of nodes, each containing a value and pointers to its left and right child nodes. The height of a node is defined as the number of edges from the node to its deepest leaf. The height difference between the left and right subtrees of a node is called the balance factor, and it must be at most 1 for every node in the tree. +An AVL tree consists of nodes, each containing a value and pointers to its left and right child nodes. The height of a node is defined as the number of edges from the node to its deepest leaf. The height difference between the left and right subtrees of a node is called the balance factor, and it must be at most 1 for every node in the tree. ## Implementation - [C](../../../algorithms/C/tree/avl.c)