Multi Way Tree : परिभाषा, प्रकार, लाभ व हानियाँ

Multi-way Tree (परिभाषा)

Multi-way Tree एक non-linear hierarchical data structure है, जिसमें हर node के दो से अधिक child nodes हो सकते हैं। यह Binary Tree का generalized form हैं, क्योंकि Binary Tree में केवल दो child nodes (Left और Right) होते हैं, जबकि Multi-way Tree में n (multiple) children हो सकते हैं।

Example :

  • Binary Tree → हर node के 2 child (left, right)
  • Multi-way Tree → हर node के n child (n ≥ 2)

Mathematical Definition (गणितीय परिभाषा)

  1. Tree में किसी भी level i पर nodes की संख्या ज्ञात करनी हो तो formula होता है:
    • Maximum Nodes at Level i = M^i
  2. और किसी height (h) वाले Tree में कुल nodes की अधिकतम संख्या होती है :
    • Total Nodes = (M^(h+1) – 1) / (M – 1)

Example : अगर एक Tree में हर node के 3 child हैं (M = 3) और height = 2 है,
Total nodes  =  (3³ – 1) / (3 – 1) = 13 nodes

Properties of Multi-way Tree (विशेषताएँ)

Multi-way Tree एक ऐसा hierarchical structure है, जो Binary Tree से ज्यादा flexible और powerful होता है। इस Tree की कुछ प्रमुख विशेषताएँ (properties) निम्न हैं – 

1. Hierarchical Structure

  • Multi-way Tree एक non-linear hierarchical structure है।
  • यह data को “Root → Child → Sub-child” के रूप में store करता है।
  • उदाहरण : File System

2. Root Node

  • हर Multi-way Tree में एक root node होता है, जो पूरे Tree का base या starting point होता है। सभी other nodes उसी root के नीचे connected रहते हैं।
  • उदाहरण : Flipkart data model

3. Degree of Node

  • किसी node के children की संख्या को उसकी degree कहा जाता है। Multi-way Tree में किसी node की degree 2 से अधिक हो सकती है।
  • उदाहरण : एक node के 4 children हैं → उसकी degree = 4

4. Degree of Tree

  • किसी Tree की degree उस Tree के सभी nodes में से maximum degree वाले node की degree के बराबर होती है।
  • उदाहरण : अगर किसी Tree में किसी एक node के 5 children हैं, तो उस Tree की degree = 5 होगी।

5. Parent Node And Child Node Relationship

  • हर node का एक parent node और एक या अधिक child nodes होते हैं।
  • Root node का कोई parent नहीं होता, और leaf node का कोई child नहीं।
  • उदाहरण : University Hierarchy

6. Leaf Nodes

  • वे nodes जिनके कोई child nodes नहीं होते, Leaf nodes कहलाते हैं।
  • ये Tree की सबसे निचली layer में पाए जाते हैं।
  • उदाहरण : File System में actual files (जैसे resume.pdf, photo.jpg) Leaf nodes होती हैं।

7. Level of Node

  • किसी Tree में Root node का level हमेशा 0 (या कभी-कभी 1) माना जाता है। हर बार जब हम किसी child node की ओर बढ़ते हैं, तो level +1 बढ़ जाता है।

8. Height of Tree

  • Tree की height, Root से लेकर सबसे गहरे Leaf node तक के levels की संख्या होती है। Height data access और traversal efficiency को directly प्रभावित करती है।
  • Formula : If maximum degree = M and height = h, then maximum nodes = (M^(h+1) – 1) / (M – 1)

9. Dynamic Size

  • Multi-way Tree का size dynamic होता है। आप चाहें तो new nodes को insert कर सकते हैं या existing nodes को delete कर सकते हैं।
  • उदाहरण : File Explorer में नया folder बनाना या delete करना।

10. Traversal Capability

  • Multi-way Tree को Preorder, Postorder या Level-order तरीके से traverse किया जा सकता है। यह traversal complex तो होता है, लेकिन efficient searching और indexing के लिए जरूरी है।
  • उदाहरण : Trie Structure में string search के लिए Preorder traversal का use होता है।

11. Multi-key Node Structure

  • B-Tree या B+ Tree जैसी structures में एक node में कई keys (data values) होती हैं। यह searching efficiency बढ़ाता है।
  • उदाहरण : B – Tree Node

Representation of Multi-way Tree

Multi-way Tree को Memory में Represent करने के 2 मुख्य प्रकार होते हैं :

  1. Sequential Representation (या Array Representation)
  2. Linked List Representation

1. Sequential Representation

इस representation में Tree के सभी nodes को sequentially array में store किया जाता है। हर node को array के एक index पर रखा जाता है, और उसके children को उसी order में उसके बाद वाले indexes पर store किया जाता है।

इस तरीके में Index Number node की position और relation को define करता है।

Working Concept

  • Root node हमेशा index 1 (या 0) पर होता है।
  • किसी node के child nodes को उसके बाद वाले indexes पर रखा जाता है।
  • यदि एक node के m children हैं, तो उनके indexes sequentially assign किए जाते हैं।

उदाहरण :

                      A
                  /   |   \
              B     C     D
                    /   \
                  E      F

Sequential Representation Table :

IndexNodeChildren
1A2, 3, 4
2B
3C5, 6
4D
5E
6F

Advantages

  • Implementation आसान है।
  • Access करना fast होता है |

Disadvantages

  • Tree sparse (कम nodes वाला) है तो memory waste होती है।
  • Dynamic insertion कठिन होता है।

2. Linked List Representation

इस तरीके में प्रत्येक node को एक structure (record) के रूप में store किया जाता है, जिसमें data field और उसके सभी child nodes के pointers शामिल होते हैं। हर node के पास उतने pointers होते हैं, जितने उसके children होते हैं।

Structure Example (C-style) :

struct Node {
int data;
struct Node* firstChild;
struct Node* nextSibling;
};

Example Diagram :

Original Tree :

                A
           /    |    \
         B     C     D
              /    \
            E      F

Child-Sibling Representation :

      A → B → C → D
              |       |
         NULL    E → F

Advantages

  • Memory-efficient : इसमें केवल 2 pointers (Left-Child और Right-Sibling) की आवश्यकता होती है।
  • Traversal Easy : इसे recursion या stack की मदद से आसानी से traverse किया जा सकता है।
  • Conversion Friendly : किसी भी Multi-way Tree को इस तरीके से आसानी से Binary Tree में convert किया जा सकता है।
  • Dynamic Structure : इसमें नए nodes जोड़ना या पुराने nodes हटाना बहुत सरल होता है।

Disadvantages

  • Visualization थोड़ा complex होता है, क्योंकि original hierarchy को समझना मुश्किल होता है।
  • Parent pointer न होने के कारण upward traversal (ऊपर की ओर traversal) कठिन हो जाता है।

Types of Multi-way Trees (प्रकार)

1.  General Multi-way Tree

  • यह Multi-way Tree का basic form है, जिसमें प्रत्येक node के arbitrary number of children हो सकते हैं। इसमें children की कोई fixed limit नहीं होती।
  • उदाहरण : XML Document Structure

2.  M – Ary Tree

  • इस प्रकार के Tree में प्रत्येक node के अधिकतम M children हो सकते हैं। अगर M = 3 हो, तो Tree को Ternary Tree कहा जाएगा।
  • उदाहरण : Directory Structure में subfolders
  • Formula : Max Nodes at Level i=Mi\text{Max Nodes at Level i} = M^i

3.  B – Tree

  • B – Tree एक balanced Multi-way Search Tree होता है, जिसका उपयोग मुख्यतः Database Indexing में किया जाता है।
  • हर node में कई keys और children pointers होते हैं, जिससे searching, insertion, और deletion operations बहुत fast होते हैं।
  • उदाहरण : RDBMS systems जैसे MySQL, Oracle, और SQLite में B-Tree या B+ Tree का उपयोग होता है।

4.  B+ Tree

  • B+ Tree, B-Tree का advanced version है। इसमें सभी leaf nodes आपस में linked list के रूप में जुड़े होते हैं, जिससे sequential access बहुत fast हो जाता है।
  • Use Case : Databases, File Systems (जैसे NTFS, ext4)

5. Trie (Prefix Tree)

  • Trie एक Multi-way Tree है जो string data को efficiently store और search करता है। इसमें हर edge किसी character को represent करती है।
  • Use Case : Dictionary Apps, Autocomplete Feature (जैसे Google Search, Paytm App)

6. Quad Tree

  • Quad Tree का उपयोग 2D space को चार बराबर भागों में divide करने के लिए किया जाता है।यह graphics, image compression और spatial indexing में बेहद उपयोगी है।
  • Use Case : Google Maps, ISRO’s Satellite Image Storage Systems

7. Octree

  • Octree का उपयोग 3D applications में किया जाता है। इसमें प्रत्येक node के 8 children होते हैं, जो 3D space को आठ भागों में बाँटते हैं।
  • Use Case : 3D Graphics, Gaming Engines, AR/VR Simulations

Operations on Multi-way Tree

क्रमांक

Operation (ऑपरेशन)

Definition (परिभाषा)

Steps / Working (कार्यविधि)

Example (उदाहरण)

1

Creation

Tree को initialize करने और Root node बनाने की प्रक्रिया।

1. Root node create करें।
2. प्रत्येक node के लिए pointer allocate करें।
3. Parent-child संबंध स्थापित करें।

Root = 10
Children = 20, 30, 40

2

Insertion

किसी existing Tree में नया node जोड़ने की प्रक्रिया।

1. Parent node identify करें।
2. नया node create करें।
3. Parent की child list में जोड़ें।

“C” node के नीचे “E” add करना।

3

Deletion

Tree से किसी node या subtree को हटाने की प्रक्रिया।

1. Node खोजें।
2. उसके children को handle करें।
3. Memory free करें।

“C” node delete करने पर subtree (E, F) भी हट जाएगा।

4

Searching

किसी particular data या node को ढूँढना।

1. DFS या BFS method use करें।
2. हर node का data check करें।

A → B → C → E → F में “F” खोजें।

6

Counting Nodes

Tree में कुल nodes की संख्या निकालना।

1. हर node visit करें।
2. Counter बढ़ाएँ।
3. Recursive तरीके से सब जोड़ें।

A, B, C, D, E, F → Total = 6

7

Checking Empty

Tree में कोई node है या नहीं।

1. अगर Root == NULL → Empty
2. अन्यथा Non-empty

Root == NULL → “Tree Empty”

8

Destroy / Delete Tree

पूरे Tree की memory free करना।

1. हर node के children delete करें।
2. Root को free करें।

Destroy(root)

Advantages of Multi-way Tree (लाभ)

  1. Multiple Children Support : Multi-way Tree में किसी भी node के एक से अधिक children हो सकते हैं। इससे complex hierarchical data, जैसे –  File System, Organization Chart आदि को आसानी से represent किया जा सकता है।
  2. Better Data Organization : यह Tree data को एक structured hierarchy में store करता है, जिससे search, insertion, और deletion operations आसान हो जाते हैं।
  3. Reduced Tree Height : हर node के कई children होने के कारण Tree की height कम होती है, जिससे search और traversal तेज़ हो जाता है।
  4. Fast Searching : हर node में कई keys और pointers होने से data को जल्दी locate किया जा सकता है।
  5. Flexible Data Insertion : किसी भी node के नीचे नया node आसानी से जोड़ा जा सकता है।

Disadvantages of Multi-way Tree (हानियाँ)

1. Complex Implementation

  • Multi-way Tree को बनाना और maintain करना आसान नहीं होता।
  • हर node के कई children और pointers होने के कारण इसका code structure काफी जटिल हो जाता है।

2. Memory Overhead

  • हर node में multiple pointers और keys store करनी पड़ती हैं।
  • इससे memory consumption बढ़ जाता है और large datasets में storage की आवश्यकता बहुत अधिक हो जाती है।

3. Difficult Traversal

  • Multi-way Tree में traversal, Binary Tree की तुलना में ज्यादा complex होता है।
  • Nodes की संख्या अधिक और hierarchy गहरी होने से extra loops या recursion की आवश्यकता होती है।

4. Balancing Problem

  • Tree के बढ़ने के साथ उसकी structure unbalanced हो सकती है।
  • Rebalancing की प्रक्रिया कठिन और time-consuming होती है।

5. Insertion & Deletion Overhead

  • नए nodes जोड़ने या पुराने delete करने पर pointers को बार-बार adjust करना पड़ता है।
  • इससे performance पर नकारात्मक असर पड़ सकता है।

6. High Maintenance

  • जैसे-जैसे Tree बड़ा होता जाता है, उसका maintenance कठिन होता जाता है। Balancing, node splitting, और restructuring जैसी प्रक्रियाएँ समय और resources दोनों मांगती हैं।

7. Complex Memory Management

  • Dynamic memory allocation के कारण fragmentation और inefficiency की समस्या होती है। साथ ही garbage collection भी कठिन हो जाती है।
error: Content is protected !!