PGDCA, BCA, B-Tech, MCA, M-Tech, B.Sc computer science राजस्थान सूचना सहायक व कंप्यूटर शिक्षक विशेष नोट्स: इस अध्याय में हम Linear vs Non-Linear Data Structures: Array, Stack vs Tree, Graph (लीनियर बनाम नॉन-लीनियर डेटा स्ट्रक्चर्स: संरचना, मेमोरी और अंतर) की संपूर्ण थ्योरी, मुख्य तकनीकी बिंदु, तुलनात्मक तालिका और विगत परीक्षाओं के पैटर्न पर आधारित 20 अति-महत्वपूर्ण बहुविकल्पीय प्रश्न (MCQs) विस्तृत हिंदी व अंग्रेजी व्याख्या सहित पढ़ेंगे।
Overview: Linear data structures (Array, Linked List, Stack, Queue) arrange elements sequentially on a single level, whereas non-linear structures (Tree, Heap, Graph) organize hierarchical or networked many-to-many links.
अध्याय सार: लीनियर डेटा स्ट्रक्चर्स (Array, Linked List, Stack, Queue) डेटा को एक क्रमिक स्तर में व्यवस्थित करते हैं, जबकि नॉन-लीनियर स्ट्रक्चर्स (Tree, Heap, Graph) पदानुक्रमित या नेटवर्क्ड बहु-स्तरीय संबंध दर्शाते हैं।
Linear vs Non-Linear Data Structures: Array, Stack vs Tree, Graph: Detailed Notes & Architecture (लीनियर बनाम नॉन-लीनियर डेटा स्ट्रक्चर्स: संरचना, मेमोरी और अंतर)
1. Logical Adjacency: Single-Level Sequence vs Hierarchy & Networks (तार्किक संरचना: एकल-स्तरीय अनुक्रम बनाम पदानुक्रम और नेटवर्क)
[EN] Linear data structures organize items along a single logical level where every element (except the first and last) has at most one predecessor and one successor—classic examples include Arrays, Linked Lists, Stacks (LIFO), and Queues (FIFO). Non-Linear data structures arrange items across multiple hierarchical or interconnected levels where one element can link to many elements—such as Trees (one-to-many parent-child hierarchy without cycles) and Graphs (many-to-many connections permitting cycles).
[HI] लीनियर डेटा स्ट्रक्चर में डेटा एक ही स्तर (Single Level) पर क्रमानुसार जुड़ा होता है—पहले और अंतिम तत्व को छोड़कर हर तत्व का केवल एक पूर्ववर्ती (Predecessor) और एक अनुवर्ती (Successor) होता है (जैसे Array, Linked List, Stack, Queue)। इसके विपरीत नॉन-लीनियर संरचनाओं (जैसे Tree और Graph) में डेटा बहु-स्तरीय होता है जहाँ एक नोड अनेक नोड्स से जुड़ सकता है।
2. Physical Memory Layout, Pointer Overhead, and Cache Locality (मेमोरी व्यवस्था, पॉइंटर ओवरहेड और कैश लोकैलिटी)
[EN] A frequent exam misconception confuses physical RAM contiguity with linearity: a Linked List IS strictly Linear despite its nodes sitting scattered in heap memory, because its logical adjacency is sequential! Arrays use contiguous RAM enabling O(1) random index calculation (`base + i * sizeof(elem)`) and superior CPU spatial cache locality, whereas pointer-based Linked Lists, Trees, and Graph Adjacency Lists spend extra bytes storing pointers/references per node. Conversely, non-linear Binary Heaps are often embedded linearly inside an array (`left = 2i + 1`, `right = 2i + 2`).
[HI] एक आम भ्रम यह है कि Linked List मेमोरी में बिखरी होने के कारण नॉन-लीनियर है—यह गलत है, तार्किक अनुक्रम के कारण Linked List पूरी तरह लीनियर है! Array सन्निहित (Contiguous) मेमोरी में रहकर O(1) रैंडम एक्सेस और बेहतरीन CPU कैश लोकैलिटी देता है, जबकि Tree व Linked List में पॉइंटर मेमोरी खर्च होती है। वहीं नॉन-लीनियर Binary Heap को भी `left=2i+1` सूत्र से Array में स्टोर किया जा सकता है।
3. Traversal Strategies: Single Pass vs Graph/Tree Algorithms (ट्रैवर्सल विधियाँ: सिंगल लूप बनाम ट्री/ग्राफ एल्गोरिदम)
[EN] Every linear structure can be completely visited in a single sequential O(n) pass using a simple `for` or `while` loop without auxiliary stacks or visited trackers. Non-linear structures involve branching and potential cycles, prohibiting a single linear loop: Trees require recursive or stack/queue traversals (Preorder, Inorder, Postorder, Level-order), while Graphs mandate Breadth-First Search (BFS using a Queue) or Depth-First Search (DFS using a Stack/Recursion plus a `visited` array to prevent infinite loops).
[HI] किसी भी लीनियर संरचना को एक साधारण `for` या `while` लूप द्वारा एक ही सिंगल पास में पूरा पढ़ा जा सकता है। इसके विपरीत, नॉन-लीनियर संरचनाओं में शाखाएँ और चक्र (Cycles) होने के कारण विशेष ट्रैवर्सल लगते हैं: Tree में Preorder/Inorder/Postorder/Level-order, तथा Graph में Queue आधारित BFS या Stack आधारित DFS (Visited सेट सहित) उपयोग होता है।
4. Time Complexity Tradeoffs and Real-World Engineering Selection (टाइम कॉम्प्लेक्सिटी तुलना और व्यावहारिक चयन)
[EN] Unsorted linear lists require O(n) linear search, and even a Sorted Array (which enables O(log n) Binary Search) suffers O(n) element-shifting during middle insertions/deletions. Balanced non-linear search trees (AVL, Red-Black Trees, B-Trees) sustain O(log n) search, insertion, and deletion simultaneously, making them ideal for database indexes and file systems, while Graphs power GPS shortest paths, social networks, and compiler dependency DAGs.
[HI] अक्रमबद्ध लीनियर सूची में खोजने में O(n) समय लगता है और सॉर्टेड ऐरे में भी बीच में इंसर्ट/डिलीट करने पर तत्व खिसकाने में O(n) खर्च होता है। वहीं संतुलित नॉन-लीनियर ट्री (AVL, Red-Black, B-Tree) खोजने, जोड़ने और हटाने तीनों में O(log n) गति देते हैं (डेटाबेस इंडेक्स हेतु उपयुक्त), और Graph मैप रूटिंग व सोशल नेटवर्क में काम आते हैं।
Syntax, Formula & Technical Example (Linear vs Non-Linear Data Structures: Array, Stack vs Tree, Graph)
// Linear Random Access (Array) vs Non-Linear Heap-in-Array & BFS Traversal
int addr = base_address + index * sizeof(int); // O(1) Array offset
// Non-linear Complete Binary Tree (Heap) mapped onto 0-based Array:
int parent(int i) { return (i - 1) / 2; }
int left(int i) { return 2 * i + 1; }
int right(int i) { return 2 * i + 2; }
// Non-linear Graph traversal uses Queue (BFS) or Stack (DFS) + visited[]
Linear vs Non-Linear Data Structures: Array, Stack vs Tree, Graph Quick Reference & Comparison Table
| Comparison Dimension | Linear Data Structures | Non-Linear Data Structures |
|---|---|---|
| Logical Arrangement | Sequential single level; at most 1 predecessor & 1 successor | Hierarchical (Tree) or network (Graph) multi-level links |
| Memory Utilization | Contiguous blocks (Array) or sequential linked heap nodes | Typically scattered pointer nodes (or Heap array/Adjacency Matrix) |
| Traversal Method | Complete scan achievable in a single O(n) loop pass | Requires DFS, BFS, or recursive hierarchical traversals |
| Classic Examples | Array, Linked List, Stack (LIFO), Queue (FIFO) | Binary Tree, BST, AVL Tree, Heap, Graph, Trie |
Linear vs Non-Linear Data Structures: Array, Stack vs Tree, Graph Top 20 Bilingual MCQs with Answers
Q1. What defines a data structure as 'Linear' in computer science?
(कंप्यूटर विज्ञान में किसी डेटा स्ट्रक्चर को 'लीनियर' (Linear) किस आधार पर कहा जाता है?)
(A) Elements are logically arranged sequentially on a single level with at most one predecessor and one successor
(B) Elements are always stored contiguously in physical RAM
(C) Elements cannot be deleted once inserted
(D) Only integers can be stored inside it
Correct Answer: (A)
[EN] Linearity refers to logical sequential adjacency—not physical contiguity (hence Linked Lists are linear).
[HI] लीनियरिटी का अर्थ एक स्तर पर क्रमिक तार्किक जुड़ाव है (एक पूर्ववर्ती व एक अनुवर्ती), न कि केवल सन्निहित मेमोरी।
Q2. Is a Singly Linked List classified as Linear or Non-Linear, and why?
(सिंगली लिंक्ड लिस्ट (Singly Linked List) को लीनियर माना जाता है या नॉन-लीनियर, और क्यों?)
(A) Linear — because nodes follow a strict sequential one-to-one logical chain despite non-contiguous RAM addresses
(B) Non-Linear — because nodes sit scattered in heap memory
(C) Neither — it is a file structure
(D) Non-Linear — because it uses pointers
Correct Answer: (A)
[EN] Physical scattering in heap RAM does not change its 1-predecessor / 1-successor sequential topology.
[HI] मेमोरी में अलग-अलग पतों पर होने के बावजूद लिंक्ड लिस्ट का तार्किक क्रम एक-के-बाद-एक होने से यह लीनियर ही है।
Q3. Which of the following is strictly a Non-Linear data structure?
(निम्नलिखित में से कौन सा एक नॉन-लीनियर डेटा स्ट्रक्चर है?)
(A) Doubly Linked List
(B) Binary Search Tree (and Graph / Heap)
(C) Stack
(D) Circular Queue
Correct Answer: (B)
[EN] Stack, Circular Queue, and Doubly Linked List are all single-level linear structures; Trees and Graphs are non-linear.
[HI] Stack, Circular Queue और Doubly Linked List लीनियर हैं; Binary Search Tree व Graph नॉन-लीनियर हैं।
Q4. Given 0-based array indexing for an array of 4-byte integers starting at address 2000, what is the O(1) memory address of `arr[5]`?
(यदि 4-बाइट पूर्णांकों के 0-आधारित ऐरे का बेस पता 2000 है, तो `arr[5]` का मेमोरी पता क्या होगा?)
(A) O(n) scan needed
(B) 2024
(C) 2005
(D) 2020 (2000 + 5 × 4)
Correct Answer: (D)
[EN] Contiguous layout allows direct arithmetic calculation `base + index * size` in constant O(1) time.
[HI] सन्निहित मेमोरी में `base + index * size = 2000 + 5 * 4 = 2020` की गणना O(1) समय में हो जाती है।
Q5. Which pair matches the exact operational discipline of Stack vs Queue?
(Stack और Queue के कार्य सिद्धांत का सही युग्म कौन सा है?)
(A) Stack = LIFO (Last-In First-Out); Queue = FIFO (First-In First-Out)
(B) Both follow FIFO
(C) Stack = Hierarchical; Queue = Cyclical
(D) Stack = FIFO; Queue = LIFO
Correct Answer: (A)
[EN] Stacks push/pop from one top end (LIFO); Queues enqueue at rear and dequeue from front (FIFO).
[HI] Stack LIFO (अंतिम अंदर, पहले बाहर) और Queue FIFO (पहले अंदर, पहले बाहर) सिद्धांत पर चलते हैं।
Q6. When storing a non-linear Complete Binary Tree (Heap) in a 0-based linear array, what are the left and right child indices of node `i`?
(0-आधारित ऐरे में नॉन-लीनियर Binary Heap स्टोर करने पर नोड `i` के बाएँ और दाएँ चिल्ड्रन के इंडेक्स क्या होते हैं?)
(A) left = 2i, right = 2i + 1
(B) left = i / 2, right = i * 2
(C) left = 2i + 1, right = 2i + 2
(D) left = i + 1, right = i + 2
Correct Answer: (C)
[EN] Under 0-based indexing, root is 0, its children are 1 and 2; under 1-based indexing, children are 2i and 2i + 1.
[HI] 0-आधारित इंडेक्स में बायाँ चाइल्ड `2i + 1` और दायाँ चाइल्ड `2i + 2` होता है।
Q7. Why do Graph traversal algorithms (DFS/BFS) require an extra `visited` boolean array unlike Linked List traversal?
(लिंक्ड लिस्ट के विपरीत Graph ट्रैवर्सल (DFS/BFS) में एक अतिरिक्त `visited` ऐरे की आवश्यकता क्यों पड़ती है?)
(A) Graphs lack memory pointers
(B) Graphs can contain cycles (closed loops), which would cause infinite traversal without tracking visited nodes
(C) Visited arrays make DFS O(1)
(D) Linked lists always contain cycles
Correct Answer: (B)
[EN] Because Graphs allow cyclic paths and multiple paths to the same vertex, `visited[]` prevents revisiting nodes infinitely.
[HI] ग्राफ में चक्र (Cycles) हो सकते हैं, इसलिए पहले देखे गए नोड को दोबारा अनंत लूप में जाने से रोकने हेतु `visited[]` जरूरी है।
Q8. Why is sequential traversal of an Array often noticeably faster in practice than a Linked List of identical size and O(n) complexity?
(समान आकार और O(n) कॉम्प्लेक्सिटी होने पर भी व्यवहार में Array का ट्रैवर्सल Linked List से काफी तेज़ क्यों होता है?)
(A) CPU registers forbid pointers
(B) Linked Lists run in O(n^2) time
(C) Contiguous array elements exploit CPU spatial cache locality (cache lines), whereas pointer chasing incurs cache misses
(D) Arrays skip half of their elements
Correct Answer: (C)
[EN] Modern CPUs prefetch contiguous memory blocks into L1/L2 cache lines automatically.
[HI] Array के तत्व पास-पास होने से CPU कैश (Spatial Cache Locality) का पूरा लाभ मिलता है, जबकि Linked List में पॉइंटर छलांग से कैश मिस होते हैं।
Q9. What structural property distinguishes a Tree from a general Graph?
(एक Tree और एक सामान्य Graph के बीच मुख्य संरचनात्मक अंतर क्या है?)
(A) A Tree can have cycles while Graphs cannot
(B) Graphs always have a single root node
(C) A Tree is a connected acyclic graph with N vertices and strictly N - 1 edges; Graphs may have cycles or disconnected parts
(D) Trees cannot be represented in RAM
Correct Answer: (C)
[EN] Every Tree has a unique simple path between any two vertices and zero cycles.
[HI] Tree एक जुड़ा हुआ चक्र-रहित (Acyclic) ग्राफ है जिसमें N शीर्षों पर ठीक N - 1 किनारे होते हैं, जबकि Graph में चक्र हो सकते हैं।
Q10. Compare worst-case search, insertion, and deletion in a Sorted Array vs a Balanced Binary Search Tree (AVL/Red-Black).
(सॉर्टेड Array बनाम संतुलित BST (AVL/Red-Black) में सर्च, इंसर्ट और डिलीट के वर्स्ट-केस समय की तुलना करें।)
(A) Sorted Array: all O(1); Balanced BST: all O(n)
(B) Sorted Array: Search O(log n), Insert/Delete O(n); Balanced BST: Search/Insert/Delete all O(log n)
(C) Balanced BST requires O(n^2) for search
(D) Both achieve O(1) across all three operations
Correct Answer: (B)
[EN] Sorted Arrays suffer O(n) element shifting on updates, whereas balanced trees maintain O(log n) dynamically.
[HI] सॉर्टेड ऐरे में अपडेट करने पर तत्व खिसकाने में O(n) लगता है, जबकि संतुलित ट्री तीनों कार्य O(log n) में कर देता है।
Q11. How many total edges exist in an undirected complete Graph of V vertices vs a Tree of V vertices?
(V शीर्षों वाले एक पूर्ण ग्राफ (Complete Graph) और एक Tree में कुल किनारों (Edges) की संख्या क्रमशः कितनी होती है?)
(A) Complete Graph: V(V - 1) / 2 edges; Tree: V - 1 edges
(B) Complete Graph: V - 1; Tree: V^2
(C) Complete Graph: 2^V; Tree: log V
(D) Both have V edges
Correct Answer: (A)
[EN] A complete simple graph connects every pair of vertices C(V, 2) = V(V - 1)/2, while a minimal connected tree has V - 1 edges.
[HI] पूर्ण ग्राफ में V(V-1)/2 किनारे और Tree में ठीक V-1 किनारे होते हैं।
Q12. Which Queue variant is ideal for Breadth-First Search (BFS) on a Graph, and what category does that helper Queue belong to?
(Graph पर BFS चलाने के लिए किस सहायक डेटा स्ट्रक्चर की आवश्यकता होती है और वह किस श्रेणी का है?)
(A) Hash Table — a Graph structure
(B) Binary Heap — a Linear structure
(C) LIFO Stack — a Non-Linear structure
(D) FIFO Queue — a Linear data structure used to traverse a Non-Linear Graph
Correct Answer: (D)
[EN] Linear FIFO Queue manages frontier vertices level-by-level during non-linear Graph BFS.
[HI] नॉन-लीनियर Graph के BFS ट्रैवर्सल में लीनियर FIFO Queue सहायता करता है।
Q13. Which real-world scenario is BEST modeled using a Non-Linear Graph rather than a Tree or Array?
(इनमें से कौन सा वास्तविक परिदृश्य Tree या Array के बजाय नॉन-लीनियर Graph से सबसे बेहतर ढंग से दर्शाया जाता है?)
(A) Printer job spooling queue
(B) Alphabetical roll-call attendance register
(C) City highway network with intersecting roads, multiple routes, and bidirectional traffic
(D) Browser Back button undo stack
Correct Answer: (C)
[EN] Intersecting road networks form cycles and multiple alternate paths—classic weighted Graph modeling.
[HI] सड़कों का जाल जहाँ एक शहर से दूसरे शहर तक कई मार्ग और चक्र बनते हैं, वेटेड Graph का श्रेष्ठ उदाहरण है।
Q14. How many logical levels exist in a Linear data structure compared to a Non-Linear data structure?
(नॉन-लीनियर डेटा स्ट्रक्चर की तुलना में लीनियर डेटा स्ट्रक्चर में कितने तार्किक स्तर (Levels) होते हैं?)
(A) Linear has a single level; Non-Linear spans multiple hierarchical or networked levels
(B) Linear has infinite levels
(C) Linear has 2 levels; Non-Linear has 1
(D) Both always have log(n) levels
Correct Answer: (A)
[EN] Linear structures align data on one flat dimension, whereas Trees/Graphs branch across depths/levels.
[HI] लीनियर डेटा स्ट्रक्चर में केवल 1 स्तर होता है, जबकि नॉन-लीनियर में अनेक स्तर या शाखाएँ होती हैं।
Q15. Does implementing a Queue using a Circular Array turn it into a Non-Linear data structure?
(क्या Circular Array की मदद से Queue बनाने पर वह नॉन-लीनियर डेटा स्ट्रक्चर बन जाता है?)
(A) Only when the queue is half full
(B) Yes — because index wraps around modulo capacity
(C) Yes — it becomes a Tree
(D) No — the logical abstraction remains strictly sequential FIFO, so a Circular Queue is Linear
Correct Answer: (D)
[EN] Wrapping physical array indices modulo N simply avoids wasted space; logical ordering remains one-predecessor/one-successor FIFO.
[HI] सर्कुलर ऐरे केवल मेमोरी पुनः उपयोग की तकनीक है; Queue की तार्किक संरचना अब भी लीनियर FIFO ही रहती है।
Q16. Which statement is NOT true comparing Linear and Non-Linear Data Structures?
(लीनियर और नॉन-लीनियर डेटा स्ट्रक्चर्स की तुलना में कौन सा कथन असत्य (NOT true) है?)
(A) Linked Lists are Linear despite scattered memory nodes
(B) Every Non-Linear structure consumes strictly less memory per element than an Array
(C) Trees and Graphs cannot be traversed meaningfully in a single flat loop without stack/queue/recursion
(D) Arrays allow O(1) random access whereas Linked Lists require O(n) traversal
Correct Answer: (B)
[EN] Pointer-based Trees and Graphs actually use MORE memory per element than Arrays because they store child/neighbor pointers alongside data.
[HI] पॉइंटर-आधारित ट्री और ग्राफ डेटा के साथ अतिरिक्त पॉइंटर भी स्टोर करते हैं, इसलिए वे Array से अधिक मेमोरी लेते हैं (कम नहीं)।
Q17. Within Linear vs Non-Linear Data Structures: Array, Stack vs Tree, Graph, which comparison dimension directly maps to: "Sequential single level; at most 1 predecessor & 1 successor"?
(Linear vs Non-Linear Data Structures: Array, Stack vs Tree, Graph में कौन सा Comparison Dimension सीधे "Sequential single level; at most 1 predecessor & 1 successor" से संबंधित है?)
(A) Memory Utilization
(B) Traversal Method
(C) Logical Arrangement
(D) Classic Examples
Correct Answer: (C)
[EN] In Linear vs Non-Linear Data Structures: Array, Stack vs Tree, Graph, 'Logical Arrangement' handles 'Sequential single level; at most 1 predecessor & 1 successor' (Hierarchical (Tree) or network (Graph) multi-level links).
[HI] Linear vs Non-Linear Data Structures: Array, Stack vs Tree, Graph में 'Logical Arrangement' का कार्य/विवरण 'Sequential single level; at most 1 predecessor & 1 successor' (Hierarchical (Tree) or network (Graph) multi-level links) है।
Q18. Which option accurately describes 'Memory Utilization' in Linear vs Non-Linear Data Structures: Array, Stack vs Tree, Graph?
(Linear vs Non-Linear Data Structures: Array, Stack vs Tree, Graph के संदर्भ में 'Memory Utilization' की सही विशेषता कौन सी है?)
(A) Contiguous blocks (Array) or sequential linked heap nodes
(B) Array, Linked List, Stack (LIFO), Queue (FIFO)
(C) Sequential single level; at most 1 predecessor & 1 successor
(D) Complete scan achievable in a single O(n) loop pass
Correct Answer: (A)
[EN] 'Memory Utilization' provides 'Contiguous blocks (Array) or sequential linked heap nodes' — key point: Typically scattered pointer nodes (or Heap array/Adjacency Matrix).
[HI] 'Memory Utilization' का मुख्य विवरण 'Contiguous blocks (Array) or sequential linked heap nodes' है (Typically scattered pointer nodes (or Heap array/Adjacency Matrix))।
Q19. In Linear vs Non-Linear Data Structures: Array, Stack vs Tree, Graph, identify the correct parameter for the specification: "Complete scan achievable in a single O(n) loop pass".
(Linear vs Non-Linear Data Structures: Array, Stack vs Tree, Graph में "Complete scan achievable in a single O(n) loop pass" विवरण किस विकल्प के लिए सही है?)
(A) Classic Examples
(B) Logical Arrangement
(C) Memory Utilization
(D) Traversal Method
Correct Answer: (D)
[EN] 'Traversal Method' corresponds to 'Complete scan achievable in a single O(n) loop pass' (Requires DFS, BFS, or recursive hierarchical traversals).
[HI] 'Traversal Method' का संबंध 'Complete scan achievable in a single O(n) loop pass' (Requires DFS, BFS, or recursive hierarchical traversals) से है।
Q20. Considering Linear vs Non-Linear Data Structures: Array, Stack vs Tree, Graph, what key behavior defines 'Classic Examples'?
(Linear vs Non-Linear Data Structures: Array, Stack vs Tree, Graph में 'Classic Examples' की मुख्य भूमिका या मान क्या है?)
(A) Array, Linked List, Stack (LIFO), Queue (FIFO)
(B) Sequential single level; at most 1 predecessor & 1 successor
(C) Contiguous blocks (Array) or sequential linked heap nodes
(D) Complete scan achievable in a single O(n) loop pass
Correct Answer: (A)
[EN] 'Classic Examples' represents 'Array, Linked List, Stack (LIFO), Queue (FIFO)' (Binary Tree, BST, AVL Tree, Heap, Graph, Trie).
[HI] 'Classic Examples' का अर्थ/मान 'Array, Linked List, Stack (LIFO), Queue (FIFO)' है (Binary Tree, BST, AVL Tree, Heap, Graph, Trie)।
Linear vs Non-Linear Data Structures: Array, Stack vs Tree, Graph — Exam FAQs
Q1: Why is a Linked List considered Linear if its nodes are scattered randomly in RAM?
यदि Linked List के नोड्स RAM में अलग-अलग स्थानों पर बिखरे होते हैं, तो उसे लीनियर क्यों कहा जाता है?
[EN] Linear vs Non-Linear classifies *logical adjacency*, not physical RAM layout. Each Linked List node points sequentially to just one next node on a single logical chain.
[HI] लीनियर या नॉन-लीनियर का वर्गीकरण भौतिक मेमोरी पर नहीं बल्कि तार्किक क्रम पर निर्भर करता है। लिंक्ड लिस्ट में हर नोड केवल एक अगले नोड से क्रमानुसार जुड़ा होता है।
Q2: Can a Non-Linear structure like a Binary Tree ever be stored inside a Linear Array?
क्या Binary Tree जैसे नॉन-लीनियर स्ट्रक्चर को लीनियर Array में संग्रहीत किया जा सकता है?
[EN] Yes! Complete Binary Trees (such as Binary Heaps) map directly into an array with zero pointers using `left = 2i + 1` and `right = 2i + 2`.
[HI] हाँ! Complete Binary Tree (जैसे Binary Heap) को बिना किसी पॉइंटर के `left = 2i + 1` और `right = 2i + 2` सूत्रों से सीधे Array में स्टोर किया जाता है।
Q3: When should I choose a Balanced Tree over a Sorted Array?
मुझे सॉर्टेड Array के बजाय Balanced Tree कब चुनना चाहिए?
[EN] Choose a Sorted Array when data is mostly static and read-heavy (fast O(1) indexing, O(log n) binary search, zero pointer overhead). Choose a Balanced Tree when frequent insertions and deletions happen alongside searching.
[HI] जब डेटा कम बदलता हो और केवल तेज खोज व कम मेमोरी चाहिए, तब सॉर्टेड ऐरे बेहतर है; जब बार-बार डेटा जोड़ना व हटाना भी हो, तब Balanced Tree चुनें।
Post a Comment
Post a Comment