Representation of Tree in Hindi – Data Structure

Tree एक non-linear डेटा स्ट्रक्चर है जिसका इस्तेमाल hierarchical डेटा को organize करने के लिए किया जाता है। Tree को मुख्य रूप से दो तरीकों से represent किया जाता है:-

1:- Linked Representation (Dynamic Representation)

Linked representation में, प्रत्येक node को एक structure के रूप में प्रस्तुत किया जाता है, जिसमें तीन हिस्से होते हैं:

  • Data – यह Node में store होने वाली value है।
  • Left Pointer – यह Left Child को point करता है।
  • Right Pointer यह Right Child को point करता है।

उदाहरण: Binary Tree का Linked Representation

struct Node {
    int data;           // data
    struct Node* left;  // left pointer
    struct Node* right; // right pointer
};

Linked Representation के फायदे

  1. Dynamic Size – इसमें नए nodes आसानी से जोड़े जा सकते हैं।
  2. Memory Efficient – इसमें सिर्फ उतनी ही मेमोरी का इस्तेमाल होता है, जितने nodes हैं।
  3. Flexible – इससे किसी भी तरह का Tree (Binary, BST, AVL) बना सकते हैं।

2:- Array Representation (Static Representation)

Array Representation में tree को array के रूप में store किया जाता है, जहाँ:

  • Root node index 0 होता है।
  • Left child का index: 2 * i + 1 होता है।
  • Right child का index:2 * i + 2 होता है।
  • Parent node का index: (i-1)/2 होता है।

उदाहरण: Binary Tree का Array Representation

Array Representation of Tree in Data Structure in Hindi

Array Representation के फायदे:-

  1. Random Access – इसमें किसी भी नोड को सीधे एक्सेस कर सकते हैं।
  2. No Pointers – इसमें extra memory की जरूरत नहीं पड़ती है।

Array Representation के नुकसान:-

  1. Fixed Size – इसमें पहले से ही array का साइज तय करना पड़ता है।
  2. Memory Waste – अगर Tree complete नहीं है, तो खाली जगह बर्बाद होती है। जिससे मेमोरी waste होती है।

इसे पढ़ें:-

Leave a Comment