Draw the resulting binary search tree. Be sure to show intermediate steps for partial credit (in case your final tree is incorrect).

Similar documents
CSE 373 Autumn 2012: Midterm #2 (closed book, closed notes, NO calculators allowed)

A6-R3: DATA STRUCTURE THROUGH C LANGUAGE

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

CSE 373 Winter 2009: Midterm #1 (closed book, closed notes, NO calculators allowed)

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

Test #2. Login: 2 PROBLEM 1 : (Balance (6points)) Insert the following elements into an AVL tree. Make sure you show the tree before and after each ro

CLO Assessment CLO1 Q1(10) CLO2 Q2 (10) CLO3 Q4 (10) CLO4 Q3a (4)

1. AVL Trees (10 Points)

CS102 Binary Search Trees

CSE373 Winter 2014, Midterm Examination January 29, 2014

CS301 - Data Structures Glossary By

CSE 332 Autumn 2013: Midterm Exam (closed book, closed notes, no calculators)

CSE373 Fall 2013, Midterm Examination October 18, 2013

CS210 (161) with Dr. Basit Qureshi Final Exam Weight 40%

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

Data Structures and Algorithms

CS 112 Final May 8, 2008 (Lightly edited for 2012 Practice) Name: BU ID: Instructions

CSCI212 Computer Science. Binary Trees/Heaps/Binary Search Trees

University of Waterloo Department of Electrical and Computer Engineering ECE 250 Data Structures and Algorithms. Final Examination

PROGRAMMING IN C++ (Regulation 2008) Answer ALL questions PART A (10 2 = 20 Marks) PART B (5 16 = 80 Marks) function? (8)

Final Examination CSE 100 UCSD (Practice)

Introduction p. 1 Pseudocode p. 2 Algorithm Header p. 2 Purpose, Conditions, and Return p. 3 Statement Numbers p. 4 Variables p. 4 Algorithm Analysis

CSE 332 Spring 2014: Midterm Exam (closed book, closed notes, no calculators)

A6-R3: DATA STRUCTURE THROUGH C LANGUAGE

Section 4 SOLUTION: AVL Trees & B-Trees

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

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

CS 112 Data Structures. Midterm Exam 1

CS 361 Data Structures & Algs Lecture 11. Prof. Tom Hayes University of New Mexico

Selection, Bubble, Insertion, Merge, Heap, Quick Bucket, Radix

ITI Introduction to Computing II

ITI Introduction to Computing II

CS171 Final Practice Exam

CS 314 Final Fall 2011

CSE Data Structures and Introduction to Algorithms... In Java! Instructor: Fei Wang. Mid-Term Exam. CSE2100 DS & Algorithms 1

Prelim 2. CS 2110, November 20, 2014, 7:30 PM Extra Total Question True/False Short Answer

EECS 311 Data Structures Midterm Exam Don t Panic!

Lecture Summary CSC 263H. August 5, 2016

Collection of priority-job pairs; priorities are comparable.

CS200 Midterm 2 Fall 2007

CSE 332 Winter 2015: Midterm Exam (closed book, closed notes, no calculators)

CSE 373 Sample Midterm #2 (closed book, closed notes, calculators o.k.)

CS 104 (Spring 2014) Final Exam 05/09/2014

1) What is the primary purpose of template functions? 2) Suppose bag is a template class, what is the syntax for declaring a bag b of integers?

3. Priority Queues. ADT Stack : LIFO. ADT Queue : FIFO. ADT Priority Queue : pick the element with the lowest (or highest) priority.

CS171 Final Practice Exam

Programming II (CS300)

- Alan Perlis. Topic 24 Heaps

Test 2: CPS 103 Owen Astrachan November 19, 1993 Name: Honor code acknowledgement (signature) Problem 1 value 9 pts. grade Problem 2 12 pts. Problem 3

Data Structures CSCI C343, Fall 2016

Second Examination Solution

CSCE 210/2201 Data Structures and Algorithms. Prof. Amr Goneid

CSCE 210/2201 Data Structures and Algorithms. Prof. Amr Goneid. Fall 2018

CSE 100 Practice Final Exam

BRONX COMMUNITY COLLEGE of the City University of New York DEPARTMENT OF MATHEMATICS AND COMPUTER SCIENCE. Sample Final Exam

Midterm II Exam Principles of Imperative Computation Frank Pfenning. March 31, 2011

Computer Science 302 Fall 2009 (Practice) Second Examination, October 15, 2009

CSC2100-Data Structures

Name Section Number. CS210 Exam #3 *** PLEASE TURN OFF ALL CELL PHONES*** Practice

Total No. of Questions :09] [Total No. of Pages : 02. II/IV B.Tech. DEGREE EXAMINATIONS, NOV/DEC First Semester CSE/IT DATA STRUCTURES USING C

list<t>::const_iterator it1 = lst.begin(); // points to first element list<t>::const_iterator it2 = lst.begin(); // points to second element it2++;

CS 310: Priority Queues and Binary Heaps

Priority Queues and Huffman Trees

PROBLEM 1 : (And the winner is...(12 points)) Assume you are considering the implementation of a priority queue that will always give you the smallest

CS61BL: Data Structures & Programming Methodology Summer 2014

A grossly unbalanced tree, with some long paths. Next to add: When does it occur? Why is it undesirable?

Priority Queues. 1 Introduction. 2 Naïve Implementations. CSci 335 Software Design and Analysis III Chapter 6 Priority Queues. Prof.

Algorithms and Data Structures

4/18/ Binary Search Trees (BSTs) 17.1 Adding an Element to a BST Removing an Element from a BST. 17.

Lecture 13: AVL Trees and Binary Heaps

Priority Queues. 04/10/03 Lecture 22 1

CPSC 211, Sections : Data Structures and Implementations, Honors Final Exam May 4, 2001

Algorithm Analysis Advanced Data Structure. Chung-Ang University, Jaesung Lee

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

University of Illinois at Urbana-Champaign Department of Computer Science. Final Examination

Data Structures Brett Bernstein

MLR Institute of Technology

CSE 373 Final Exam 3/14/06 Sample Solution

Priority Queues Heaps Heapsort

Section 1: True / False (1 point each, 15 pts total)

UNIVERSITY REGULATIONS

Data Structures Question Bank Multiple Choice

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

York University AK/ITEC INTRODUCTION TO DATA STRUCTURES. Final Sample II. Examiner: S. Chen Duration: Three hours

CISC 320 Midterm Exam

Binary Search Trees Treesort

Algorithms, Spring 2014, CSE, OSU Lecture 2: Sorting

Definition of a Heap. Heaps. Priority Queues. Example. Implementation using a heap. Heap ADT

FINAL EXAMINATION. COMP-250: Introduction to Computer Science - Fall 2011

Priority Queues. T. M. Murali. January 23, T. M. Murali January 23, 2008 Priority Queues

Algorithm Design (8) Graph Algorithms 1/2

INFO1x05 Tutorial 09

Design and Analysis of Algorithms - Chapter 6 6

CPSC 331 Term Test #2 March 26, 2007

Recitation 9. Prelim Review

CISC-235* Test #3 March 19, 2018

Trees & Tree-Based Data Structures. Part 4: Heaps. Definition. Example. Properties. Example Min-Heap. Definition

Priority Queues (Heaps)

INSTITUTE OF AERONAUTICAL ENGINEERING

Priority Queues. T. M. Murali. January 29, 2009

Transcription:

Problem 1. Binary Search Trees (36 points) a) (12 points) Assume that the following numbers are inserted into an (initially empty) binary search tree in the order shown below (from left to right): 42 36 15 11 4 59 82 8 25 1 Draw the resulting binary search tree. Be sure to show intermediate steps for partial credit (in case your final tree is incorrect). 1

(b) (12 points) For this problem, please note that when you remove a node that has two children, you have two ways to go about it. If you choose one way, you must be consistent and choose the same way throughout this problem. Remove the following nodes from the above Binary Search Tree in the specified order: 17, 20 26 Draw the resulting binary search tree after these removals are done. Be sure to show intermediate steps if you want partial credit (in case your final tree is incorrect). 2

c) (12 points) Write the code for a templated member function of the class BinarySearchTree to insert a new value into a binary search tree (this includes the code for finding where to insert the node as well as inserting it). Be sure to check if the user enters a duplicate value. Feel free to add whatever other member functions or member variables you need (if any). The next page is blank if you need more room to work. You are only responsible for writing the actual insert function and you may assume that the following code declarations already exist: template <typename T> class BTNode{ public: BTNode(T& d) : data(d) { left = NULL; right = NULL; } T data; BTNode<T>* left; BTNode<T>* right; }; template <typename T> class BinarySearchTree { private: BTNode<T>* root; public: void insert(t& value); }; 3

(This problem intentionally left blank so you can use this page for whatever you want.) 4

Problem 2. AVL & Balance Trees(14 points) a) (8 points) Calculate the balance factor for each node in the tree 5

b) (3 points) Is this tree balanced? If not, which nodes would need to be balanced? c) (3 points) Why is balance important for binary search trees? How does it affect Big O? 6

Problem 3. Heaps (20 points) a) (12 points) A binary heap is an array-based data structure that can be viewed as a nearly-complete binary tree structure. You are given an array with the following elements (in sequence): 83 24 46 13 20 69 7 35 The elements currently do not satisfy the Max Heap Property. Please make the array into a Max Heap by performing a sequence of Max-Heapify operations, starting from the bottom of the tree. Please draw all intermediate trees whenever elements are swapped in order to receive full credit. Feel free to add additional text and/or drawings if you want to help explain what you are doing. Please also show what the resulting array would look like. 7

b) (8 points) Explain the algorithm for the Extract Max operation (removing and returning the maximum value node) from a Priority Queue that is based on a Max Heap (including the details of how the tree is rearranged to make sure it still obeys the max heap property). You may use your answer for the Max Heap above as an example. 8

Problem 4. Graphs (20 points) a) (5 points) Draw the Adjacency Matrix for the above graph 9

b) (5 points) Draw the Adjacency List for the above graph c) (5 points) Write out the order in which the vertexes in the graph would be visited if a Breadth-First Search were started from vertex C given the above adjacency list representation of the graph. (NOTE: There is only one correct answer since you must use the given adjacency list and follow the rules of accessing such a data structure.) d) (5 points) Write out the order in which the vertexes in the graph would be visited if a Depth-First Search were started from vertex C given the above adjacency list representation of the graph. (NOTE: There is only one correct answer since you must use the given adjacency list and follow the rules of accessing such a data structure.) 10

Problem 5. Short Answers (20 points) a) (5 points) What are the two most common strategies for handling collisions in a hash table? Name them and explain how each of them works. b) (5 points) What is Big O for searching, inserting, and removing for a hash table with a perfect/ideal hashing function? What about with the worst possible hash function? 11

c) (5 points) What is Big O for searching, inserting, and removing for a binary search tree? Why is it sometimes better to use a Red/Black Tree or AVL tree instead of a normal Binary Search Tree? d) (5 points) A binary heap can be viewed as a nearly-complete binary tree structure. What is the Max Heap Property for a binary heap? What is Big O for searching, inserting, and removing for a binary heap? 12

EXTRA CREDIT (10 points) A Priority Queue is represented by the following Min Heap: 4 10 22 40 12 36 55 87 61 29 33 48 a) (3 points) Draw the Min Heap b) (7 points) Perform Extract Min on the Priority Queue (removing and returning the minimum value node) and draw the resulting Min Heap. Please show intermediate steps for partial credit. 13