Minimum Spanning Tree: Kruskal's vs Prim's Greedy Algorithms Notes in Hindi & English : मिनिमम स्पैनिंग ट्री (MST): क्रुस्कल बनाम प्रिम के ग्रीडी एल्गोरिदम और 20 महत्वपूर्ण MCQ प्रश्न (India IT Exam)

Post a Comment

UGC-NET, GATE, NIELIT (O/A/B Level), KVS/NVS Computer Teacher, PGDCA, BCA, MCA, B-Tech व All India IT Exam विशेष नोट्स: इस अध्याय में हम Minimum Spanning Tree: Kruskal's vs Prim's Greedy Algorithms (मिनिमम स्पैनिंग ट्री (MST): क्रुस्कल बनाम प्रिम के ग्रीडी एल्गोरिदम) की संपूर्ण थ्योरी, मुख्य तकनीकी बिंदु, तुलनात्मक तालिका और राष्ट्रीय स्तर की परीक्षाओं के पैटर्न पर आधारित 20 अति-महत्वपूर्ण बहुविकल्पीय प्रश्न (MCQs) विस्तृत हिंदी व अंग्रेजी व्याख्या सहित पढ़ेंगे।

Overview: A Minimum Spanning Tree (MST) connects all V vertices of a weighted, undirected, connected graph using exactly V-1 edges with the minimum possible total edge weight. Kruskal's algorithm grows a forest by sorting edges globally, while Prim's algorithm grows a single tree from a starting vertex using a priority queue.

अध्याय सार: एक मिनिमम स्पैनिंग ट्री (MST) न्यूनतम संभव कुल भार के साथ ठीक V-1 किनारों का उपयोग करके एक भारित, अनिर्देशित, जुड़े हुए ग्राफ के सभी V शीर्षों को जोड़ता है। क्रुस्कल का एल्गोरिदम किनारों को सॉर्ट करके एक फॉरेस्ट बढ़ाता है, जबकि प्रिम का एल्गोरिदम प्रायोरिटी क्यू का उपयोग करके एक ट्री बढ़ाता है।

Minimum Spanning Tree: Kruskal's vs Prim's Greedy Algorithms: Detailed Notes & Architecture (मिनिमम स्पैनिंग ट्री (MST): क्रुस्कल बनाम प्रिम के ग्रीडी एल्गोरिदम)

1. Properties of Minimum Spanning Trees (मिनिमम स्पैनिंग ट्री के गुण)

[EN] For any connected undirected graph with V vertices and E edges, a spanning tree has exactly V-1 edges and no cycles. If all edge weights are distinct, the MST is strictly unique. Two fundamental greedy properties—the Cut Property and the Cycle Property—prove that both Kruskal's and Prim's algorithms always find the optimal MST.

[HI] V शीर्षों और E किनारों वाले किसी भी जुड़े अनिर्देशित ग्राफ के लिए, स्पैनिंग ट्री में ठीक V-1 किनारे होते हैं और कोई चक्र नहीं होता। यदि सभी किनारों के भार अलग-अलग हैं, तो MST अद्वितीय होता है।

2. Kruskal's Greedy Algorithm (क्रुस्कल का ग्रीडी एल्गोरिदम)

[EN] Kruskal's algorithm sorts all E edges in non-decreasing order of weight in O(E log E) time. It iterates through the sorted edges, adding an edge to the MST if it does not form a cycle, checked efficiently using a Disjoint Set Union (Union-Find) data structure with path compression. Kruskal's is ideal for sparse graphs where E is close to V.

[HI] क्रुस्कल का एल्गोरिदम सभी E किनारों को O(E log E) समय में भार के बढ़ते क्रम में सॉर्ट करता है। यह सॉर्ट किए गए किनारों पर चलता है और यदि कोई किनारा चक्र नहीं बनाता है तो उसे MST में जोड़ता है, जिसे Union-Find डेटा संरचना से जांचा जाता है।

3. Prim's Greedy Algorithm (प्रिम का ग्रीडी एल्गोरिदम)

[EN] Prim's algorithm starts from an arbitrary root vertex and grows a single connected tree by repeatedly picking the minimum-weight edge crossing the cut between visited and unvisited vertices. Using a Binary Min-Heap and adjacency list, Prim's runs in O((V + E) log V) time (or O(E + V log V) with a Fibonacci Heap). Prim's outperforms Kruskal's on dense graphs.

[HI] प्रिम का एल्गोरिदम किसी भी रूट शीर्ष से शुरू होता है और विज़िट किए गए व अनविज़िट किए गए शीर्षों के बीच न्यूनतम-भार वाले किनारे को चुनकर एक एकल ट्री बढ़ाता है। बाइनरी मिन-हीप के साथ, प्रिम O((V + E) log V) समय में चलता है और घने ग्राफ पर बेहतर प्रदर्शन करता है।

4. Kruskal's vs Prim's Comparison (क्रुस्कल बनाम प्रिम की तुलना)

[EN] Both algorithms are greedy and produce the same total MST weight. Kruskal's works even on disconnected graphs (producing a Minimum Spanning Forest), whereas Prim's requires a connected graph. Kruskal's relies on Union-Find, while Prim's relies on a Min-Heap priority queue.

[HI] दोनों एल्गोरिदम ग्रीडी हैं और समान कुल MST भार उत्पन्न करते हैं। क्रुस्कल असंबद्ध ग्राफ पर भी काम करता है (मिनिमम स्पैनिंग फॉरेस्ट बनाता है), जबकि प्रिम को जुड़ा हुआ ग्राफ चाहिए।

Syntax, Formula & Technical Example (Minimum Spanning Tree: Kruskal's vs Prim's Greedy Algorithms)

# Kruskal's Algorithm Core Loop (Python)
edges.sort(key=lambda e: e[2])  # Sort by weight: (u, v, w)
mst_weight = 0
for u, v, w in edges:
    if find(u) != find(v):      # No cycle
        union(u, v)
        mst_weight += w

Minimum Spanning Tree: Kruskal's vs Prim's Greedy Algorithms Quick Reference & Comparison Table

AlgorithmTime ComplexityKey Exam Fact
Kruskal's (Union-Find)O(E log E)Best for sparse graphs; sorts all edges
Prim's (Binary Heap)O((V + E) log V)Best for dense graphs; grows single tree
Prim's (Fibonacci Heap)O(E + V log V)Theoretically fastest for dense graphs
Prim's (Adj Matrix)O(V^2)Simple array-based; no heap needed

Minimum Spanning Tree: Kruskal's vs Prim's Greedy Algorithms Top 20 Bilingual MCQs with Answers

Q1. How many edges does a Minimum Spanning Tree of a graph with V vertices have?

(V शीर्षों वाले ग्राफ के मिनिमम स्पैनिंग ट्री में कितने किनारे होते हैं?)

(A) V - 1

(B) V + 1

(C) V

(D) 2V

Correct Answer: (A)

[EN] A tree with V vertices always has exactly V - 1 edges.

[HI] V शीर्षों वाले ट्री में हमेशा ठीक V - 1 किनारे होते हैं।

Q2. Which data structure is used by Kruskal's algorithm to detect cycles efficiently?

(चक्रों का कुशलतापूर्वक पता लगाने के लिए क्रुस्कल के एल्गोरिदम द्वारा किस डेटा संरचना का उपयोग किया जाता है?)

(A) Hash Table

(B) Stack

(C) Min-Heap

(D) Disjoint Set Union (Union-Find)

Correct Answer: (D)

[EN] Union-Find with path compression checks cycle formation in nearly O(1) amortized time.

[HI] पाथ कम्प्रेशन के साथ Union-Find लगभग O(1) समय में चक्र की जांच करता है।

Q3. What is the time complexity of Kruskal's algorithm for a graph with E edges?

(E किनारों वाले ग्राफ के लिए क्रुस्कल के एल्गोरिदम की समय जटिलता क्या है?)

(A) O(E log E)

(B) O(V + E)

(C) O(E^2)

(D) O(V^2)

Correct Answer: (A)

[EN] Sorting E edges dominates Kruskal's runtime at O(E log E).

[HI] E किनारों को सॉर्ट करना O(E log E) पर क्रुस्कल के रनटाइम पर हावी होता है।

Q4. Which algorithm is generally preferred for dense graphs (where E is close to V^2)?

(घने ग्राफ (जहाँ E, V^2 के करीब है) के लिए आमतौर पर किस एल्गोरिदम को प्राथमिकता दी जाती है?)

(A) Kruskal's algorithm

(B) BFS

(C) Prim's algorithm

(D) Bellman-Ford

Correct Answer: (C)

[EN] Prim's with a Fibonacci Heap or Adjacency Matrix avoids sorting O(V^2) edges.

[HI] प्रिम का एल्गोरिदम O(V^2) किनारों को सॉर्ट करने से बचता है।

Q5. When is a graph guaranteed to have a unique Minimum Spanning Tree?

(किस स्थिति में किसी ग्राफ का एक अद्वितीय मिनिमम स्पैनिंग ट्री होने की गारंटी होती है?)

(A) When the graph is directed

(B) When all edge weights are distinct

(C) When all edge weights are equal

(D) When V is even

Correct Answer: (B)

[EN] Distinct edge weights guarantee a unique MST.

[HI] अलग-अलग किनारे के भार एक अद्वितीय MST की गारंटी देते हैं।

Q6. Which algorithmic paradigm do both Kruskal's and Prim's algorithms use?

(क्रुस्कल और प्रिम दोनों एल्गोरिदम किस एल्गोरिदमिक पैराडाइम का उपयोग करते हैं?)

(A) Dynamic Programming

(B) Divide and Conquer

(C) Backtracking

(D) Greedy

Correct Answer: (D)

[EN] Both make locally optimal edge choices proven safe by the Cut Property.

[HI] दोनों स्थानीय रूप से इष्टतम किनारे चुनते हैं।

Q7. What does Kruskal's algorithm produce if the input graph is disconnected?

(यदि इनपुट ग्राफ असंबद्ध (disconnected) है तो क्रुस्कल का एल्गोरिदम क्या उत्पन्न करता है?)

(A) A shortest path tree

(B) A single tree

(C) A Minimum Spanning Forest

(D) An infinite loop

Correct Answer: (C)

[EN] Kruskal's naturally finds the MST for each connected component.

[HI] क्रुस्कल स्वाभाविक रूप से प्रत्येक जुड़े हुए घटक के लिए MST ढूंढता है।

Q8. What is the time complexity of Prim's algorithm using an Adjacency Matrix without a heap?

(बिना हीप के एडजेसेंसी मैट्रिक्स का उपयोग करके प्रिम के एल्गोरिदम की समय जटिलता क्या है?)

(A) O(V^2)

(B) O(V log V)

(C) O(V^3)

(D) O(E log V)

Correct Answer: (A)

[EN] Scanning an array of V vertices V times takes O(V^2) time.

[HI] V शीर्षों के ऐरे को V बार स्कैन करने में O(V^2) समय लगता है।

Q9. In Prim's algorithm, what is stored in the Min-Heap priority queue?

(प्रिम के एल्गोरिदम में, मिन-हीप प्रायोरिटी क्यू में क्या स्टोर किया जाता है?)

(A) Visited vertices only

(B) Degree of each vertex

(C) Unvisited vertices keyed by their minimum connecting edge weight

(D) All edges sorted by weight

Correct Answer: (C)

[EN] The Min-Heap extracts the closest unvisited vertex to the growing tree.

[HI] मिन-हीप बढ़ते ट्री के सबसे निकटतम अनविज़िट किए गए शीर्ष को निकालता है।

Q10. Can Prim's or Kruskal's algorithm handle negative edge weights?

(क्या प्रिम या क्रुस्कल का एल्गोरिदम नकारात्मक किनारे के भार को संभाल सकता है?)

(A) No, neither works

(B) Yes, both work with negative weights

(C) Only Kruskal's works

(D) Only Prim's works

Correct Answer: (B)

[EN] MST algorithms work with any real-valued edge weights, including negative ones.

[HI] MST एल्गोरिदम नकारात्मक सहित किसी भी वास्तविक-मूल्य वाले किनारे के भार के साथ काम करते हैं।

Q11. Which MST property states that the lightest edge crossing any cut of the graph belongs to the MST?

(कौन सा MST गुण बताता है कि ग्राफ के किसी भी कट को पार करने वाला सबसे हल्का किनारा MST से संबंधित है?)

(A) Cut Property

(B) Pigeonhole Principle

(C) Cycle Property

(D) Triangle Inequality

Correct Answer: (A)

[EN] The Cut Property is the theoretical foundation of Prim's and Kruskal's.

[HI] कट प्रॉपर्टी प्रिम और क्रुस्कल की सैद्धांतिक नींव है।

Q12. Which MST property states that the heaviest edge in any cycle cannot be in the MST (for distinct weights)?

(कौन सा MST गुण बताता है कि किसी भी चक्र में सबसे भारी किनारा MST में नहीं हो सकता?)

(A) Handshaking Lemma

(B) Cut Property

(C) Cycle Property

(D) Master Theorem

Correct Answer: (C)

[EN] Removing the heaviest edge in a cycle always lowers or maintains total weight.

[HI] चक्र में सबसे भारी किनारे को हटाने से कुल भार कम होता है।

Q13. How does Prim's algorithm differ from Dijkstra's shortest path algorithm?

(प्रिम का एल्गोरिदम डिक्जस्ट्रा के शॉर्टेस्ट पाथ एल्गोरिदम से कैसे भिन्न है?)

(A) Prim's uses a stack; Dijkstra's uses a queue

(B) Prim's tracks minimum edge weight to the tree; Dijkstra's tracks total distance from source

(C) They are completely unrelated

(D) Dijkstra's works on undirected graphs only

Correct Answer: (B)

[EN] Both use a Min-Heap, but their relaxation key formulas differ.

[HI] दोनों मिन-हीप का उपयोग करते हैं, लेकिन उनके की-फ़ॉर्मूले अलग हैं।

Q14. If a graph has 10 vertices and all edge weights are 5, what is the weight of its MST?

(यदि एक ग्राफ में 10 शीर्ष हैं और सभी किनारों का भार 5 है, तो इसके MST का भार क्या होगा?)

(A) 5

(B) 50

(C) 45

(D) 40

Correct Answer: (C)

[EN] An MST has V - 1 = 9 edges; 9 * 5 = 45.

[HI] एक MST में V - 1 = 9 किनारे होते हैं; 9 * 5 = 45।

Q15. Which optimization in Union-Find reduces tree height during find()?

(Union-Find में कौन सा ऑप्टिमाइजेशन find() के दौरान ट्री की ऊंचाई कम करता है?)

(A) Hashing

(B) Binary Search

(C) Memoization

(D) Path Compression

Correct Answer: (D)

[EN] Path Compression flattens the structure by pointing nodes directly to the root.

[HI] पाथ कम्प्रेशन नोड्स को सीधे रूट की ओर इंगित करके संरचना को समतल करता है।

Q16. Which algorithm is best suited for finding an MST in a sparse graph?

(स्पार्स ग्राफ में MST खोजने के लिए कौन सा एल्गोरिदम सबसे उपयुक्त है?)

(A) Floyd-Warshall

(B) Topological Sort

(C) Prim's with Adjacency Matrix

(D) Kruskal's algorithm

Correct Answer: (D)

[EN] When E = O(V), Kruskal's O(E log E) is very fast.

[HI] जब E = O(V), तो क्रुस्कल का O(E log E) बहुत तेज़ होता है।

Q17. Within Minimum Spanning Tree: Kruskal's vs Prim's Greedy Algorithms, which algorithm directly maps to: "O(E log E)"?

(Minimum Spanning Tree: Kruskal's vs Prim's Greedy Algorithms में कौन सा Algorithm सीधे "O(E log E)" से संबंधित है?)

(A) Prim's (Adj Matrix)

(B) Prim's (Binary Heap)

(C) Prim's (Fibonacci Heap)

(D) Kruskal's (Union-Find)

Correct Answer: (D)

[EN] In Minimum Spanning Tree: Kruskal's vs Prim's Greedy Algorithms, 'Kruskal's (Union-Find)' handles 'O(E log E)' (Best for sparse graphs; sorts all edges).

[HI] Minimum Spanning Tree: Kruskal's vs Prim's Greedy Algorithms में 'Kruskal's (Union-Find)' का कार्य/विवरण 'O(E log E)' (Best for sparse graphs; sorts all edges) है।

Q18. Which option accurately describes 'Prim's (Binary Heap)' in Minimum Spanning Tree: Kruskal's vs Prim's Greedy Algorithms?

(Minimum Spanning Tree: Kruskal's vs Prim's Greedy Algorithms के संदर्भ में 'Prim's (Binary Heap)' की सही विशेषता कौन सी है?)

(A) O(V^2)

(B) O(E log E)

(C) O((V + E) log V)

(D) O(E + V log V)

Correct Answer: (C)

[EN] 'Prim's (Binary Heap)' provides 'O((V + E) log V)' — key point: Best for dense graphs; grows single tree.

[HI] 'Prim's (Binary Heap)' का मुख्य विवरण 'O((V + E) log V)' है (Best for dense graphs; grows single tree)।

Q19. In Minimum Spanning Tree: Kruskal's vs Prim's Greedy Algorithms, identify the correct parameter for the specification: "O(E + V log V)".

(Minimum Spanning Tree: Kruskal's vs Prim's Greedy Algorithms में "O(E + V log V)" विवरण किस विकल्प के लिए सही है?)

(A) Prim's (Fibonacci Heap)

(B) Prim's (Adj Matrix)

(C) Prim's (Binary Heap)

(D) Kruskal's (Union-Find)

Correct Answer: (A)

[EN] 'Prim's (Fibonacci Heap)' corresponds to 'O(E + V log V)' (Theoretically fastest for dense graphs).

[HI] 'Prim's (Fibonacci Heap)' का संबंध 'O(E + V log V)' (Theoretically fastest for dense graphs) से है।

Q20. Considering Minimum Spanning Tree: Kruskal's vs Prim's Greedy Algorithms, what key behavior defines 'Prim's (Adj Matrix)'?

(Minimum Spanning Tree: Kruskal's vs Prim's Greedy Algorithms में 'Prim's (Adj Matrix)' की मुख्य भूमिका या मान क्या है?)

(A) O(E log E)

(B) O(V^2)

(C) O((V + E) log V)

(D) O(E + V log V)

Correct Answer: (B)

[EN] 'Prim's (Adj Matrix)' represents 'O(V^2)' (Simple array-based; no heap needed).

[HI] 'Prim's (Adj Matrix)' का अर्थ/मान 'O(V^2)' है (Simple array-based; no heap needed)।

Minimum Spanning Tree: Kruskal's vs Prim's Greedy Algorithms — Exam FAQs

Q1: Can a graph have more than one Minimum Spanning Tree?

क्या एक ग्राफ में एक से अधिक मिनिमम स्पैनिंग ट्री हो सकते हैं?

[EN] Yes, if two or more edges share the exact same weight, multiple valid MSTs with the same minimum total weight may exist.

[HI] हाँ, यदि दो या अधिक किनारों का भार बिल्कुल समान है, तो समान न्यूनतम कुल भार वाले कई वैध MST मौजूद हो सकते हैं।

Q2: Why can't we use MST algorithms on directed graphs?

हम निर्देशित ग्राफ पर MST एल्गोरिदम का उपयोग क्यों नहीं कर सकते?

[EN] MST is defined for undirected graphs; the directed equivalent is a Minimum Spanning Arborescence (Edmonds' algorithm).

[HI] MST अनिर्देशित ग्राफ के लिए परिभाषित है; निर्देशित समतुल्य मिनिमम स्पैनिंग आर्बोरेसेंस है।

Q3: What is a real-world application of MST?

MST का वास्तविक दुनिया का अनुप्रयोग क्या है?

[EN] Designing minimum-cost fiber-optic networks, power grids, and road networks connecting all cities.

[HI] सभी शहरों को जोड़ने वाले न्यूनतम-लागत वाले फाइबर-ऑप्टिक नेटवर्क, पावर ग्रिड और सड़क नेटवर्क डिज़ाइन करना।

Related Posts

  • Loading related posts...

Post a Comment

Search Topic Notes & 20 MCQs (Hindi / English)