GATE CS Trees questions
Practise Trees questions for GATE CS. Explore official PYQs and original topic-wise quizzes, check answers and view available solutions. Free, no sign-in.
Subject, topic, year and type filter the full library. Match any choice within a filter, and all selected filter categories. Search, source and sort apply to this page.
20 on this page
The set represents various traversals over binary tree. The set represents the order of visiting nodes during a traversal. …
Consider a binary tree in which every node has either zero or two children. Let be the number of nodes in . Which ONE of the following is the number of nodes in that have exactly two children?
Consider the function and the binary tree shown. typedef struct node { int val; struct node *left, *right; } node; int foo(node *p) { int retval; if (p == NULL) return 0; else { retval = p->val + foo(p->left) + foo(p->right); printf("%d ", retval); return retval; } } When is called with a pointer to the …
An in a connected graph is a vertex such that removing the vertex and its incident edges disconnects the graph into two or more connected components. Let be a tree obtained by doing in a connected undirected graph . Which of the following options is/are correct?
Consider a complete binary tree with nodes. Let denote the set of first elements obtained by performing Breadth-First Search starting from the root. Let denote the set of first elements obtained by performing Depth-First Search starting from the root. The value of is …
What is the worst case time complexity of inserting elements into an AVL-tree with elements initially?
Let be a full binary tree with leaves. (A full binary tree has every level full.) Suppose two leaves and of are chosen uniformly and independently at random. The expected value of the distance between and in (ie., the number of edges in the unique path between and ) is (rounded off to decimal …
The postorder traversal of a binary tree is . The inorder traversal of the same tree is . The height of a tree is the length of the longest path from the root to any leaf. The height of the binary tree above is _____
Let be a tree with vertices. The sum of the degrees of all the vertices in is ________
Consider the following New-order strategy for traversing a binary tree: Visit the root; Visit the right subtree using New-order; Visit the left subtree using New-order; The New-order traversal of the expression tree corresponding to the reverse polish expression 3 4 * 5 - 2 ^ 6 7 * 1 + - is given by:
The height of a tree is the length of the longest root-to-leaf path in it. The maximum and minimum number of nodes in a binary tree of height are
A binary tree T has leaves. The number of nodes in T having two children is ______.
Consider a binary tree T that has leaf nodes. Then the number of nodes in T that have exactly two children are ______.
Consider a rooted n node binary tree represented using pointers. The best upper bound on the time required to determine the number of subtrees having exactly nodes is . Then the value of is __________.
Consider the pseudocode given below. The function takes as argument a pointer to the root of an arbitrary tree represented by the representation. Each node of the tree is of type . typedef struct treeNode* treeptr; struct treeNode { treeptr leftMostChild, rightSibling; }; int DoSomething (treeptr …
Consider the following rooted tree with the vertex labeled as the root: The order in which the nodes are visited during an in-order traversal of the tree is
The height of a tree is defined as the number of edges on the longest path in the tree. The function shown in the pseudo-code below is invoked as height (root) to compute the height of a binary tree rooted at the tree pointer root. int height(treeptr n) { if(n == NULL) return -1; if(n -> left == NULL) if(n -> right == NULL) return 0; else return B1; // …
We are given a set of distinct elements and an unlabeled binary tree with nodes. In how many ways can we populate the tree with the given set so that it becomes a binary search tree?
In a binary tree with nodes, every node has an odd number of descendants. Every node is considered to be its own descendant. What is the number of nodes in the tree that have exactly one child?
Consider the following C program segment where represents a node in a binary tree: struct CellNode { struct CellNode *leftChild; int element; struct CellNode *rightChild; }; int Getvalue (struct CellNode *ptr) { int value = 0; if (ptr != NULL) { if ((ptr->leftChild == NULL) && (ptr->rightChild == NULL)) value = 1; else value …
