Suppose that the following is from a correct C++ program:

Similar documents
Multiple choice questions. Answer on Scantron Form. 4 points each (100 points) Which is NOT a reasonable conclusion to this sentence:

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?

Part I: Short Answer (12 questions, 65 points total)

double d0, d1, d2, d3; double * dp = new double[4]; double da[4];

CSE 250 Final Exam. Fall 2013 Time: 3 hours. Dec 11, No electronic devices of any kind. You can open your textbook and notes

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

Day 10. COMP1006/1406 Summer M. Jason Hinek Carleton University

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

MID TERM MEGA FILE SOLVED BY VU HELPER Which one of the following statement is NOT correct.

Computer Science 302 Spring 2007 Practice Final Examination: Part I

(b) int count = 0; int i = 1; while (i<m) { for (int j=i; j<n; j++) { count = count + 1; i = i + 1; O(M + N 2 ) (c) int count = 0; int i,j,k; for (i=1

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

Solution to CSE 250 Final Exam

Largest Online Community of VU Students

Basic Data Structures (Version 7) Name:

CMSC 341 Lecture 10 Binary Search Trees

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

Computer Science 302 Spring 2017 (Practice for) Final Examination, May 10, 2017

MIDTERM EXAMINATION Spring 2010 CS301- Data Structures

DATA STRUCTURES AND ALGORITHMS

CSCE 2014 Final Exam Spring Version A

Recitation 9. Prelim Review

Trees. Chapter 6. strings. 3 Both position and Enumerator are similar in concept to C++ iterators, although the details are quite different.

Chapter 20: Binary Trees

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

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

CSE 143 Sp03 Final Exam Sample Solution Page 1 of 13

O(n): printing a list of n items to the screen, looking at each item once.

Data Structures Question Bank Multiple Choice

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

CS134 Spring 2005 Final Exam Mon. June. 20, 2005 Signature: Question # Out Of Marks Marker Total

Summer Final Exam Review Session August 5, 2009

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

CSE373: Data Structure & Algorithms Lecture 21: More Comparison Sorting. Aaron Bauer Winter 2014

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

! Determine if a number is odd or even. ! Determine if a number/character is in a range. - 1 to 10 (inclusive) - between a and z (inclusive)

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

CS126 Final Exam Review

COMP Data Structures

MARKING KEY The University of British Columbia MARKING KEY Computer Science 260 Midterm #2 Examination 12:30 noon, Thursday, March 15, 2012

Lecture 15 Binary Search Trees

CSE 2320 Section 002, Fall 2015 Exam 2 Time: 80 mins

n 2 C. Θ n ( ) Ο f ( n) B. n 2 Ω( n logn)

CSE143 Exam with answers MIDTERM #1, 1/26/2001 Problem numbering may differ from the test as given.

Course Review for Finals. Cpt S 223 Fall 2008

Instructions. Definitions. Name: CMSC 341 Fall Question Points I. /12 II. /30 III. /10 IV. /12 V. /12 VI. /12 VII.

Prelim 2 SOLUTION. 5:30 PM, 25 April Total Question Name Short Search/ Collections Trees Graphs

Discussion 2C Notes (Week 8, February 25) TA: Brian Choi Section Webpage:

20 Some terminology regarding trees: Parent node: A node that has branches. Parent nodes can have multiple branches.

COS 226 Algorithms and Data Structures Fall Midterm

Binary Search Trees Treesort

INF2220: algorithms and data structures Series 1

CSE373 Fall 2013, Final Examination December 10, 2013 Please do not turn the page until the bell rings.

"sort A" "sort B" "sort C" time (seconds) # of elements

Exam I Principles of Imperative Computation, Summer 2011 William Lovas. May 27, 2011

Lecture 15 Notes Binary Search Trees

Tree: non-recursive definition. Trees, Binary Search Trees, and Heaps. Tree: recursive definition. Tree: example.

Binary Trees

CS2223: Algorithms Sorting Algorithms, Heap Sort, Linear-time sort, Median and Order Statistics

Programming II (CS300)

Unit 10: Sorting/Searching/Recursion

CSE 373 MAY 24 TH ANALYSIS AND NON- COMPARISON SORTING

COMP : Trees. COMP20012 Trees 219

( ) n 3. n 2 ( ) D. Ο

INF2220: algorithms and data structures Series 1

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

STUDENT LESSON AB30 Binary Search Trees

Prelim 2, CS2110. SOLUTION

Trees. Tree Structure Binary Tree Tree Traversals

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Sorting lower bound and Linear-time sorting Date: 9/19/17

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

Algorithmic Analysis. Go go Big O(h)!

Programming II (CS300)

Prelim 2. CS 2110, November 19, 2015, 7:30 PM Total. Sorting Invariants Max Score Grader

COMP 250 Fall recurrences 2 Oct. 13, 2017

Tree Data Structures CSC 221

II (Sorting and) Order Statistics

Section 1: True / False (2 points each, 30 pts total)

Binary Tree Node Relationships. Binary Trees. Quick Application: Expression Trees. Traversals

Binary Trees. For example: Jargon: General Binary Trees. root node. level: internal node. edge. leaf node. Data Structures & File Management

CSE373 Fall 2013, Final Examination December 10, 2013 Please do not turn the page until the bell rings.

COS 226 Midterm Exam, Spring 2009

Lecture Notes on Binary Search Trees

I. Algorithms. examples of cubic, quadratic, NlogN, linear, logarithmic, and constant

21# 33# 90# 91# 34# # 39# # # 31# 98# 0# 1# 2# 3# 4# 5# 6# 7# 8# 9# 10# #

Priority Queues (Heaps)

9. The expected time for insertion sort for n keys is in which set? (All n! input permutations are equally likely.)

CMSC 341. Binary Search Trees CMSC 341 BST

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

CSE 530A. B+ Trees. Washington University Fall 2013

) $ f ( n) " %( g( n)

Sorting. Task Description. Selection Sort. Should we worry about speed?

CPSC 311 Lecture Notes. Sorting and Order Statistics (Chapters 6-9)

Computer Science E-22 Practice Final Exam

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

Review for Test 1 (Chapter 1-5)

Algorithms and Data Structures

CSE 332: Data Structures & Parallelism Lecture 12: Comparison Sorting. Ruth Anderson Winter 2019

Measuring algorithm efficiency

Binary Trees. Directed, Rooted Tree. Terminology. Trees. Binary Trees. Possible Implementation 4/18/2013

Transcription:

All multiple choice questions are equally weighted. You can generally assume that code shown in the questions is intended to be syntactically correct, unless something in the question or one of the answers suggests otherwise. 1. When an array is to be sorted, it may happen that some data values start out being in the same position where they should end up. For example, in the array which is originally 40-1 33 0 the 33 is right where it will be in the final sorted output: -1 0 33 40 But as a particular sorting algorithm operates, it might (depending on the algorithm) move such an element out of the position where it belongs (of course, it will eventually get moved back). Which of the following statements are true? I. Mergesort never (even temporarily) moves such an element. II. Quicksort never (even temporarily) moves such an element. III. Selection sort never (even temporarily) moves such an element. D. I and III E. II and III 2. Suppose that the following is from a correct C++ program: bp = new bicycle("built for two", 2, 4); What can be deduced from this? I. bicycle is the name of a concrete (non-abstract) class. II. bp was declared as a pointer to bicycle or to some base class of bicycle. III. bp was declared as a pointer to bicycle or to some class derived from bicycle. D. I and II only E. I and III only

Final CSE 143, Summer 2000 Page 2 3. Two algorithms, A and B, which solve the same problem, are analyzed, and it is found that B s asymptotic running time is greater than A s. A and B are then implemented (carefully and correctly) as programs and tested on various data sets. What is the best prediction? I. A will always run faster than B. II. B will always run faster than A. III. As the size of the test data increases, A is more and more likely to run faster than B. IV. As the size of the test data increases, B is more and more likely to run faster than A. D. IV only E. No predictions are possible without knowing the make and model of the computer used for testing. 4. int findmax(int array[], int arraysize) { int max = array[0]; for (int i = 1; i < arraysize; i++) { if (max < array[i]) max = array[i]; return max; This function is intended to find the largest value in an array of integers, under the precondition arraysize >=1. Suppose an additional precondition for this function is given as array[i] <= array[i+1] for all i from 0 to arraysize-2. What is true about the function, as coded? I. The function returns the correct answer only for those arrays which meet the new precondition. II. The function returns the correct answer faster for arrays which meet the new precondition. III. There is a much faster algorithm which returns the correct answer for all arrays meeting both preconditions. D. I and II only E. II and III only

Final CSE 143, Summer 2000 Page 3 5. In the following code fragment, Q is a queue of integers: Q.insert(1); while (!Q.isEmpty() ) { int f = Q.getFront(); if (f > 10) f = Q.dequeue(); else Q.enqueue(f+1); The last time through this loop, what value is removed from the queue? A. 1 B. 9 C. 10 D. 11 E. can t tell---infinite loop 6. Suppose a tree has 7 nodes and a height of 3. (Our definition has the root at level 1.) What is true? I. The tree must be a binary tree. II. The tree cannot be a binary tree. III. The tree has at least one node at level 3. IV. At least one node at level 3 is not a leaf. D. I and IV only E. II and IV only 7. A function which maps a key to an index or bucket number is called a A. accessor method B. overloaded index function C. hash function D. leaky bucket function E. retrieve function

Final CSE 143, Summer 2000 Page 4 8. The preorder traversal of a certain binary search tree is 10 5 3 2 15 12 20 If the value 11 is then added to this tree, what is the preorder traversal of the resulting tree? (hint: First, draw the tree, using the fact that it is a search tree.) A. 11 10 5 3 2 15 12 20 B. 10 11 5 3 2 15 12 20 C. 10 5 3 2 11 15 12 20 D. 10 5 3 2 15 11 12 20 E. 10 5 3 2 15 12 11 20 9. Rank the following (1-7) into increasing order of growth, with 1 as smallest (slowest growing) and 7 as largest (fastest growing): constant cubic exponential linear logarithmic n log n quadratic Having done this, which are the entries with ranks 5 and 6? A. 5. exponential 6. quadratic B. 5. quadratic 6. cubic C. 5. constant 6. quadratic D. 5. n log n 6. exponential E. 5. logarithmic 6. cubic 10. In the mergesort algorithm, what is the asymptotic running time of the step of merging sorted subarrays? A. O(log n) B. O(n) C. O(n log n) D. O(n 2 ) E. O(n 2 log n)

Final CSE 143, Summer 2000 Page 5 11. Suppose the partition function (of quicksort) is called on this array: 4 7 6 5 1 8 0 Which of the arrays below could result from the call, i.e. which of them satisfies the postconditions of partition? (Assume partition chooses the first element as the pivot.) A. 1 0 4 5 6 8 7 B. 4 0 1 5 6 8 7 C. 4 0 1 5 6 7 8 D. 1 0 5 4 6 8 7 E. 4 8 7 6 5 1 0 12. Which of these sorting algorithms has the best (lowest) asymptotic running time when the input list is already sorted? I. insertion sort II. selection sort III. quicksort (choosing the first element of the array as the pivot) IV. mergesort A. I B. II C. III D. IV E. III and IV, with the same asymptotic running time 13. Consider the following definition of class A: class A { private: void foo(int, int) = 0; public: void bar(double x); void baz(double x, double y); void quax(double xyz[]); Which of the following is true about the declaration of foo within A? A. The declaration is illegal because it does not specify argument names. B. The declaration is not logical because the method cannot be called by client code. C. The declaration is illegal because the method is not virtual. D. The declaration is not logical because the other methods cannot call foo. E. The declaration may be both legal and logical, depending on the other code in the program.

Final CSE 143, Summer 2000 Page 6 14. Suppose v is the value of a node N in a binary search tree. Assume that there is a value higher than v in the tree. Among all the values in the tree, where is that next larger value located? A. somewhere in the left subtree of N B. in the right child of N (always) C. always somewhere in the right subtree of N, athough not necessarily in the right child itself D. in the parent node of N (always) E. sometimes in the right subtree of N, sometimes in the parent of N 15. class A { //... class B : public A { //... class C : public A { //... A* ap = new A; B* bp = new B; C* cp = new C; int main() { // Which of the following assignments raises a COMPILE-time error? ap = bp; *ap = *cp; bp = cp; // I // II // III return 0; D. II and III only E. none

Final CSE 143, Summer 2000 Page 7 16. void foo(int N) { int temp = 0; for (int i = 0; (i < N) && (temp < N); i++) for (int j = 0; j < N; j++) temp++; Chose the correct statement. (hint: First figure out what the function does, then analyze its complexity.) A. If f(n) represents the running time function of foo, then f(n) = 2 + N(4 + 3N). (The constants 2, 4 and 3 could be off by 1 or 2.) B. The asymptotic complexity of foo does not depend on N, i.e. it is O(1) (constant). C. The asymptotic complexity of foo is O(N). D. The asymptotic complexity of foo is O(N 2 ). E. The asymptotic complexity cannot be analyzed without knowing the value of N. 17. #include <iostream.h> class Base { public: virtual void foo() { bar(); protected: virtual void bar() { cout << "base "; class Derived : public Base { public: virtual int foo(int x) { return x; protected: virtual void bar() { cout << "derived "; void main() { Base *baseptr1 = new Base(); Base *baseptr2 = new Derived(); baseptr1->foo(); baseptr2->foo(); Given the program above, choose the statement which is true: A. The program outputs "base base ". B. The program outputs "derived derived ". C. The program outputs "base derived ". D. The program won t compile, because Derived does not define void foo(). E. The program won t compile, because method call baseptr2->foo() is illegal.

Final CSE 143, Summer 2000 Page 8 18. Programming Problem (worth 4 multiple choice questions) There are many different ways a set of values could be arranged in a binary search tree. Two trees are called "content-equal" if they contain exactly the same node values, regardless of how the nodes are arranged in the tree. Design and implement the function iscontenteq, which should return true if and only if the two given binary search trees are "content-equal." You may assume that neither tree contains duplicate values. Make no assumptions about how large or deep the trees are. You must use the function prototype and tree node definition shown below. You may not modify the trees. If you call any functions, you must provide full code for them. A. Give an overview (in English) of how your algorithm will operate. (PROBLEM CONTINUES ON NEXT PAGE) // Use this definition of a tree node (without modification): struct BinTreeNode { double value; BinTreeNode *left, *right; // Use this prototype: bool iscontenteq(bintreenode *T1, BinTreeNode *T2);

Final CSE 143, Summer 2000 Page 9 B. Implement the function iscontenteq. Remember, if you call any helper functions, you must fully declare and implement them. // Use this definition of a tree node (without modification): struct BinTreeNode { double value; BinTreeNode *left, *right; // Use this prototype: bool iscontenteq(bintreenode *T1, BinTreeNode *T2);