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 के फायदे
- Dynamic Size – इसमें नए nodes आसानी से जोड़े जा सकते हैं।
- Memory Efficient – इसमें सिर्फ उतनी ही मेमोरी का इस्तेमाल होता है, जितने nodes हैं।
- 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 के फायदे:-
- Random Access – इसमें किसी भी नोड को सीधे एक्सेस कर सकते हैं।
- No Pointers – इसमें extra memory की जरूरत नहीं पड़ती है।
Array Representation के नुकसान:-
- Fixed Size – इसमें पहले से ही array का साइज तय करना पड़ता है।
- Memory Waste – अगर Tree complete नहीं है, तो खाली जगह बर्बाद होती है। जिससे मेमोरी waste होती है।
इसे पढ़ें:-
Summary (सारांश)
Tree Data Structure में hierarchy को store करने के दो मुख्य तरीके हैं – Linked Representation और Array Representation। यह article इन दोनों को विस्तार से समझाता है। Linked Representation में हर node में data, left pointer और right pointer होता है, जो dynamic memory allocation और flexible tree creation (जैसे Binary, BST, AVL) की सुविधा देता है। Array Representation में root index 0 पर होता है और left child (2*i+1), right child (2*i+2) formula से access होता है, जिससे random access आसान है लेकिन fixed size और incomplete tree में memory waste हो सकती है। इस article से छात्र सीखेंगे:
- Tree को represent करने के दो तरीकों की पूरी समझ
- Linked Representation के फायदे (dynamic size, memory efficient)
- Array Representation के फायदे और नुकसान (random access, fixed size)
- Binary Tree के struct Node और array index formulas का practical use