Midterm Examination #1 CSE 100. (practice)

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

From Last Time: Remove (Delete) Operation

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

Full and Complete Binary Trees

- Easy to insert & delete in O(1) time - Don t need to estimate total memory needed. - Hard to search in less than O(n) time

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:

Ordered Lists and Binary Trees

Binary Search Trees (BST)

Binary Heaps. CSE 373 Data Structures

CSE 326: Data Structures B-Trees and B+ Trees

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

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

Symbol Tables. Introduction

Converting a Number from Decimal to Binary

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

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

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

TREE BASIC TERMINOLOGIES

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

Introduction Advantages and Disadvantages Algorithm TIME COMPLEXITY. Splay Tree. Cheruku Ravi Teja. November 14, 2011

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

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

Persistent Binary Search Trees

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

Data Structures and Algorithms

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

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

A Comparison of Dictionary Implementations

Data Structures and Algorithms Written Examination

Data Structures and Data Manipulation

Binary Search Trees CMPSC 122

Chapter 14 The Binary Search Tree

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

6 March Array Implementation of Binary Trees

Lecture 1: Data Storage & Index

Data Structures Fibonacci Heaps, Amortized Analysis

Why Use Binary Trees?

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

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)

Binary Search Trees. Ric Glassey

Physical Data Organization

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

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

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

Review of Hashing: Integer Keys

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

Algorithms Chapter 12 Binary Search Trees

CompSci-61B, Data Structures Final Exam

Lecture 4: Balanced Binary Search Trees

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

Lecture Notes on Binary Search Trees

Structure for String Keys

B+ Tree Properties B+ Tree Searching B+ Tree Insertion B+ Tree Deletion Static Hashing Extendable Hashing Questions in pass papers

Exam study sheet for CS2711. List of topics

Motivation Suppose we have a database of people We want to gure out who is related to whom Initially, we only have a list of people, and information a

S. Muthusundari. Research Scholar, Dept of CSE, Sathyabama University Chennai, India Dr. R. M.

The ADT Binary Search Tree

Optimal Binary Search Trees Meet Object Oriented Programming

CS 464/564 Introduction to Database Management System Instructor: Abdullah Mueen

Big Data and Scripting. Part 4: Memory Hierarchies

Operations: search;; min;; max;; predecessor;; successor. Time O(h) with h height of the tree (more on later).

Analysis of a Search Algorithm

Analysis of Algorithms I: Binary Search Trees

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

Data Structure with C

CS 2112 Spring Instructions. Assignment 3 Data Structures and Web Filtering. 0.1 Grading. 0.2 Partners. 0.3 Restrictions

PES Institute of Technology-BSC QUESTION BANK

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

Rotation Operation for Binary Search Trees Idea:

Algorithms and Data Structures Written Exam Proposed SOLUTION

Lecture 11 Doubly Linked Lists & Array of Linked Lists. Doubly Linked Lists

DATA STRUCTURES USING C

Mathematical Induction. Lecture 10-11

International Journal of Software and Web Sciences (IJSWS)

CIS 631 Database Management Systems Sample Final Exam

Data Warehousing und Data Mining

7.1 Our Current Model

Union-Find Problem. Using Arrays And Chains

Lecture Notes on Binary Search Trees

Talend Open Studio for MDM. Getting Started Guide 6.0.0

10CS35: Data Structures Using C

Lecture 2 February 12, 2003

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

An Evaluation of Self-adjusting Binary Search Tree Techniques

Data Structures. Level 6 C Module Descriptor

Fundamental Algorithms

Binary Trees and Huffman Encoding Binary Search Trees

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

Excel Database Management

CS 245 Final Exam Winter 2013

Introduction to Algorithms March 10, 2004 Massachusetts Institute of Technology Professors Erik Demaine and Shafi Goldwasser Quiz 1.

Creating Surveys Using SurveyMonkey

The following themes form the major topics of this chapter: The terms and concepts related to trees (Section 5.2).

DATABASE DESIGN - 1DL400

How to Make the Most of Excel Spreadsheets

Analysis of Algorithms I: Optimal Binary Search Trees

University of Massachusetts Amherst Department of Computer Science Prof. Yanlei Diao

Chapter 8: Structures for Files. Truong Quynh Chi Spring- 2013

Randomized Binary Search Trees

Transcription:

Midterm Examination #1 () RULES: 1. Don t start the exam until the instructor says to. 2. This is a closed-book, closed-notes, no-calculator exam. Don t refer to any materials other than the exam itself. 3. Write your name, and your login name, on each page of the exam when you get to it. Think carefully about each question. Before you turn in your exam, make sure you have all the pages. The last page is blank and can be used as scratch paper. 4. Do not look at anyone else s exam. Do not talk to anyone but an exam proctor during the exam. If you re wearing a billed cap, please turn it around or take it off. And turn off cell phones and other devices. 5. If you have a question, raise your hand and an exam proctor will come to you. 6. You have until the end of the class period to finish the exam. When you are done, give your exam to a proctor. The proctor will check your picture ID and sign the ID check below. 7. Your exam grade will be emailed to your account this week. Exams will be handed back in lecture next week. # Type max pts actual pts 1. General TF 19 2. General MC 15 3. Skip Lists 12 4. Treaps 12 5. Pointers 12 TOTAL 70 grader: PROCTOR ID CHECK: Page 0 of 6

1. [19 pts.] (1 pt each correct; -1 pt each incorrect; 0 pt if left blank) True or False: a. A treap is a binary tree. b. The height of a randomized search tree is always less than 2N, where N is the number of leaves in the tree. c. In a red-black tree with N nodes, any path from the root to another node contains no more than 2 log 2 (N+1) + 2 nodes. d. In a red-black tree, every path from the root to a null reference contains the same number of red nodes. e. A treap always satisfies the AVL balance property. f. In an AVL tree, the levels of any two leaves can differ by at most 1. g. Every subtree of a treap is itself a treap. h. Every subtree of a AVL tree is itself an AVL tree. i. Treaps and linked lists have the same big-o worst-case time cost for insert operations. j. Skip lists and randomized search trees have the same big-o worst-case time costs for find operations. k. In a skip list, the values of the priorites associated with keys that have been inserted determine which key is in the first node of the list. l. An AVL double rotation consists of two AVL single rotations. m. The result of any AVL rotation in a BST is always a BST. n. The C++ class hierarchy is a tree whose root is the Object class. o. AVL trees are considered to be more difficult to implement than randomized search trees. p. In C++, an iterator for the std::set container will iterate over the elements in the set in sorted order. q. In C++, the end() method of the std::vector class returns an iterator pointing at the last element in the vector. r. In C++, storage for objects created dynamically using new is automatically reclaimed by the garbage collector when the objects can no longer be accessed in your program. s. In C++, * is a pointer dereference operator. Page 1 of 6

2. [15 pts] (3 pts each) Multiple choice. Write the capital letter of the best answer in the blank provided. a. Using the usual probabilistic assumptions, the average case number of comparisons for successful search in a binary search tree vs. a randomized search tree (RST) with the same number of nodes is A. much worse than RST B. slightly worse than RST C. the same as RST D. much better than RST E. slightly better than RST b. Suppose T is a completely filled binary search tree with 7 nodes. The worst-case number of comparisons for a successful find operation in T is A. 1 B. 2 C. 3 D. 6 E. 7 c. Suppose T is a completely filled binary search tree with 7 nodes. The best-case number of comparisons for a successful find operation in T is A. 1 B. 2 C. 3 D. 4 E. 7 d. Suppose T is a binary search tree with 7 nodes, only one of which is a leaf. Suppose all keys are equally likely. The integer closest to the average-case number of comparisons for a successful find operation in T is A. 1 B. 2 C. 3 D. 4 E. 7 e. Suppose T is a completely filled binary search tree with 7 nodes. Suppose all keys are equally likely. The integer closest to the average-case number of comparisons for a successful find operation in T is A. 1 B. 2 C. 3 D. 6 E. 7 Page 2 of 6

3. [12 pts] The following integer keys were inserted in this sequence into an initially empty skip list: 7, 3, 1, 6, 4 In doing these insertions, the following sequence of node levels (i.e., number of forward pointers) was generated by the skip list s random level generator: 3, 1, 2, 4, 1 Answer the following multiple-choice questions about the resulting skip list by writing the letter of the answer in the space provided. Assume 0-based indexing of pointers within nodes. The possible answers are these: A: the node containing key 1 B: the node containing key 3 C: the node containing key 4 D: the node containing key 6 E: the node containing key 7 F: the skip list header node G: null H: error! There is no pointer with that description. a. The skip list header has an index 2 pointer pointing at: b. The node containing key 1 has an index 1 pointer pointing at: c. The node containing key 3 has an index 3 pointer pointing at: d. The node containing key 6 has an index 3 pointer pointing at: e. The node containing key 4 has an index 0 pointer pointing at it from: f. The node containing key 7 has an index 1 pointer pointing at it from: Page 3 of 6

4. [12 pts total] In the following treaps, keys are characters, with alphabetic ordering; priorities are integers. a. [6 pts] Consider the Treap #1a as the treap used internally by a randomized search tree (RST). A client of this RST now inserts key A into the RST, and the RST implementation s random number generator generates a priority of 30 for this key. Show the resulting Treap #2a after this insert operation is complete: Treap #1a: H,50 Treap #2a: C,35 K,29 B,24 G,33 Q,28 F,25 b. [6 pts] Usually one assumes all keys in a treap to be equally likely to be searched for, but if some keys are less likely than others, moving them farther from the root can improve average case search times. The operation used to implement this is the priority lowering operation, in which a node s priority is decreased and rotations are performed as needed to restore the treap properties. Suppose key H was identified in Treap #1b, and the priority of the node containing H was decreased from 50 to 20. Show the resulting Treap #2b after the priority lowering operation is complete: Treap #1b: H,50 Treap #2b: C,35 K,29 B,24 G,33 Q,28 F,25 E,10 Page 4 of 6

5. [12 pts total] Consider these C++ declarations. After some computation, the current state of memory is as shown. Null pointers are shown as 0; non-null pointers are shown with an arrow indicating what object they point to. class Node { current state of memory: public: Node* l; Node* r; x: }; Node* x; Node* y; y: 0 l: 0 r: l: 0 r: 0 l: 0 r: 0 a. [6 pts] Starting with the current state of memory shown above, consider the C++ code shown below. In the space to the right, draw the state of memory after this code executes. y = x->l; x->l = y->r; y->r = x; x: y: b. [6 pts] Again starting with the current state of memory shown above at the top of the page, consider the C++ code shown below. In the space to the right, draw the state of memory after this code executes. y = x->l->r; x->r->l = y; x->l->r = nullptr; x: y: Page 5 of 6

(blank paper) Page 6 of 6