निम्नलिखित में से कौन-सी आकृति संतुलित बाइनरी ट्री है?
Which of the following figures is a balanced binary tree?
A
B
C
D
सही उत्तर / Answer: (B)
हल / Solution
संतुलित बाइनरी ट्री में हर नोड पर बाएँ और दाएँ उप-वृक्ष की ऊँचाई का अंतर अधिकतम एक होना चाहिए। दूसरी आकृति में जड़ के बाएँ दो पत्तियाँ हैं और दाएँ एक, और किसी नोड पर अंतर एक से ज़्यादा नहीं जाता, इसलिए वही संतुलित है। पहली आकृति में एक ओर की शाखा तीन स्तर लंबी है, दूसरी ओर केवल एक नोड। तीसरी और चौथी में एक नोड के नीचे दो स्तर हैं और दूसरी ओर कुछ नहीं।
In a balanced binary tree the heights of the left and right subtrees must differ by at most one at every node. In the second figure the root has two leaves on its left and one on its right, and no node breaks that limit, so it is balanced. In the first, one branch runs three levels deep while the other side holds one node. The third and fourth have two levels below a node on one side only.
Graph traversal, tree traversal से अलग क्यों होता है?
Graph traversal is different from tree traversal because:
ATree जुड़ा हुआ नहीं होताTree is not connected
BGraph में loops हो सकते हैंGraph may have loops
CTree में जड़ होती हैTree has root
DTree traversal में visited array रखना पड़ता हैTree traversal needs a visited array
सही उत्तर / Answer: (B)
हल / Solution
पेड़ (tree) एक चक्र-रहित जुड़ा हुआ graph है जिसमें हर node तक ठीक एक ही रास्ता जाता है, इसलिए उसे घूमते हुए कोई node दोबारा नहीं आता। पर सामान्य graph में loop और चक्र हो सकते हैं। इसी कारण graph में BFS या DFS चलाते समय देखे गए node का हिसाब (visited array) रखना पड़ता है, वरना algorithm चक्र में फँसकर अनंत चलता रहता है। यही अतिरिक्त हिसाब असली फ़र्क़ है।
A tree is a connected acyclic graph in which exactly one path reaches each node, so a traversal never meets the same node twice. A general graph, however, may contain loops and cycles, and several paths may lead to one node. That is why BFS or DFS on a graph must keep a record of visited nodes, otherwise the algorithm falls into a cycle and runs forever. This extra bookkeeping is the real difference.
इनफ़िक्स नोटेशन को पोस्टफ़िक्स नोटेशन में बदलने के लिए किस डेटा संरचना की ज़रूरत होती है?
Which data structure is needed to convert infix notation to postfix notation?
ABranch / ब्रांचBranch
BTree / ट्रीTree
CQueue / क्यूQueue
DStack / स्टैकStack
सही उत्तर / Answer: (D)
हल / Solution
इनफ़िक्स से पोस्टफ़िक्स बनाते समय ऑपरेंड सीधे आउटपुट में चले जाते हैं, पर चिह्नों को रोककर रखना पड़ता है। किस चिह्न को कब निकालना है, यह उसकी प्राथमिकता और कोष्ठक तय करते हैं। जो चिह्न बाद में आया और ऊँची प्राथमिकता का है, वह पहले बाहर जाता है — यह उल्टा क्रम सिर्फ़ स्टैक दे सकता है। इसी तरीक़े को Shunting Yard कहते हैं। क्यू FIFO है, इसलिए वह यह क्रम नहीं देगा। ट्री और ब्रांच यहाँ साधन नहीं हैं।
While converting infix to postfix, operands go straight to the output but operators must be held back. Precedence and brackets decide when each held operator is released. An operator that arrived later with higher precedence leaves first, and only a stack can produce that reverse order. The method is known as the Shunting Yard algorithm. A queue is FIFO, so it cannot give that order. A tree or a branch is not the tool for this step.
निम्नलिखित में से कौन-सी ट्री डेटा संरचना संतुलित बाइनरी ट्री नहीं है?
Which of the following tree data structures is not a balanced binary tree?
Aएवीएल ट्री (AVL tree)AVL tree
Bरेड-ब्लैक ट्री (Red-black tree)Red-black tree
Cस्प्ले ट्री (Splay tree)Splay tree
Dबी-ट्री (B-tree)B-tree
सही उत्तर / Answer: (D)
हल / Solution
बाइनरी ट्री की शर्त है कि किसी भी नोड के अधिकतम दो बच्चे हों। बी-ट्री इस शर्त को ही तोड़ देता है, क्योंकि उसके एक नोड में कई कुंजियाँ और दो से कहीं ज़्यादा बच्चे हो सकते हैं। वह संतुलित तो रहता है, पर बाइनरी नहीं। एवीएल, रेड-ब्लैक और स्प्ले — तीनों बाइनरी सर्च ट्री हैं और तीनों ख़ुद को संतुलित रखने के नियम लगाते हैं, इसलिए वे प्रश्न की माँग पर खरे नहीं उतरते।
A binary tree must have at most two children at every node. A B-tree breaks that very condition, because a single node can hold several keys and far more than two children. It does stay balanced, but it is not binary. AVL, red-black and splay trees are all binary search trees and each of them applies rules to keep itself balanced, so none of them answers what the question is asking for.
Aहर node के ठीक शून्य या दो बच्चे होंEach node has exactly zero or two children
Bहर node के ठीक दो बच्चे होंEach node has exactly two children
Cसभी leaves एक ही स्तर पर होंAll leaves at same level
Dहर node के ठीक एक या दो बच्चे होंEach node has exactly one or two children
सही उत्तर / Answer: (A)
हल / Solution
पूर्ण (full) binary tree — जिसे strict या proper भी कहते हैं — वह है जिसमें हर node के या शून्य बच्चे हों (यानी वह पत्ती है) या ठीक दो; एक बच्चे वाला node कहीं नहीं होता। इसी से सुंदर संबंध बनते हैं: भीतरी node I हों तो पत्तियाँ L=I+1 और कुल node N=2L−1। «हर node के ठीक दो बच्चे» ग़लत है, क्योंकि पत्तियों के बच्चे शून्य होते हैं। «सब पत्तियाँ एक स्तर पर» perfect पेड़ की बात है।
A full binary tree, also called strict or proper, is one in which every node has either zero children, that is it is a leaf, or exactly two; no node ever has a single child. This gives neat relations: with I internal nodes there are L=I+1 leaves and N=2L−1 nodes in all. Saying every node has exactly two children is wrong, because leaves have none, and leaves on one level describes a perfect tree.
सीरियल एक्सेस मेमोरी में रखे डेटा तक पहुँचने की प्रक्रिया ________ पर डेटा के साथ काम करने जैसी है
The process of accessing data stored in a serial access memory is similar to manipulating data on a ________
AHeap Tree / हीप ट्रीHeap Tree
BBinary Tree / बाइनरी ट्रीBinary Tree
CGraph / ग्राफ़Graph
DStack / स्टैकStack
सही उत्तर / Answer: (D)
हल / Solution
सीरियल एक्सेस मेमोरी में किसी जगह तक सीधे नहीं पहुँचा जा सकता। वहाँ डेटा एक तय क्रम में ही मिलता है, जैसे टेप में। स्टैक भी ऐसा ही है — अंदर पड़ा कोई तत्व सीधे नहीं पढ़ा जा सकता, ऊपर वाले पहले हटाने पड़ते हैं। इसी सीमित पहुँच की वजह से दोनों की तुलना की जाती है। हीप ट्री और बाइनरी ट्री में रास्ता चुनकर तेज़ी से पहुँचा जा सकता है। ग्राफ़ में तो कई रास्ते होते हैं।
Serial access memory does not let you jump straight to a location. Data comes in a fixed order, the way it does on a tape. A stack behaves the same way, because an element lying inside cannot be read directly and the ones above it must be removed first. That shared restriction is why the two are compared. A heap tree or a binary tree allows a guided path to any node, and a graph offers many paths.
आठ पत्तियों (leaves) वाले संतुलित पूर्ण बाइनरी ट्री की ऊँचाई कितनी होगी?
What will be the height of a balanced full binary tree with 8 leaves?
A8
B5
C6
D4
सही उत्तर / Answer: (D)
हल / Solution
पूर्ण बाइनरी ट्री में हर स्तर पर नोड दुगुने होते जाते हैं — 1, 2, 4, 8। आठ पत्तियाँ पाने के लिए जड़ के बाद तीन बार दुगुना करना पड़ा, यानी जड़ वाले स्तर को मिलाकर कुल चार स्तर बने। स्तरों की गिनती से ऊँचाई चार आती है, इसलिए विकल्प (D) सही है। आठ, पाँच और छह किसी गणना से नहीं निकलते; आठ तो पत्तियों की संख्या है, ऊँचाई नहीं।
In a full binary tree the number of nodes doubles at every level, giving 1, 2, 4, 8. To reach eight leaves the tree has to double three times after the root, so counting the root level as well there are four levels in all. Measuring height by levels gives four, so option (D) is correct. The values eight, five and six come from no calculation at all; eight is simply the number of leaves, not the height.
Aहर node के ठीक शून्य या दो बच्चे होंEach node has exactly zero or two children
Bसबसे निचले स्तर को छोड़ पूरी भरी हो, निचला स्तर दाएँ से बाएँ भरा होFilled completely except bottom level, filled right to left
Cसबसे निचले स्तर को छोड़ पूरी भरी हो, निचला स्तर बाएँ से दाएँ भरा होFilled completely except bottom level, filled left to right
Dसभी leaves एक ही स्तर पर होंAll leaves lie at the same level
सही उत्तर / Answer: (C)
हल / Solution
पूर्ण-प्राय (complete) binary tree वह है जिसमें सबसे निचले स्तर को छोड़कर बाक़ी सब स्तर पूरे भरे रहते हैं, और निचले स्तर के node बाएँ से दाएँ, बीच में जगह ख़ाली छोड़े बिना बैठते हैं। इसी नियमित बनावट से ऐसा पेड़ array में कसकर रखा जा सकता है — index i के node का बायाँ बच्चा 2i पर, दायाँ 2i+1 पर; इसीलिए heap सदा complete होता है। «शून्य या दो बच्चे» full की परिभाषा है,।
A complete binary tree is one in which every level except the bottom one is entirely full, and the nodes of the bottom level sit from left to right with no gap between them. This regular shape lets the tree be packed tightly into an array: the node at index i has its left child at 2i and its right child at 2i+1, which is why a heap is always complete. Zero or two children defines a full tree.
किसी रिकर्सिव एल्गोरिदम के ग़ैर-रिकर्सिव रूप में आपको अक्सर कौन-सी डेटा संरचना दिखेगी?
What data structure would you most likely see in a non-recursive implementation of a recursive algorithm?
ALinked List / लिंक्ड लिस्टLinked List
BStack / स्टैकStack
CQueue / क्यूQueue
DTree / ट्रीTree
सही उत्तर / Answer: (B)
हल / Solution
रिकर्सन चलते समय हर कॉल के चर और लौटने का पता सिस्टम के call stack में जमा होते हैं। जब वही एल्गोरिदम बिना रिकर्सन के लिखा जाता है, तो यह जमा-जमाई जानकारी हमें ख़ुद सँभालनी पड़ती है। इसके लिए अपना एक स्टैक बनाया जाता है। इसीलिए पेड़ के ट्रैवर्सल जैसे काम बिना रिकर्सन के स्टैक से किए जाते हैं। क्यू FIFO है, वह लौटने का उल्टा क्रम नहीं दे सकता। लिंक्ड लिस्ट और ट्री सिर्फ़ ढाँचे हैं।
While recursion runs, the variables and return address of each call are saved on the system call stack. If we rewrite the same algorithm without recursion, that saved information has to be handled by us. So we build an explicit stack of our own. This is how tree traversals are written iteratively. A queue is FIFO and cannot give the reverse order that backtracking needs. A linked list or a tree is only a container here.
Dलेवल ऑर्डर ट्रैवर्सल (Level order traversal)Level order traversal
सही उत्तर / Answer: (C)
हल / Solution
ट्रैवर्सल का नाम इस बात से तय होता है कि जड़ (root) का डेटा कब छापा जा रहा है। यहाँ पहले बायाँ उप-वृक्ष पूरा घूमा जाता है, फिर दायाँ, और छपाई सबसे आख़िर में होती है। बाएँ-दाएँ-जड़ का यही क्रम पोस्टऑर्डर कहलाता है। प्रीऑर्डर में छपाई सबसे पहले होती, इनऑर्डर में दोनों कॉलों के बीच में। लेवल ऑर्डर स्तर-दर-स्तर चलता है और उसके लिए रिकर्शन नहीं, क्यू चाहिए।
The name of a traversal depends on when the data of the root is printed. In this code the whole left subtree is visited first, then the whole right subtree, and printing happens at the very end. This left, right, root order is called postorder. In preorder the printing would come first, and in inorder it would sit between the two recursive calls. Level order moves level by level and needs a queue rather than recursion.
आगे के 10 प्रश्नों के उत्तर और हल app मेंFliQi Question Bank — अभ्यास, हल और आपकी प्रगति