Questions 1 through 25 are worth 2 points each. Choose one best answer for each.



Similar documents
1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++

DATA STRUCTURES USING C

Data Structure [Question Bank]

Krishna Institute of Engineering & Technology, Ghaziabad Department of Computer Application MCA-213 : DATA STRUCTURES USING C

Binary Search Trees CMPSC 122

Converting a Number from Decimal to Binary

Binary Trees and Huffman Encoding Binary Search Trees

Data Structures, Practice Homework 3, with Solutions (not to be handed in)

Sorting revisited. Build the binary search tree: O(n^2) Traverse the binary tree: O(n) Total: O(n^2) + O(n) = O(n^2)

Chapter 14 The Binary Search Tree

PES Institute of Technology-BSC QUESTION BANK

10CS35: Data Structures Using C

5. A full binary tree with n leaves contains [A] n nodes. [B] log n 2 nodes. [C] 2n 1 nodes. [D] n 2 nodes.

INTERNATIONAL JOURNAL OF PURE AND APPLIED RESEARCH IN ENGINEERING AND TECHNOLOGY

Java Software Structures

CSE 326, Data Structures. Sample Final Exam. Problem Max Points Score 1 14 (2x7) 2 18 (3x6) Total 92.

1. The memory address of the first element of an array is called A. floor address B. foundation addressc. first address D.

Data Structures. Level 6 C Module Descriptor

Binary Search Trees. A Generic Tree. Binary Trees. Nodes in a binary search tree ( B-S-T) are of the form. P parent. Key. Satellite data L R

Binary Heap Algorithms

Binary Heaps * * * * * * * / / \ / \ / \ / \ / \ * * * * * * * * * * * / / \ / \ / / \ / \ * * * * * * * * * *

Ordered Lists and Binary Trees

ECE 250 Data Structures and Algorithms MIDTERM EXAMINATION /5:15-6:45 REC-200, EVI-350, RCH-106, HH-139

root node level: internal node edge leaf node Data Structures & Algorithms McQuain

MAX = 5 Current = 0 'This will declare an array with 5 elements. Inserting a Value onto the Stack (Push)

AP Computer Science AB Syllabus 1

A binary search tree or BST is a binary tree that is either empty or in which the data element of each node has a key, and:

Data Structures Fibonacci Heaps, Amortized Analysis

Algorithms and Data Structures Written Exam Proposed SOLUTION

Binary Search Trees (BST)

Linked Lists, Stacks, Queues, Deques. It s time for a chainge!

6 March Array Implementation of Binary Trees

A TOOL FOR DATA STRUCTURE VISUALIZATION AND USER-DEFINED ALGORITHM ANIMATION

Analysis of Algorithms I: Binary Search Trees

Data Structures and Data Manipulation

Introduction to Data Structures and Algorithms

Heaps & Priority Queues in the C++ STL 2-3 Trees

Sample Questions Csci 1112 A. Bellaachia

Data Structures and Algorithms

Data Structures and Algorithm Analysis (CSC317) Intro/Review of Data Structures Focus on dynamic sets

Analysis of a Search Algorithm

Exercises Software Development I. 11 Recursion, Binary (Search) Trees. Towers of Hanoi // Tree Traversal. January 16, 2013

Home Page. Data Structures. Title Page. Page 1 of 24. Go Back. Full Screen. Close. Quit

Exam study sheet for CS2711. List of topics

Data Structures UNIT III. Model Question Answer

TREE BASIC TERMINOLOGIES

The Tower of Hanoi. Recursion Solution. Recursive Function. Time Complexity. Recursive Thinking. Why Recursion? n! = n* (n-1)!

Abstract Data Type. EECS 281: Data Structures and Algorithms. The Foundation: Data Structures and Abstract Data Types

Binary Search Trees. Data in each node. Larger than the data in its left child Smaller than the data in its right child

Previous Lectures. B-Trees. External storage. Two types of memory. B-trees. Main principles

GUJARAT TECHNOLOGICAL UNIVERSITY, AHMEDABAD, GUJARAT. Course Curriculum. DATA STRUCTURES (Code: )

STACKS,QUEUES, AND LINKED LISTS

Queues Outline and Required Reading: Queues ( 4.2 except 4.2.4) COSC 2011, Fall 2003, Section A Instructor: N. Vlajic

Data Structure and Algorithm I Midterm Examination 120 points Time: 9:10am-12:10pm (180 minutes), Friday, November 12, 2010

Atmiya Infotech Pvt. Ltd. Data Structure. By Ajay Raiyani. Yogidham, Kalawad Road, Rajkot. Ph : ,

Learning Outcomes. COMP202 Complexity of Algorithms. Binary Search Trees and Other Search Trees

Quiz 4 Solutions EECS 211: FUNDAMENTALS OF COMPUTER PROGRAMMING II. 1 Q u i z 4 S o l u t i o n s

To My Parents -Laxmi and Modaiah. To My Family Members. To My Friends. To IIT Bombay. To All Hard Workers

B-Trees. Algorithms and data structures for external memory as opposed to the main memory B-Trees. B -trees

Algorithms Chapter 12 Binary Search Trees

Persistent Binary Search Trees

Lecture 12 Doubly Linked Lists (with Recursion)

\Mankinds's progress is measured by the number of. Elementary data structures such as stacks, queues,

Outline BST Operations Worst case Average case Balancing AVL Red-black B-trees. Binary Search Trees. Lecturer: Georgy Gimel farb

What is a Stack? Stacks and Queues. Stack Abstract Data Type. Java Interface for Stack ADT. Array-based Implementation

A binary heap is a complete binary tree, where each node has a higher priority than its children. This is called heap-order property

Linked Lists Linked Lists, Queues, and Stacks

CS104: Data Structures and Object-Oriented Design (Fall 2013) October 24, 2013: Priority Queues Scribes: CS 104 Teaching Team

Data Structure with C

CompuScholar, Inc. Alignment to Utah's Computer Programming II Standards

A binary search tree is a binary tree with a special property called the BST-property, which is given as follows:

Lecture Notes on Binary Search Trees

Binary Heaps. CSE 373 Data Structures

Algorithms and Data Structures Exercise for the Final Exam (17 June 2014) Stack, Queue, Lists, Trees, Heap

Introduction to Object-Oriented Programming

Data Structures. Jaehyun Park. CS 97SI Stanford University. June 29, 2015

Output: struct treenode{ int data; struct treenode *left, *right; } struct treenode *tree_ptr;

Tables so far. set() get() delete() BST Average O(lg n) O(lg n) O(lg n) Worst O(n) O(n) O(n) RB Tree Average O(lg n) O(lg n) O(lg n)

CS711008Z Algorithm Design and Analysis

Data Structures Using C++ 2E. Chapter 5 Linked Lists

Symbol Tables. Introduction

Class Notes CS Creating and Using a Huffman Code. Ref: Weiss, page 433

EE2204 DATA STRUCTURES AND ALGORITHM (Common to EEE, EIE & ICE)

Sorting Algorithms. Nelson Padua-Perez Bill Pugh. Department of Computer Science University of Maryland, College Park

Introduction to Programming System Design. CSCI 455x (4 Units)

How To Create A Tree From A Tree In Runtime (For A Tree)

Cpt S 223. School of EECS, WSU

Module 2 Stacks and Queues: Abstract Data Types

Lecture 6: Binary Search Trees CSCI Algorithms I. Andrew Rosenberg

Universidad Carlos III de Madrid

DATABASE DESIGN - 1DL400

Chapter 3: Restricted Structures Page 1

Algorithms and Data Structures

Common Data Structures

Lecture Notes on Binary Search Trees

Binary Search Trees. Ric Glassey

LINKED DATA STRUCTURES

JAWAA: Easy Web-Based Animation from CS 0 to Advanced CS Courses

Unit Write iterative and recursive C functions to find the greatest common divisor of two integers. [6]

Transcription:

Questions 1 through 25 are worth 2 points each. Choose one best answer for each. 1. For the singly linked list implementation of the queue, where are the enqueues and dequeues performed? c a. Enqueue in front of the first element, dequeue the first element b. Enqueue after the last element, dequeue the last element c. Enqueue after the last element, dequeue the first element d. Enqueue in front of the first element, dequeue the last element e. Enqueue after the first element, dequeue the first element 2. Which operation is not supported in constant time by a double-ended queue (deque)? d a. Insertion at the front or rear item b. Access to the front or rear item c. Deletion of the front or rear item d. Access and deletion of the minimum item e. All of the above are supported 3. Which of the following operations is not efficiently supported by a singly linked list? c a. accessing the element in the current position b. insertion after the current position c. moving to the position immediately prior to the current position d. moving to the position immediately following the current position e. all of the above are efficiently supported 4. What operation is supported in constant time by the doubly linked list, but not supported in constant time by the singly linked list? b a. first c. advance b. retreat d. all are constant time on singly linked list 5. Insertion of a node into a doubly linked list requires how many changes to next and prev references? c a. no changes d. 3 next, 3 prev b. 1 next, 1 prev e. none of the above c. 2 next, 2 prev 6. What is the running time for merging two singly linked lists into a single singly linked list? a (d only if there was a tail pointer on one of the lists) a. O(N) d. O(1) b. O(N 2 ) e. None of the above. c. O(N log N) 7. Consider an operation in which you need to return the elements immediately preceding and following a given item x. Which variation of lists would be most efficient? d a. singly linked list d. doubly linked list b. singly linked list with header and trailer nodes e. none of the above c. circular list 1

8. Which of the following algorithms requires the most extra space when implemented as in the text? b a. insertion sort d. shellsort b. mergesort e. all use only constant extra space c. quicksort 9. Which of the following algorithms runs in N log N average time but quadratic worst-case time? c a. insertion sort d. shellsort b. mergesort e. none of the above c. quicksort 10. If the array is already sorted, which algorithm will perform best? a a. insertion sort d. quicksort b. selection sort e. All will take same amount of time c. merge sort 11. Which data structure is used by the compiler to implement recursion? e a. hash table d. search tree b. priority queue e. stack c. queue 12. The following method violates which rule(s) of recursion? d static int recurse( int n ) if( n == 0 ) else return n + recurse( n/2 )+ recurse( n/2+1 ); a. No base case c. Performs redundant work b. Fails to make progress toward base case d. (b) and (c) 13. A recursive algorithm works by solving two half-sized problems recursively, with an additional linear-time overhead. The total running time is most accurately given by c a. O( log N ) d. O( N 2 ) b. O( N ) e. none of the above c. O( N log N ) 14. Which of the following, as discussed in lecture, is a binary tree? d a. Expression tree d. (a) and (b) b. Huffman coding tree e. none of (a), (b), and (c) c. Unix file system 15. Which of the following traversals requires more than linear time in the worst case? e b. level order e. all of these traversals are linear time 2

16. A node with key 8 has a left child with key 10. Which of the following objects could this node be found in? c a. binary search tree d. (a) and (c) b. max heap e. none of (a), (b), and (c) c. min heap 17. Which iterator traversal does not use a stack? b b. level order e. all of these traversals use a stack 18. How many N node binary trees with items 1, 2,..., N have identical preorder and inorder traversals? b a. 0 d. N! b. 1 e. none of the above c. N 19. The following items are inserted into a binary search tree: 3, 6, 5, 2, 4, 7, 1. Which node is the deepest? c a. 1 d. 7 b. 3 e. none of the above c. 4 The next four questions (20 through 23) relate to the tree below: A B C D E 20. Which of the following traversals yields ABCDE? e b. level order e. (b) and (d) 21. Which output could be produced by an inorder traversal of the tree? e a. ABCDE d. EDCBA b. ABDCE e. none of the above c. BDECA 22. The height of the tree is c a. 0 d. 3 b. 1 e. none of the above c. 2 3

23. Suppose a postorder iteration is performed on the tree. At the time that D is output, what symbols are still on the stack? c a. A only d. A, B, and C b. A and B only e. none of the above c. A and C only 24. Which of the following is not a red-black tree property? b a. the root is black b. all leaves are black c. consecutive red nodes are disallowed d. every path from a node to an external node must contain the same number of black nodes e. all of the above are red-black tree properties 25. Every node in a binary min heap b a. has two children b. is no larger than its children c. is no smaller than its children d. has a smaller left child than right child e. two or more of the above 26. (10 pts) Show the result of inserting 3, 1, 4, 6, 9, 2, 5, and 7 in an initially empty binary search tree. Then show the result of deleting the root. You should draw 2 separate trees to answer this question. First tree Inorder listing: 12345679 Preorder listing: 31246597 Postorder lising: 21579643 Second tree Inorder listing: 1245679 Preorder listing: 4126597 Postorder lising: 2157964 27. (20 pts) Show the result of inserting 10, 12, 1, 14, 6, 5, 8, 15, 3, 9, 7, 4, 11, 13, and 2, one at a time, into an initially empty binary min heap Either draw each intermediate heap or give a level order listing of the nodes in each intermediate heap for full credit (15 trees or 15 listings total). 2 points extra credit for both trees and level order listings!! The following are level-order listings of the trees: Tree 1: 10 Tree 2: 10 12 Tree 3: 1 12 10 Tree 4: 1 12 10 14 Tree 5: 1 6 10 14 12 Tree 6: Tree 7: 1 6 5 14 12 10 1 6 5 14 12 10 8 Tree 8: 1 6 5 14 12 10 8 15 Tree 9: 1 3 5 6 12 10 8 15 14 Tree 10: 1 3 5 6 9 10 8 15 14 12 Tree 11: 1 3 5 6 7 10 8 15 14 12 9 Tree 12: Tree 13: 1 3 4 6 7 5 8 15 14 12 9 10 1 3 4 6 7 5 8 15 14 12 9 10 11 Tree 14: 1 3 4 6 7 5 8 15 14 12 9 10 11 13 Tree 15: 1 3 2 6 7 5 4 15 14 12 9 10 11 13 8 4

28. (20 pts) Write methods that take a reference to a binary tree root T, compute, and return the quantities specified in parts (a) and (b) below. Assume T is a reference to a BinaryNode object and that each node in the linked tree contains a key and pointers to left and right BinaryNode children. Include the code for any helper methods you use. a) The number of leaves in T. Method in BinaryTree class: public int countleaves(binarynode T) if (T == null) if (T.getLeft() == null && T.getRight() == null) return 1; return countleaves(t.getleft())+countleaves(t.getright()); b) The number of nodes in T that have one non-null child. Method in BinaryTree class: public int countsolos(binarynode T) if (T == null) if (T.getLeft()==null && T.getRight()==null) else if (T.getLeft()==null && T.getRight()!=null) return 1 + countsolos(getright()); if (T.getLeft()!=null && T.getRight()==null) return 1 + countsolos(getleft()) return countsolos(getleft())+countsolos(getright()); 5