Data Structures and Algorithms | Set 7 Last Updated : 13 Dec, 2022 Comments Improve Suggest changes Like Article Like Report Following questions have been asked in GATE CS 2006 exam. 1. In a binary max heap containing n numbers, the smallest element can be found in time (GATE CS 2006) (A) 0(n) (B) O(logn) (C) 0(loglogn) (D) 0(1) Answer (A) In a max heap, the smallest element is always present at a leaf node. So we need to check for all leaf nodes for the minimum value. Worst case complexity will be O(n) 12 / \ / \ 8 7 / \ / \ / \ / \ 2 3 4 5 2. A scheme for storing binary trees in an array X is as follows. Indexing of X starts at 1 instead of 0. the root is stored at X[1]. For a node stored at X[i], the left child, if any, is stored in X[2i] and the right child, if any, in X[2i+1]. To be able to store any binary tree on n vertices the minimum size of X should be. (GATE CS 2006) (A) log2n (B) n (C) 2n + 1 (D) 2^n — 1 Answer (D) For a right skewed binary tree, number of nodes will be 2^n - 1. For example, in below binary tree, node 'A' will be stored at index 1, 'B' at index 3, 'C' at index 7 and 'D' at index 15. A \ \ B \ \ C \ \ D 3. Which one of the following in place sorting algorithms needs the minimum number of swaps? (GATE CS 2006) (A) Quick sort (B) Insertion sort (C) Selection sort (D) Heap sort Answer (C) For selection sort, number of swaps required is minimum ( Θ(n) ). 4. An element in an array X is called a leader if it is greater than all elements to the right of it in X. The best algorithm to find all leaders in an array (GATE CS 2006) (A) Solves it in linear time using a left to right pass of the array (B) Solves it in linear time using a right to left pass of the array (C) Solves it using divide and conquer in time 8(nlogn) (D) Solves it in time 8(n2) Answer (B) Please see this post for explanation. 5. Consider a weighted complete graph G on the vertex set {v1, v2, ..vn} such that the weight of the edge (vi, vj) is 2|i-j|. The weight of a minimum spanning tree of G is: (GATE CS 2006) (A) n — 1 (B) 2n — 2 (C) nC2 (D) 2 Answer (B) Minimum spanning tree of such a graph is v1 \ v2 \ v3 \ v4 . . . vn Weight of the minimum spanning tree = 2|2 - 1| + 2|3 - 2| + 2|4 - 3| + 2|5 - 4| .... + 2| n - (n-1) | = 2n - 2 Please see GATE Corner for all previous year paper/solutions/explanations, syllabus, important dates, notes, etc. Please write comments if you find any of the answers/explanations incorrect or you want to share more information about the topics discussed above. Comment More infoAdvertise with us Next Article Data Structures and Algorithms | Set 7 kartik Follow Improve Article Tags : DSA GATE-CS-DS-&-Algo GATE-CS-2006 Similar Reads DSA Guide for GATE CS Exam | Notes, Syllabus, Preparation Strategy The GATE (Graduate Aptitude Test in Engineering) Exam is a critical milestone for computer science enthusiasts seeking advanced education or career opportunities. A solid understanding of Data Structures and Algorithms (DSA) is indispensable for success in this exam, as it forms the core of computer 9 min read Asymptotic Analysis of Algorithms Notes for GATE Exam [2024] This Asymptotic Analysis of Algorithms is a critical topic for the GATE (Graduate Aptitude Test in Engineering) exam, especially for candidates in computer science and related fields. This set of notes provides an in-depth understanding of how algorithms behave as input sizes grow and is fundamental 15 min read Recurrence Relations Notes for GATE Exam [2024] Recurrence relations are the mathematical backbone of algorithmic analysis, providing a systematic way to express the time complexity of recursive algorithms. As GATE Exam 2024 approaches, a profound understanding of recurrence relations becomes imperative for tackling questions that demand a deep c 13 min read Array Notes for GATE Exam [2024] Arrays are fundamental data structures in computer science, and mastering them is crucial for success in the GATE exam. This article aims to provide concise yet comprehensive notes on arrays, covering essential concepts and strategies to help you tackle array-related questions in the GATE 2024 exam. 15+ min read Linked List Notes for GATE Exam [2024] The "Linked List Notes for GATE Exam" is a comprehensive resource designed to aid students in preparing for the Graduate Aptitude Test in Engineering (GATE). Focused specifically on linked lists, a fundamental data structure in computer science, these notes offer a detailed and structured approach t 15+ min read Queue Notes for GATE Exam [2024] A Queue is defined as a linear data structure that is open at both ends and the operations are performed in First In First Out (FIFO) order. Queue is a list in which all additions to the list are made at one end, and all deletions from the list are made at the other end.  The element, which is first 15+ min read Stack Notes for GATE Exam [2024] Stacks, a fundamental data structure in computer science, are crucial for understanding algorithmic paradigms and solving complex computational problems. As candidates gear up for the GATE Exam 2024, a solid grasp of stack concepts is indispensable. These notes are designed to provide a concise yet 14 min read Hashing Notes for GATE Exam [2024] Hashing is a fundamental concept in computer science and plays a pivotal role in various algorithms and data structures. Aspiring candidates preparing for the GATE Exam 2024 must grasp the intricacies of hashing to tackle complex problem-solving scenarios efficiently. These notes aim to provide a co 15+ min read Trees Notes for GATE Exam [2024] Trees are foundational structures in computer science, serving as the backbone for numerous algorithms and data representations. GATE aspirants should be well versed in tree structures to prepare for the GATE Exam in 2024. This article aims to provide a concise yet comprehensive overview of trees, e 15 min read Graph Data Structure Notes for GATE Exam [2024] Graphs, a fundamental concept in computer science and mathematics, serve as powerful tools for modeling and solving a myriad of real-world problems. As aspirants gear up for the GATE Exam 2024, a comprehensive understanding of graph data structures becomes paramount. These notes aim to provide a con 15+ min read Like