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

Size: px
Start display at page:

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

Transcription

1 Multiple choice questions Answer on Scantron Form 4 points each (100 points) 1. Which is NOT a reasonable conclusion to this sentence: Multiple constructors for a class... A. are distinguished by the number of parameters and by the return type. B. are natural to have if there is more than one way to initialize a class instance. C. are an example of "overloading". D. all must have the same name. E. give the clients some choices about how to initialize an object Which is a good reason for defining private members of a class? A. So that the client cannot change internal data structures. B. So that you can provide accessor functions like getdata(). C. Because private is the default mode for class instance variables. D. Because it is more efficient to access private data than public data. E. All of the above. An example of a FIFO data structure would be a: A. List. B. Stack. C. Queue. D. Set. E. Table. Local variables... A. are automatically allocated and automatically deallocated. B. are sometimes automatically allocated and sometimes dynamically allocated. C. are initialized by the system to zero (if numeric or pointer type). D. may be explicitly deallocated by the programmer (if desired), although this is not necessary. E. must all be declared at the beginning of the function. int * countinglist (int n) // line 0 int * nums = new int[n]; // line 1 for (n=n ; n>= 0; n--) // line 2 nums[n] = n; // line 3 return nums; // line 4 The most serious problem with this code is: A. line 0 is in error, because int * cannot be used as a return type. B. line 1 is an error, because int[n] is illegal. C. In line 2, it is illegal to modify the parameter n, because it was not passed by reference. D. line 3 will have an array bounds error at one point in the loop E. line 4 is an error, because it creates a dangling pointer.

2 6. Suppose you see this in a correctly working program: Myclass * v1 = new Myclass [3]; From this alone, you can conclude with certainty: A. Myclass has a copy constructor. B. Myclass has a constructor with one argument. C. Myclass has a destructor. A. A only B. B only C. C only D. None of A, B, or C E. More than one of A, B, or C 7. Suppose you have a class mammal originally defined as: class mammal public: mammal (int);... private: int ribs; double brainsize;... ; Suppose you now want build a new class "whale" and inherit from mammal. The new class will need a data member called "fins" and a new constructor that takes one argument. "whale" also needs access to ribs and brainsize. What changes must you make to mammal to support this? A. Change public to protected. B. Change private to protected. C. Add the "fins" variable to the mammal class. A. A only B. B only C. C only D. A and C E. B and C 8. A commonly accepted view of Object-Oriented Programming holds that is is characterized by three things: A. Encapsulation, inheritance, and dynamic dispatching. B. Classes, recursion, and top-down design C. Functional decomposition, abstraction, and overloading. D. Post-modernism, constructivism, and cognito-intellectual deconstructionism. E. Objects, messages, and methods.

3 The worst case complexities for Linear and Binary Search are: A. linear: O(1) binary: O(N*logN) B. linear: O(N) binary: O(N) C. linear: O(N) binary: O(logN) D. linear: O(N*N) binary: O(N*Log N) E. linear: O(N) binary: O(N*N) Given the following code: void DoIt() MyClass c;... The destructor for c is called automatically A. When c is destroyed at the end of the program. B. When c.~myclass() is called in the program. C. When c is destroyed at the end of DoIt(). D. If c uses dynamic memory. E. If c does not use dynamic memory. 11. Which of the following statements about separate compilation is true: A. All.h files are compiled before the.cpp files. B. If an implementation file is changed, it is only necessary to recompile that implementation file. C. If a specification file is changed, it is only necessary to recompile the corresponding implementation file. D. If an implementation file is changed, then all the files that the implementation file depends on must also be recompiled. E. If an implementation file is changed, then all the files that rely on the corresponding specification file need to be recompiled.

4 12. A "deep" copy may be prefered over a "shallow copy" because: a. Deep copying is more efficient than shallow copying. b. Deep copying prevents inadvertent updates of shared structures. c. Deep copying allows the default destructor to be used in all cases. A. Only a is true. B. Only b is true. C. Only c is true. D. a and b are true. E. none are true. 13. Suppose an expression tree has inorder traversal * What is the value of the expression? A. 11 B. 13 C. 15 D. 21 E. Cannot be sure Which of the following statements are true: 1) 2n + 1 = O(n*n) 2) n*n = O(n*n-100) A. 1 is false, 2 is false B. 1 is false, 2 is true C. 1 is true, 2 is false D. 1 is true, 2 is true E. cannot be sure without knowing the value of n bool F(int low, int high) if (low >= high) return false; else return! F(low + 2, high + 1); Consider the state of A and B after the following two calls: bool A = F(5, 7); bool B = F(0, 4); A. A is false, B is false B. A is false, B is true C. A is true, B is false D. A is true, B is true E. The program does not terminate

5 16. Suppose that the class Snark has a copy constructor. At what points when in the following function is the copy constructor used? Snark F(Snark s) Snark t(s); t.snipe(); return t; A. Only when t is created. B. Only when the argument is passed to F and when the value is returned C. Only when t is created and when the snipe method is called D. Only when the argument is passed to F, when t is created, and when the value Is returned. E. Snarks can t have copy constructors. 17. class A public: virtual void fun(); ; class B : public A public: virtual void fun(); ; void A::fun() cout << "I am A. "; void B::fun() cout << "I am B. "; Suppose the following statements are executed - what is the result? A* a = new B; B* b = new A; a->fun(); b->fun(); A. I am A. I am B. B. I am A. I am A. C. I am B. I am A. D. I am B. I am B. E. Nothing, since the compiler would report an error.

6 18. Consider the following four statements: A. Although quicksort has average case run time of O(n log n), in the worst case quicksort can take quadratic time. B. If a function f(n) is always less than another function g(n), then f(n) = O(g(n)) C. Given an arbitrary binary tree, a postorder traversal of that tree will visit the nodes in the exact reverse order of a preorder traversal. D. Different binary search trees can have the same inorder traversal. A. A. is false B. B. is false C. C. is false D. D is false E. A, B, C, and D are true. 19. Consider the following four statements A. For a queue, "enqueue" and "dequeue" cancel each other out: an enqueue of any value followed by a dequeue leaves the queue in exactly the state it was in initially. B. assert( true ) at any point in a program will cause that program to immediately abort. C. The bool type with the values true and false, and the int type with the values 1 and 0 can both be used to represent boolean values, but 1 and 0 should be used when possible because it makes the program faster. D. Programs which have short variable names are generally faster than programs with long variables names. A. A is true B. B is true C. C is true D. D is true E. The statements A, B, C, and D are all false

7 20. Consider the following code fragment int k = 0; for (int i = 0; i < N; i += 1000) for (int j = 0; j < N; j += 1000) k++; double d = 0; double v = N * 0.001; while (d < 1000) d += v; Which statement most accurately characterizes the run time (as a function of N): A. O(N*N) but not O(N) B. O(N) but not O(N*N) C. O( N) D. O(N*N*N) but not O(N*N) E. The asymptotic run time depends on the compiler that is used. 21. int a[] = 2, 4, 6, 8, 10, 12, 14, 16, 18, 20; int whatisthis(int b[], int size) if (size == 1) return b[size - 1]; else return b[size] + whatisthis(b, size - 1); What is the result of the function call whatisthis(a, 4)? A. 10 B. 16 C. 24 D. 26 E Consider the following four statements A. In a binary tree with two nodes, the root is not a leaf node. B. A binary tree with n nodes has height at least O(log n). C. Finding an element in a binary search tree with n nodes runs in worst case O(n) time. D. Deleting a node in a binary search tree takes worst case O(log n) time. A. A is false. B. B is false. C. C is false. D. D is false. E. A, B, C, and D are true.

8 Suppose you are using a bucket hashing scheme in which each slot in your hash table contains a linked list in order to handle collisions. If you add n items to the hash table and they all happen to hash to the same location, how much time would you expect it to take to retrieve an item from the hash table? A. O(1) B. O(log n) C. O(n) D. O(n log n) E. O(n*n) Given the following statements: 1) Pure virtual functions are only present in abstract classes. 2) You can instantiate classes with pure virtual functions. 3) Pure virtual functions can be in the protected section of a class. Which of the following are true? A. statement 1 only. B. statement 2 only. C. statement 3 only. D. statements 1 and 3 only. E. all statements are true.

9 25. Given the following classes and function: class Base public: void print( ); virtual int value( ); ; class Derived : public Base public: void print( ); virtual int value( ); ; void Foo(Base* baseptr) baseptr->print( ); If the print( ) methods both call the value( ) method, and Foo is invoked with a Derived argument, which of the following is true about when baseptr->print( ) gets called? A. The Derived print( ) method is invoked, which calls the Base value( ) method. B. The Derived print( ) method is invoked, which calls the Derived value( ) method. C. The Base print( ) method is invoked, which calls the Base value( ) method. D. The Base print( ) method is invoked, which calls the Derived value( ) method. E. None of the above; you cannot pass a Derived argument to Foo( ).

10 Answer the following problems directly on the test paper points The following struct is used to define nodes of a doubly linked list: struct DoubleNode DoubleNode* next; DoubleNode* prev; int data; ; Give the code which removes a node from a doubly linked list, and returns the node to the free storage pool. (Don t forget that next and/or prev could be null, if the node is at the start or end of the list.) void SpliceOut(DoubleNode* dptr) assert(dptr!= NULL) dptr->prev->next = dptr->next; if (dptr->next!= NULL) dptr->next->prev= dptr->prev; delete dptr;

11 2. 20 points The depth of a node in a tree is the distance from the node to the root of the tree. (The root has depth 0). Give a recursive routine which determines the depth of a node with a given key value in a binary search tree. If there is no node of the given key value, then -1 is returned. The run time of your algorithm should be proportional to the height of the tree. Assume that tree nodes have the following structure: struct BSNode BSNode* left; BSNode* right; int key; ; int FindDepth(BSNode* root, int k) It s probably safe to skip this one.

12 3. 10 points Construct the binary expression tree for ((x + y) * z) + 2. Then show the pre-order, in-order, and post-order traversals of the tree. Tree: + / \ * 2 / \ + z / \ x y Pre-order: +*+xyz2 Post-order: xy+z*2+ In-order: x+y*z points Show the result of hashing the following integers into a table of size 9 using the hash function h(x) = 3x % 9. Assume that the buckets of the hash table are linked lists. Values to hash: 5, 10, 15, 20, 25, 30, 35, 40, 45 Skip this one

13 6. 10 points Show the result of inserting 18, 14, 9, and 8 into the following binary search tree. (Show the tree after the four values have been inserted in the order given. Make sure that the it is clear which are left children, and which are right children) will be inserted to the right of will be inserted to the left of 18 9 will be inserted to the right of 7 8 will be inserted to the left of 9 Show the result of delete the node 10 from the following binary search tree 13 moves to the root position. 15 is now the right child of is the left child of

14 7. 10 points Give short answers to the following questions. a.) If you were implementing an inheritance hierarchy of students, would you make 143_student a subclass of student, or student a subclass of 143_student? Why. 143_student is a subclass of student because it is a kind of student. b) What is the difference between dynamic dispatch and static dispatch? Dynamic dispatch happens at run-time. Static dispatch happens at compile time. c) Give an example of a has-a relationship. Is this something that is generally implemented with inheritance? To steal Ernesto s example. A car has an engine. But an engine is not of the same kind as car, therefore inheritance does not apply.

15 8. 40 points A priority queue is a data structure that stores values with associated priorities. The insert operation stores a value with a priority in the structure. The findbest operation returns the value with the smallest priority, and the deletebest operation returns the value with the smallest priority and also deletes that value from the priority queue. For example, if the queue contains the following items (in (data, priority) pairs): 124, 3 123, 6 456, 7 234, 1 The subsequent deletebest operations will return 234, 124, 123, and finally 456. The specification of a priority Queue is as follows: class PriorityQueue public: PriorityQueue(); bool isfull(); // Test if the priority queue is full bool isempty(); // Test if the priority queue is empty // Add a value, priority pair to the queue void insert(int data, int priority); int deletebest(); // Return and delete the value with the // smallest priority int findbest(); // Find the value with the smallest // priority private: // Fill this in EntryList entries; ; Complete the specification of the PriorityQueue above and provide implementations for the methods. Be sure to use some ADT as the backbone of your PriorityQueue in order to expedite the implementation process. Note that the data and priority tags are integer values. You may assume the existence of an EntryList, which is a list of items of type Entry. An Entry is a struct with a priority field and a value field. struct Entry int data; int key; ; // The value // The priority If necessary, you may add other methods (but you are not required to). PriorityQueue::PriorityQueue() EntryList has it s own constuctor.

16 bool PriorityQueue::isFull() return entries.isfull(); bool PriorityQueue::isEmpty() return entries.isfull(); void PriorityQueue::insert(int data, int priority)

17 int PriorityQueue::deleteBest() int PriorityQueue::findBest()

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

Suppose that the following is from a correct C++ program: 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

More information

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR STUDENT IDENTIFICATION NO MULTIMEDIA COLLEGE JALAN GURNEY KIRI 54100 KUALA LUMPUR FIFTH SEMESTER FINAL EXAMINATION, 2014/2015 SESSION PSD2023 ALGORITHM & DATA STRUCTURE DSEW-E-F-2/13 25 MAY 2015 9.00 AM

More information

Data Structures Question Bank Multiple Choice

Data Structures Question Bank Multiple Choice Section 1. Fundamentals: Complexity, Algorthm Analysis 1. An algorithm solves A single problem or function Multiple problems or functions Has a single programming language implementation 2. A solution

More information

Chapter 20: Binary Trees

Chapter 20: Binary Trees Chapter 20: Binary Trees 20.1 Definition and Application of Binary Trees Definition and Application of Binary Trees Binary tree: a nonlinear linked list in which each node may point to 0, 1, or two other

More information

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

Name CPTR246 Spring '17 (100 total points) Exam 3 Name CPTR246 Spring '17 (100 total points) Exam 3 1. Linked Lists Consider the following linked list of integers (sorted from lowest to highest) and the changes described. Make the necessary changes in

More information

Binary Trees, Binary Search Trees

Binary Trees, Binary Search Trees Binary Trees, Binary Search Trees Trees Linear access time of linked lists is prohibitive Does there exist any simple data structure for which the running time of most operations (search, insert, delete)

More information

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

l Determine if a number is odd or even l Determine if a number/character is in a range - 1 to 10 (inclusive) - between a and z (inclusive) Final Exam Exercises Chapters 1-7 + 11 Write C++ code to: l Determine if a number is odd or even CS 2308 Fall 2016 Jill Seaman l Determine if a number/character is in a range - 1 to 10 (inclusive) - between

More information

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

! Tree: set of nodes and directed edges. ! Parent: source node of directed edge. ! Child: terminal node of directed edge Trees & Heaps Week 12 Gaddis: 20 Weiss: 21.1-3 CS 5301 Fall 2018 Jill Seaman!1 Tree: non-recursive definition! Tree: set of nodes and directed edges - root: one node is distinguished as the root - Every

More information

Cpt S 122 Data Structures. Course Review FINAL. Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University

Cpt S 122 Data Structures. Course Review FINAL. Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 Data Structures Course Review FINAL Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Final When: Wednesday (12/12) 1:00 pm -3:00 pm Where: In Class

More information

CS301 - Data Structures Glossary By

CS301 - Data Structures Glossary By CS301 - Data Structures Glossary By Abstract Data Type : A set of data values and associated operations that are precisely specified independent of any particular implementation. Also known as ADT Algorithm

More information

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

! Tree: set of nodes and directed edges. ! Parent: source node of directed edge. ! Child: terminal node of directed edge Trees (& Heaps) Week 12 Gaddis: 20 Weiss: 21.1-3 CS 5301 Spring 2015 Jill Seaman 1 Tree: non-recursive definition! Tree: set of nodes and directed edges - root: one node is distinguished as the root -

More information

CMSC 341 Lecture 10 Binary Search Trees

CMSC 341 Lecture 10 Binary Search Trees CMSC 341 Lecture 10 Binary Search Trees John Park Based on slides from previous iterations of this course Review: Tree Traversals 2 Traversal Preorder, Inorder, Postorder H X M A K B E N Y L G W UMBC CMSC

More information

Programming II (CS300)

Programming II (CS300) 1 Programming II (CS300) Chapter 10: Search and Heaps MOUNA KACEM mouna@cs.wisc.edu Spring 2018 Search and Heaps 2 Linear Search Binary Search Introduction to trees Priority Queues Heaps Linear Search

More information

DATA STRUCTURE : A MCQ QUESTION SET Code : RBMCQ0305

DATA STRUCTURE : A MCQ QUESTION SET Code : RBMCQ0305 Q.1 If h is any hashing function and is used to hash n keys in to a table of size m, where n

More information

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

Course goals. exposure to another language. knowledge of specific data structures. impact of DS design & implementation on program performance Course goals exposure to another language C++ Object-oriented principles knowledge of specific data structures lists, stacks & queues, priority queues, dynamic dictionaries, graphs impact of DS design

More information

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

MARKING KEY The University of British Columbia MARKING KEY Computer Science 260 Midterm #2 Examination 12:30 noon, Thursday, March 15, 2012 MARKING KEY The University of British Columbia MARKING KEY Computer Science 260 Midterm #2 Examination 12:30 noon, Thursday, March 15, 2012 Instructor: K. S. Booth Time: 70 minutes (one hour ten minutes)

More information

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

Tree: non-recursive definition. Trees, Binary Search Trees, and Heaps. Tree: recursive definition. Tree: example. Trees, Binary Search Trees, and Heaps CS 5301 Fall 2013 Jill Seaman Tree: non-recursive definition Tree: set of nodes and directed edges - root: one node is distinguished as the root - Every node (except

More information

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

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 FINALTERM EXAMINATION Fall 2009 CS301- Data Structures Question No: 1 The data of the problem is of 2GB and the hard disk is of 1GB capacity, to solve this problem we should Use better data structures

More information

Computer Science 302 Spring 2007 Practice Final Examination: Part I

Computer Science 302 Spring 2007 Practice Final Examination: Part I Computer Science 302 Spring 2007 Practice Final Examination: Part I Name: This practice examination is much longer than the real final examination will be. If you can work all the problems here, you will

More information

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

Part I: Short Answer (12 questions, 65 points total) CSE 143 Sp01 Final Exam Sample Solution page 1 of 14 Part I: Short Answer (12 questions, 65 points total) Answer all of the following questions. READ EACH QUESTION CAREFULLY. Answer each question in the

More information

Solution printed. Do not start the test until instructed to do so! CS 2604 Data Structures Midterm Spring Instructions:

Solution printed. Do not start the test until instructed to do so! CS 2604 Data Structures Midterm Spring Instructions: VIRG INIA POLYTECHNIC INSTITUTE AND STATE U T PROSI M UNI VERSI TY Instructions: Print your name in the space provided below. This examination is closed book and closed notes, aside from the permitted

More information

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

double d0, d1, d2, d3; double * dp = new double[4]; double da[4]; 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

More information

This examination has 11 pages. Check that you have a complete paper.

This examination has 11 pages. Check that you have a complete paper. MARKING KEY The University of British Columbia MARKING KEY Computer Science 252 2nd Midterm Exam 6:30 PM, Monday, November 8, 2004 Instructors: K. Booth & N. Hutchinson Time: 90 minutes Total marks: 90

More information

Trees. CSE 373 Data Structures

Trees. CSE 373 Data Structures Trees CSE 373 Data Structures Readings Reading Chapter 7 Trees 2 Why Do We Need Trees? Lists, Stacks, and Queues are linear relationships Information often contains hierarchical relationships File directories

More information

CS201 - Introduction to Programming Glossary By

CS201 - Introduction to Programming Glossary By CS201 - Introduction to Programming Glossary By #include : The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with

More information

Programming II (CS300)

Programming II (CS300) 1 Programming II (CS300) Chapter 12: Heaps and Priority Queues MOUNA KACEM mouna@cs.wisc.edu Fall 2018 Heaps and Priority Queues 2 Priority Queues Heaps Priority Queue 3 QueueADT Objects are added and

More information

Trees. A tree is a directed graph with the property

Trees. A tree is a directed graph with the property 2: Trees Trees A tree is a directed graph with the property There is one node (the root) from which all other nodes can be reached by exactly one path. Seen lots of examples. Parse Trees Decision Trees

More information

Programming II (CS300)

Programming II (CS300) 1 Programming II (CS300) Chapter 11: Binary Search Trees MOUNA KACEM mouna@cs.wisc.edu Fall 2018 General Overview of Data Structures 2 Introduction to trees 3 Tree: Important non-linear data structure

More information

Short Notes of CS201

Short Notes of CS201 #includes: Short Notes of CS201 The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with < and > if the file is a system

More information

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

Trees. (Trees) Data Structures and Programming Spring / 28 Trees (Trees) Data Structures and Programming Spring 2018 1 / 28 Trees A tree is a collection of nodes, which can be empty (recursive definition) If not empty, a tree consists of a distinguished node r

More information

Trees, Binary Trees, and Binary Search Trees

Trees, Binary Trees, and Binary Search Trees COMP171 Trees, Binary Trees, and Binary Search Trees 2 Trees Linear access time of linked lists is prohibitive Does there exist any simple data structure for which the running time of most operations (search,

More information

CS 216 Exam 1 Fall SOLUTION

CS 216 Exam 1 Fall SOLUTION CS 216 Exam 1 Fall 2004 - SOLUTION Name: Lab Section: Email Address: Student ID # This exam is closed note, closed book. You will have an hour and fifty minutes total to complete the exam. You may NOT

More information

INF2220: algorithms and data structures Series 1

INF2220: algorithms and data structures Series 1 Universitetet i Oslo Institutt for Informatikk A. Maus, R.K. Runde, I. Yu INF2220: algorithms and data structures Series 1 Topic Trees & estimation of running time (Exercises with hints for solution) Issued:

More information

Course Review for Finals. Cpt S 223 Fall 2008

Course Review for Finals. Cpt S 223 Fall 2008 Course Review for Finals Cpt S 223 Fall 2008 1 Course Overview Introduction to advanced data structures Algorithmic asymptotic analysis Programming data structures Program design based on performance i.e.,

More information

CMSC 341. Binary Search Trees CMSC 341 BST

CMSC 341. Binary Search Trees CMSC 341 BST CMSC 341 Binary Search Trees CMSC 341 BST Announcements Homework #3 dues Thursday (10/5/2017) Exam #1 next Thursday (10/12/2017) CMSC 341 BST A Generic Tree CMSC 341 BST Binary Tree CMSC 341 BST The Binary

More information

Example Final Questions Instructions

Example Final Questions Instructions Example Final Questions Instructions This exam paper contains a set of sample final exam questions. It is for practice purposes only. You ll most likely need longer than three hours to answer all the questions.

More information

! 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)

! 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) Final Exam Exercises CS 2308 Spring 2014 Jill Seaman Chapters 1-7 + 11 Write C++ code to: Determine if a number is odd or even Determine if a number/character is in a range - 1 to 10 (inclusive) - between

More information

Binary Search Trees Treesort

Binary Search Trees Treesort Treesort CS 311 Data Structures and Algorithms Lecture Slides Friday, November 13, 2009 Glenn G. Chappell Department of Computer Science University of Alaska Fairbanks CHAPPELLG@member.ams.org 2005 2009

More information

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

COSC 2007 Data Structures II Final Exam. Part 1: multiple choice (1 mark each, total 30 marks, circle the correct answer) COSC 2007 Data Structures II Final Exam Thursday, April 13 th, 2006 This is a closed book and closed notes exam. There are total 3 parts. Please answer the questions in the provided space and use back

More information

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

MID TERM MEGA FILE SOLVED BY VU HELPER Which one of the following statement is NOT correct. MID TERM MEGA FILE SOLVED BY VU HELPER Which one of the following statement is NOT correct. In linked list the elements are necessarily to be contiguous In linked list the elements may locate at far positions

More information

Lec 17 April 8. Topics: binary Trees expression trees. (Chapter 5 of text)

Lec 17 April 8. Topics: binary Trees expression trees. (Chapter 5 of text) Lec 17 April 8 Topics: binary Trees expression trees Binary Search Trees (Chapter 5 of text) Trees Linear access time of linked lists is prohibitive Heap can t support search in O(log N) time. (takes O(N)

More information

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

Computer Science 302 Spring 2017 (Practice for) Final Examination, May 10, 2017 Computer Science 302 Spring 2017 (Practice for) Final Examination, May 10, 2017 Name: The entire practice examination is 1005 points. 1. True or False. [5 points each] The time to heapsort an array of

More information

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

University of Illinois at Urbana-Champaign Department of Computer Science. Second Examination University of Illinois at Urbana-Champaign Department of Computer Science Second Examination CS 225 Data Structures and Software Principles Fall 2011 9a-11a, Wednesday, November 2 Name: NetID: Lab Section

More information

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

University of Illinois at Urbana-Champaign Department of Computer Science. Second Examination University of Illinois at Urbana-Champaign Department of Computer Science Second Examination CS 225 Data Structures and Software Principles Spring 2014 7-10p, Tuesday, April 8 Name: NetID: Lab Section

More information

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

University of Illinois at Urbana-Champaign Department of Computer Science. Second Examination University of Illinois at Urbana-Champaign Department of Computer Science Second Examination CS 225 Data Structures and Software Principles Spring 2012 7p-9p, Tuesday, April 3 Name: NetID: Lab Section

More information

Recitation 9. Prelim Review

Recitation 9. Prelim Review Recitation 9 Prelim Review 1 Heaps 2 Review: Binary heap min heap 1 2 99 4 3 PriorityQueue Maintains max or min of collection (no duplicates) Follows heap order invariant at every level Always balanced!

More information

INSTITUTE OF AERONAUTICAL ENGINEERING

INSTITUTE OF AERONAUTICAL ENGINEERING INSTITUTE OF AERONAUTICAL ENGINEERING (Autonomous) Dundigal, Hyderabad - 500 043 COMPUTER SCIENCE AND ENGINEERING TUTORIAL QUESTION BANK Course Name Course Code Class Branch DATA STRUCTURES ACS002 B. Tech

More information

Trees, Part 1: Unbalanced Trees

Trees, Part 1: Unbalanced Trees Trees, Part 1: Unbalanced Trees The first part of this chapter takes a look at trees in general and unbalanced binary trees. The second part looks at various schemes to balance trees and/or make them more

More information

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

Binary Tree Node Relationships. Binary Trees. Quick Application: Expression Trees. Traversals Binary Trees 1 Binary Tree Node Relationships 2 A binary tree is either empty, or it consists of a node called the root together with two binary trees called the left subtree and the right subtree of the

More information

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

Binary Trees. For example: Jargon: General Binary Trees. root node. level: internal node. edge. leaf node. Data Structures & File Management Binary Trees 1 A binary tree is either empty, or it consists of a node called the root together with two binary trees called the left subtree and the right subtree of the root, which are disjoint from

More information

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

CS61B Lecture #20: Trees. Last modified: Mon Oct 8 21:21: CS61B: Lecture #20 1 CS61B Lecture #20: Trees Last modified: Mon Oct 8 21:21:22 2018 CS61B: Lecture #20 1 A Recursive Structure Trees naturally represent recursively defined, hierarchical objects with more than one recursive

More information

Data Structure (CS301)

Data Structure (CS301) WWW.VUPages.com http://forum.vupages.com WWW.VUTUBE.EDU.PK Largest Online Community of VU Students Virtual University Government of Pakistan Midterm Examination Spring 2003 Data Structure (CS301) StudentID/LoginID

More information

COMP : Trees. COMP20012 Trees 219

COMP : Trees. COMP20012 Trees 219 COMP20012 3: Trees COMP20012 Trees 219 Trees Seen lots of examples. Parse Trees Decision Trees Search Trees Family Trees Hierarchical Structures Management Directories COMP20012 Trees 220 Trees have natural

More information

CS251-SE1. Midterm 2. Tuesday 11/1 8:00pm 9:00pm. There are 16 multiple-choice questions and 6 essay questions.

CS251-SE1. Midterm 2. Tuesday 11/1 8:00pm 9:00pm. There are 16 multiple-choice questions and 6 essay questions. CS251-SE1 Midterm 2 Tuesday 11/1 8:00pm 9:00pm There are 16 multiple-choice questions and 6 essay questions. Answer the multiple choice questions on your bubble sheet. Answer the essay questions in the

More information

CSCI2100B Data Structures Trees

CSCI2100B Data Structures Trees CSCI2100B Data Structures Trees Irwin King king@cse.cuhk.edu.hk http://www.cse.cuhk.edu.hk/~king Department of Computer Science & Engineering The Chinese University of Hong Kong Introduction General Tree

More information

Summer Final Exam Review Session August 5, 2009

Summer Final Exam Review Session August 5, 2009 15-111 Summer 2 2009 Final Exam Review Session August 5, 2009 Exam Notes The exam is from 10:30 to 1:30 PM in Wean Hall 5419A. The exam will be primarily conceptual. The major emphasis is on understanding

More information

Review for Test 1 (Chapter 1-5)

Review for Test 1 (Chapter 1-5) Review for Test 1 (Chapter 1-5) 1. Software development 1. Pre-conditions and Post-conditions 2. Running time analysis Big O Timing loops and nested loops 1) Write the simplest big-o expression to describe

More information

! 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)

! 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) Final Exam Exercises Chapters 1-7 + 11 Write C++ code to:! Determine if a number is odd or even CS 2308 Fall 2018 Jill Seaman! Determine if a number/character is in a range - 1 to 10 (inclusive) - between

More information

Largest Online Community of VU Students

Largest Online Community of VU Students WWW.VUPages.com http://forum.vupages.com WWW.VUTUBE.EDU.PK Largest Online Community of VU Students MIDTERM EXAMINATION SEMESTER FALL 2003 CS301-DATA STRUCTURE Total Marks:86 Duration: 60min Instructions

More information

Basic Data Structures (Version 7) Name:

Basic Data Structures (Version 7) Name: Prerequisite Concepts for Analysis of Algorithms Basic Data Structures (Version 7) Name: Email: Concept: mathematics notation 1. log 2 n is: Code: 21481 (A) o(log 10 n) (B) ω(log 10 n) (C) Θ(log 10 n)

More information

CSE 143. Complexity Analysis. Program Efficiency. Constant Time Statements. Big Oh notation. Analyzing Loops. Constant Time Statements (2) CSE 143 1

CSE 143. Complexity Analysis. Program Efficiency. Constant Time Statements. Big Oh notation. Analyzing Loops. Constant Time Statements (2) CSE 143 1 CSE 1 Complexity Analysis Program Efficiency [Sections 12.1-12., 12., 12.9] Count number of instructions executed by program on inputs of a given size Express run time as a function of the input size Assume

More information

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

CSE 332 Winter 2015: Midterm Exam (closed book, closed notes, no calculators) _ UWNetID: Lecture Section: A CSE 332 Winter 2015: Midterm Exam (closed book, closed notes, no calculators) Instructions: Read the directions for each question carefully before answering. We will give

More information

Why Do We Need Trees?

Why Do We Need Trees? CSE 373 Lecture 6: Trees Today s agenda: Trees: Definition and terminology Traversing trees Binary search trees Inserting into and deleting from trees Covered in Chapter 4 of the text Why Do We Need Trees?

More information

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

NET/JRF-COMPUTER SCIENCE & APPLICATIONS. Time: 01 : 00 Hour Date : M.M. : 50 1 NET/JRF-COMPUTER SCIENCE & APPLICATIONS UNIT TEST : DATA STRUCTURE Time: 01 : 00 Hour Date : 02-06-2017 M.M. : 50 INSTRUCTION: Attempt all the 25 questions. Each question carry TWO marks. 1. Consider

More information

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

Revision Statement while return growth rate asymptotic notation complexity Compare algorithms Linear search Binary search Preconditions: sorted, [1] Big-O Analysis AVERAGE(n) 1. sum 0 2. i 0. while i < n 4. number input_number(). sum sum + number 6. i i + 1 7. mean sum / n 8. return mean Revision Statement no. of times executed 1 1 2 1 n+1 4 n

More information

3137 Data Structures and Algorithms in C++

3137 Data Structures and Algorithms in C++ 3137 Data Structures and Algorithms in C++ Lecture 3 July 12 2006 Shlomo Hershkop 1 Announcements Homework 2 out tonight Please make sure you complete hw1 asap if you have issues, please contact me will

More information

ECE250: Algorithms and Data Structures Midterm Review

ECE250: Algorithms and Data Structures Midterm Review ECE250: Algorithms and Data Structures Midterm Review Ladan Tahvildari, PEng, SMIEEE Associate Professor Software Technologies Applied Research (STAR) Group Dept. of Elect. & Comp. Eng. University of Waterloo

More information

MARKING KEY The University of British Columbia MARKING KEY Computer Science 260 Final Examination 8:30 AM, Wednesday, April 18, 2012

MARKING KEY The University of British Columbia MARKING KEY Computer Science 260 Final Examination 8:30 AM, Wednesday, April 18, 2012 MARKING KEY The University of British Columbia MARKING KEY Computer Science 260 Final Examination 8:30 AM, Wednesday, April 18, 2012 Instructor: K. S. Booth Time: 150 minutes (two hours thirty minutes)

More information

MIDTERM EXAMINATION Spring 2010 CS301- Data Structures

MIDTERM EXAMINATION Spring 2010 CS301- Data Structures MIDTERM EXAMINATION Spring 2010 CS301- Data Structures Question No: 1 Which one of the following statement is NOT correct. In linked list the elements are necessarily to be contiguous In linked list the

More information

CS302 - Data Structures using C++

CS302 - Data Structures using C++ CS302 - Data Structures using C++ Topic: Trees Kostas Alexis Trees List, stacks, and queues are linear in their organization of data. Items are one after another In this section, we organize data in a

More information

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

Course Review for. Cpt S 223 Fall Cpt S 223. School of EECS, WSU Course Review for Midterm Exam 1 Cpt S 223 Fall 2011 1 Midterm Exam 1 When: Friday (10/14) 1:10-2pm Where: in class Closed book, closed notes Comprehensive Material for preparation: Lecture slides & in-class

More information

Priority Queues and Heaps. Heaps and Priority Queues 1

Priority Queues and Heaps. Heaps and Priority Queues 1 Priority Queues and Heaps 2 5 6 9 7 Heaps and Priority Queues 1 Priority Queue ADT A priority queue stores a collection of items An item is a pair (key, element) Main methods of the Priority Queue ADT

More information

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 250 Final Exam. Fall 2013 Time: 3 hours. Dec 11, No electronic devices of any kind. You can open your textbook and notes CSE 250 Final Exam Fall 2013 Time: 3 hours. Dec 11, 2013 Total points: 100 14 pages Please use the space provided for each question, and the back of the page if you need to. Please do not use any extra

More information

Section 05: Solutions

Section 05: Solutions Section 05: Solutions 1. Memory and B-Tree (a) Based on your understanding of how computers access and store memory, why might it be faster to access all the elements of an array-based queue than to access

More information

CH 8. HEAPS AND PRIORITY QUEUES

CH 8. HEAPS AND PRIORITY QUEUES CH 8. HEAPS AND PRIORITY QUEUES ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH, TAMASSIA AND MOUNT (WILEY 2004) AND SLIDES FROM NANCY

More information

An Introduction to C++

An Introduction to C++ An Introduction to C++ Introduction to C++ C++ classes C++ class details To create a complex type in C In the.h file Define structs to store data Declare function prototypes The.h file serves as the interface

More information

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

Cpt S 122 Data Structures. Course Review Midterm Exam # 1 Cpt S 122 Data Structures Course Review Midterm Exam # 1 Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Midterm Exam 1 When: Friday (09/28) 12:10-1pm Where:

More information

DATA STRUCTURES AND ALGORITHMS

DATA STRUCTURES AND ALGORITHMS DATA STRUCTURES AND ALGORITHMS For COMPUTER SCIENCE DATA STRUCTURES &. ALGORITHMS SYLLABUS Programming and Data Structures: Programming in C. Recursion. Arrays, stacks, queues, linked lists, trees, binary

More information

Course Review. Cpt S 223 Fall 2009

Course Review. Cpt S 223 Fall 2009 Course Review Cpt S 223 Fall 2009 1 Final Exam When: Tuesday (12/15) 8-10am Where: in class Closed book, closed notes Comprehensive Material for preparation: Lecture slides & class notes Homeworks & program

More information

CH. 8 PRIORITY QUEUES AND HEAPS

CH. 8 PRIORITY QUEUES AND HEAPS CH. 8 PRIORITY QUEUES AND HEAPS ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH, TAMASSIA AND MOUNT (WILEY 2004) AND SLIDES FROM NANCY

More information

CSCE 2014 Final Exam Spring Version A

CSCE 2014 Final Exam Spring Version A CSCE 2014 Final Exam Spring 2017 Version A Student Name: Student UAID: Instructions: This is a two-hour exam. Students are allowed one 8.5 by 11 page of study notes. Calculators, cell phones and computers

More information

CSE373 Fall 2013, Midterm Examination October 18, 2013

CSE373 Fall 2013, Midterm Examination October 18, 2013 CSE373 Fall 2013, Midterm Examination October 18, 2013 Please do not turn the page until the bell rings. Rules: The exam is closed-book, closed-note, closed calculator, closed electronics. Please stop

More information

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

PROGRAMMING IN C++ (Regulation 2008) Answer ALL questions PART A (10 2 = 20 Marks) PART B (5 16 = 80 Marks) function? (8) B.E./B.Tech. DEGREE EXAMINATION, NOVEMBER/DECEMBER 2009 EC 2202 DATA STRUCTURES AND OBJECT ORIENTED Time: Three hours PROGRAMMING IN C++ Answer ALL questions Maximum: 100 Marks 1. When do we declare a

More information

Binary Trees

Binary Trees Binary Trees 4-7-2005 Opening Discussion What did we talk about last class? Do you have any code to show? Do you have any questions about the assignment? What is a Tree? You are all familiar with what

More information

Object Oriented Programming COP3330 / CGS5409

Object Oriented Programming COP3330 / CGS5409 Object Oriented Programming COP3330 / CGS5409 Intro to Data Structures Vectors Linked Lists Queues Stacks C++ has some built-in methods of storing compound data in useful ways, like arrays and structs.

More information

Chapter 5. Binary Trees

Chapter 5. Binary Trees Chapter 5 Binary Trees Definitions and Properties A binary tree is made up of a finite set of elements called nodes It consists of a root and two subtrees There is an edge from the root to its children

More information

CSI33 Data Structures

CSI33 Data Structures Outline Department of Mathematics and Computer Science Bronx Community College November 13, 2017 Outline Outline 1 C++ Supplement.1: Trees Outline C++ Supplement.1: Trees 1 C++ Supplement.1: Trees Uses

More information

CSE 373 Spring Midterm. Friday April 21st

CSE 373 Spring Midterm. Friday April 21st CSE 373 Spring 2006 Data Structures and Algorithms Midterm Friday April 21st NAME : Do all your work on these pages. Do not add any pages. Use back pages if necessary. Show your work to get partial credit.

More information

Queues. ADT description Implementations. October 03, 2017 Cinda Heeren / Geoffrey Tien 1

Queues. ADT description Implementations. October 03, 2017 Cinda Heeren / Geoffrey Tien 1 Queues ADT description Implementations Cinda Heeren / Geoffrey Tien 1 Queues Assume that we want to store data for a print queue for a student printer Student ID Time File name The printer is to be assigned

More information

CPSC 221: Algorithms and Data Structures Lecture #1: Stacks and Queues

CPSC 221: Algorithms and Data Structures Lecture #1: Stacks and Queues CPSC 221: Algorithms and Data Structures Lecture #1: Stacks and Queues Alan J. Hu (Slides borrowed from Steve Wolfman) Be sure to check course webpage! http://www.ugrad.cs.ubc.ca/~cs221 1 Lab 1 is available.

More information

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

Section 1: True / False (2 points each, 30 pts total) Section 1: True / False (2 points each, 30 pts total) Circle the word TRUE or the word FALSE. If neither is circled, both are circled, or it impossible to tell which is circled, your answer will be considered

More information

First Examination. CS 225 Data Structures and Software Principles Spring p-9p, Tuesday, February 19

First Examination. CS 225 Data Structures and Software Principles Spring p-9p, Tuesday, February 19 Department of Computer Science First Examination CS 225 Data Structures and Software Principles Spring 2008 7p-9p, Tuesday, February 19 Name: NetID: Lab Section (Day/Time): This is a closed book and closed

More information

Example Final Questions Instructions

Example Final Questions Instructions Example Final Questions Instructions This exam paper contains a set of sample final exam questions. It is for practice purposes only. You ll most likely need longer than three hours to answer all the questions.

More information

University of Waterloo Department of Electrical and Computer Engineering ECE250 Algorithms and Data Structures Fall 2014

University of Waterloo Department of Electrical and Computer Engineering ECE250 Algorithms and Data Structures Fall 2014 University of Waterloo Department of Electrical and Computer Engineering ECE250 Algorithms and Data Structures Fall 2014 Midterm Examination Instructor: Ladan Tahvildari, PhD, PEng, SMIEEE Date: Tuesday,

More information

COMP 250 Midterm #2 March 11 th 2013

COMP 250 Midterm #2 March 11 th 2013 NAME: STUDENT ID: COMP 250 Midterm #2 March 11 th 2013 - This exam has 6 pages - This is an open book and open notes exam. No electronic equipment is allowed. 1) Questions with short answers (28 points;

More information

Multiple Choice: 2 pts each CS-3020 Exam #3 (CH16-CH21) FORM: EX03:P

Multiple Choice: 2 pts each CS-3020 Exam #3 (CH16-CH21) FORM: EX03:P Multiple Choice: 2 pts each CS-3020 Exam #3 (CH16-CH21) FORM: EX03:P Choose the BEST answer of those given and enter your choice on the Answer Sheet. You may choose multiple options, but the point value

More information

CMPSCI 187: Programming With Data Structures. Lecture #26: Binary Search Trees David Mix Barrington 9 November 2012

CMPSCI 187: Programming With Data Structures. Lecture #26: Binary Search Trees David Mix Barrington 9 November 2012 CMPSCI 187: Programming With Data Structures Lecture #26: Binary Search Trees David Mix Barrington 9 November 2012 Binary Search Trees Why Binary Search Trees? Trees, Binary Trees and Vocabulary The BST

More information

Priority Queues (Heaps)

Priority Queues (Heaps) Priority Queues (Heaps) 1 Priority Queues Many applications require that we process records with keys in order, but not necessarily in full sorted order. Often we collect a set of items and process the

More information

Data Structure Advanced

Data Structure Advanced 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)

More information

CS 61B Spring 2017 Guerrilla Section 4 Worksheet. 11 March 2017

CS 61B Spring 2017 Guerrilla Section 4 Worksheet. 11 March 2017 Spring 2017 11 March 2017 Directions: In groups of 4-5, work on the following exercises. Do not proceed to the next exercise until everyone in your group has the answer and understands why the answer is

More information