Data Structure Advanced

Similar documents
Data Structures. Outline. Introduction Linked Lists Stacks Queues Trees Deitel & Associates, Inc. All rights reserved.

1 Binary trees. 1 Binary search trees. 1 Traversal. 1 Insertion. 1 An empty structure is an empty tree.

First Semester - Question Bank Department of Computer Science Advanced Data Structures and Algorithms...

R13. II B. Tech I Semester Supplementary Examinations, May/June DATA STRUCTURES (Com. to ECE, CSE, EIE, IT, ECC)

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

Course Review for. Cpt S 223 Fall Cpt S 223. School of EECS, WSU

Binary Trees. College of Computing & Information Technology King Abdulaziz University. CPCS-204 Data Structures I

Data Structure. IBPS SO (IT- Officer) Exam 2017

Data Structures Question Bank Multiple Choice

Binary Trees

Name CPTR246 Spring '17 (100 total points) Exam 3

Revision Statement while return growth rate asymptotic notation complexity Compare algorithms Linear search Binary search Preconditions: sorted,

Data Structures And Algorithms

CSCI-401 Examlet #5. Name: Class: Date: True/False Indicate whether the sentence or statement is true or false.

A6-R3: DATA STRUCTURE THROUGH C LANGUAGE

12 Abstract Data Types

Cpt S 122 Data Structures. Data Structures Trees

Copyright 1998 by Addison-Wesley Publishing Company 147. Chapter 15. Stacks and Queues

Final Exam Data Structure course. No. of Branches (5)

CSE 373 APRIL 17 TH TREE BALANCE AND AVL

CS24 Week 8 Lecture 1

Abstract Data Structures IB Computer Science. Content developed by Dartford Grammar School Computer Science Department

Programming II (CS300)

Programming II (CS300)

Cpt S 122 Data Structures. Course Review Midterm Exam # 1

Lecture 37 Section 9.4. Wed, Apr 22, 2009

DATA STRUCTURE : A MCQ QUESTION SET Code : RBMCQ0305

Trees. (Trees) Data Structures and Programming Spring / 28

Stacks, Queues and Hierarchical Collections

C Data Structures Stacks. Stack. push Adds a new node to the top of the stack

a graph is a data structure made up of nodes in graph theory the links are normally called edges

Abstract Data Types CHAPTER 12. Review Questions

Binary Search Trees. See Section 11.1 of the text.

CSE 100: GRAPH ALGORITHMS

Data Structures. Binary Trees. Root Level = 0. number of leaves:?? leaves Depth (Maximum level of the tree) leaves or nodes. Level=1.

Cpt S 223 Fall Cpt S 223. School of EECS, WSU

COP 3502 (Computer Science I) Test #3: Data Structures Date: 11/1/2013 VERSION A

FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- MARCH, 2012 DATA STRUCTURE (Common to CT and IF) [Time: 3 hours

3137 Data Structures and Algorithms in C++

Stacks, Queues and Hierarchical Collections. 2501ICT Logan

Answers. 1. (A) Attempt any five : 20 Marks

CS61B Lecture #20: Trees. Last modified: Wed Oct 12 12:49: CS61B: Lecture #20 1

Binary Trees, Binary Search Trees

Sample Question Paper

CS61BL. Lecture 3: Asymptotic Analysis Trees & Tree Traversals Stacks and Queues Binary Search Trees (and other trees)

Course Review. Cpt S 223 Fall 2009

Trees. Truong Tuan Anh CSE-HCMUT

Chapter 5. Binary Trees

DYNAMIC MEMORY ALLOCATION AND DEALLOCATION

Trees Algorhyme by Radia Perlman

CS61B Spring 2016 Guerrilla Section 3 Worksheet. 12 March 2016

CP2 Revision. theme: dynamic datatypes & data structures

INSTITUTE OF AERONAUTICAL ENGINEERING

Course Review for Finals. Cpt S 223 Fall 2008

9/26/2018 Data Structure & Algorithm. Assignment04: 3 parts Quiz: recursion, insertionsort, trees Basic concept: Linked-List Priority queues Heaps

Chapter 20: Binary Trees

CSE 373 Spring Midterm. Friday April 21st

End-Term Examination Second Semester [MCA] MAY-JUNE 2006

ECE250: Algorithms and Data Structures Midterm Review

Department of Computer Science and Technology

CS61B Lecture #20. Today: Trees. Readings for Today: Data Structures, Chapter 5. Readings for Next Topic: Data Structures, Chapter 6

CMSC351 - Fall 2014, Homework #2

Data Structure. Recitation VII

There are many other applications like constructing the expression tree from the postorder expression. I leave you with an idea as how to do it.

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified)

Thus, it is reasonable to compare binary search trees and binary heaps as is shown in Table 1.

1 P age DS & OOPS / UNIT II

Trees. Introduction & Terminology. February 05, 2018 Cinda Heeren / Geoffrey Tien 1

DATA STRUCTURE. 1- What data structure can be used to check if a syntax has balanced paranthesis? A - queue B - tree C - list D - stack

Programming II (CS300)

Computational Optimization ISE 407. Lecture 16. Dr. Ted Ralphs

! Tree: set of nodes and directed edges. ! Parent: source node of directed edge. ! Child: terminal node of directed edge

Course Review. Cpt S 223 Fall 2010

LECTURE 11 TREE TRAVERSALS

Stacks, Queues & Trees. The Stack Interface. The Stack Interface. Harald Gall, Prof. Dr.

University of Palestine. Final Exam 2 nd semester 2014/2015 Total Grade: 50

Course goals. exposure to another language. knowledge of specific data structures. impact of DS design & implementation on program performance

R10 SET - 1. Code No: R II B. Tech I Semester, Supplementary Examinations, May

Prepared By: Ms. Nidhi Solanki (Assist. Prof.) Page 1

COP 3502 Section 2 Exam #2 Version A Spring /23/2017

COSC 2007 Data Structures II Final Exam. Part 1: multiple choice (1 mark each, total 30 marks, circle the correct answer)

1. Stack overflow & underflow 2. Implementation: partially filled array & linked list 3. Applications: reverse string, backtracking

Summer Final Exam Review Session August 5, 2009

Trees. Tree Structure Binary Tree Tree Traversals

Tree Structures. A hierarchical data structure whose point of entry is the root node

( ) + n. ( ) = n "1) + n. ( ) = T n 2. ( ) = 2T n 2. ( ) = T( n 2 ) +1

MIDTERM EXAMINATION Spring 2010 CS301- Data Structures

CSE 373 Autumn 2010: Midterm #1 (closed book, closed notes, NO calculators allowed)

Trees! Ellen Walker! CPSC 201 Data Structures! Hiram College!

CS61B Lecture #20: Trees. Last modified: Mon Oct 8 21:21: CS61B: Lecture #20 1

Direct Addressing Hash table: Collision resolution how handle collisions Hash Functions:

CS350: Data Structures Heaps and Priority Queues

SOLUTIONS. COMP103 Introduction to Data Structures and Algorithms

Table of Contents. Chapter 1: Introduction to Data Structures... 1

Tree. A path is a connected sequence of edges. A tree topology is acyclic there is no loop.

Trees : Part 1. Section 4.1. Theory and Terminology. A Tree? A Tree? Theory and Terminology. Theory and Terminology

FINALTERM EXAMINATION Fall 2009 CS301- Data Structures Question No: 1 ( Marks: 1 ) - Please choose one The data of the problem is of 2GB and the hard

CS 206 Introduction to Computer Science II

CSE 332: Data Structures & Parallelism Lecture 7: Dictionaries; Binary Search Trees. Ruth Anderson Winter 2019

NET/JRF-COMPUTER SCIENCE & APPLICATIONS. Time: 01 : 00 Hour Date : M.M. : 50

Transcription:

Data Structure Advanced 1. Is it possible to find a loop in a Linked list? a. Possilbe at O(n) b. Not possible c. Possible at O(n^2) only d. Depends on the position of loop Solution: a. Possible at O(n) Have two pointers say P1 and P2 pointing to the first node of the list. Start a loop and Increment P1 once and P2 twice in each iteration. At any point of time if P1==P2 then there is a loop in that linked list. If P2 reaches NULL (end of linked list) then no loop exists. 2. Two linked lists L1 and L2 intersects at a particular node N1 and from there all other nodes till the end are common. The length of the lists are not same. What are the possibilities to find N1?. a. Solution exist for certain cases only b. No linear solution exist c. Linear solution is possible d Only Non-linear solution exist. Solution: c. Linear solution is possible Have two pointers say P1 pointing to the first node of L1 and P2 to that of L2. Traverse through both the lists. If P1 reaches L1 s last node, point it to the first node of L2 and continue traversing. Do the same thing for P2 when it reaches L2 s last node. (By doing this, we are balancing the difference in the length between the linked lists. The shorter one will get over soon and by redirecting to longer list s head, it will traverse the extra nodes also.) Finally they will Meet at the Intersection node. 3. void PrintTree (Tree T) if (T!= NULL) Page 1 of 5

The above method PrintTree results in which of the following traversal a Inorder b. Preorder c. Postorder d. None of the above Solution: a. Inorder Inorder: void PrintTree (Tree T) if (T!= NULL) For preorder use this order For postorder use this order 4. Given a Binary Search Tree (BST), print its values in ascending order. a. Perform Depth first traversal Page 2 of 5

b. Perform Breadth first traversal c. Perform Postorder traversal d. Perform Inorder traversal Solution: d. Perform Inorder traversal It is the properfy of BST and Inorder traversal. 5. Is it possible to implement a queue using Linked List?. Enqueue & Dequeue should be O(1). a. Not possible to implement. b Only Enqueue is possible at O(1). c. Only Dequeue is possible at O(1). d. Both Enqueue and Dequeue is possible at O(1) Solution: d. Both Enqueue and Dequeue is possible at O(1) Have two pointers H pointing to the Head and T pointing to the Tail of the linked list. Perform enqueue at T and perform dequeue at H. Update the pointers after each operations accordingly. 6. Given a Tree, is it possible to find the greatest and least among leaves in linear time?. a. Solution depends on the tree structure b.linear solution exist c. Only Non-linear solution exist. d. No linear solution exist Solution: b. Linear solution exist Have two variables Min and Max. Perform any tree traversal.assign the first traversed leaf element to Min and Max for all other leaf elements check with these variables and update it accordingly. If a current element is < Min then update Min with that element. If it is > Min then check with Max. Note: If you want to find the greatest and least among all nodes perform the checks for each node traversed. 7. Is it possible to find find the greatest and least value among the nodes Page 3 of 5

in a given BST without using any extra variables? a. No solution exist. b. Solution need 2 extra variables c. Solution exist without any extra variables d Solution need 1 extra variable Solution:c Solution exist without any extra variables As per BST property, the left most node should be the least one and the rightmost node should be the greatest. In other words, the first and last node of an Inorder traversal are the least and greatest among the nodes respectively. 8. Is it possible to implement 2 stack in an array? Condition: None of the stack should indicate an overflow until every slot of an array is used. a. Only 1 stack can be implemented for the given condition b. Stacks can not be implemented in array c. 2 stacks can be implemented for the given condition. d. 2 stacks can be implemented if the given condition is applied only for 1 stack. Solution:c. 2 stacks can be implemented for the given condition Start 1st stack from left (1st position of an array) and 2nd from right (last position say n). Move 1st stack towards right( i.e 1,2,3...n) and 2nd towards left (i.e n,n-1,n-2...1). 9. Given two keys K1 & K2, write an algorithm to print all the elements between them with K1<=K2 in a BST. a. Solution need 2 extra spaces b. Linear solution is possible without using any extra space c No linear solution exist d Solution need 1 extra space Solution:b. Linear solution is possible without using any extra space Perform an inorder traversal. Once you find K1 print it and continue traversal now, print all other traversed elements until you reach K2. Note: If K1 == K2 stop once you find K1. Page 4 of 5

10. How many stacks are required to implement a Queue. a. One b. Two c. Three d. Two + one extra space. Solution:b Two Have two stacks S1 and S2. For Enqueue, perform push on S1. For Dequeue, if S2 is empty pop all the elements from S1 and push it to S2. The last element you popped from S1 is an element to be dequeued. If S2 is not empty, then pop the top element in it. Page 5 of 5