Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Data Structures and Object Oriented Development - Exam 2 to Solutions | CS 2606, Exams of Data Structures and Algorithms

Material Type: Exam; Professor: McQuain; Class: Data Structs & OO Development; Subject: Computer Science; University: Virginia Polytechnic Institute And State University; Term: Fall 2007;

Typology: Exams

Pre 2010

Uploaded on 09/24/2008

ramblurr
ramblurr 🇺🇸

19 documents

1 / 6

Toggle sidebar

Related documents


Partial preview of the text

Download Data Structures and Object Oriented Development - Exam 2 to Solutions | CS 2606 and more Exams Data Structures and Algorithms in PDF only on Docsity! CS 2606 Data Structures and OO Devel II Test 2 1 READ THIS NOW! • Print your name in the space provided below. • Unless a question involves determining whether given C++ code is syntactically correct, assume that it is. Unless a question specifically deals with compiler #include directives, you should assume the necessary header files have been included. • There are 6 short-answer questions, priced as marked. The maximum score is 100. • When you have finished, sign the pledge at the bottom of this page and turn in the test and your fact sheet. • Aside from the allowed one-page fact sheet, this is a closed-book, closed-notes examination. • No laptops, calculators, cell phones or other electronic devices may be used during this examination. • You may not discuss this examination with any student who has not taken it. • Failure to adhere to any of these restrictions is an Honor Code violation. Name (Last, First) printed Pledge: On my honor, I have neither given nor received unauthorized aid on this examination. signed CS 2606 Data Structures and OO Devel II Test 2 2 For questions 1 and 2, consider the following graph G1: 1. [12 points] Draw the spanning tree for G1 obtained by applying a depth-first traversal starting at node A. Visit neighbors in alphabetical order, and number the edges in the order they are added to the tree. 2. [12 points] Draw the spanning tree for G1 obtained by applying a breadth-first traversal starting at node A. Visit neighbors in alphabetical order, and number the edges in the order they are added to the tree. A B C D E F A B C D E F 1 2 3 5 4 A B C D E F 1 2 3 4 5 CS 2606 Data Structures and OO Devel II Test 2 5 6. [12 points] Suppose that you need to sort a list of N non-negative integer values. One objection to using binsort would be that it would require too many bins if the range of the data values was large. Describe a scenario in which, even if the number of bins is feasible, binsort would not really be Θ(N). Note: the question is about binsort, not radix sort. Let B be the number of bins; in any case B must be at least as large as N and typically B is much larger than N. The pass of binsort through the data elements will leave then in sorted order, but scattered throughout the B bins. It is still necessary to collect the elements into a single list, and that will require a linear pass through the bins, which would be Θ(B). That makes the total cost of binsort Θ(N + B). But this will only be Θ(N) if B is bounded by kN for some constant k. This, unfortunately, isn't guaranteed, even if the number of bins is feasible. For a specific example, suppose that we are sorting a collection of N = 1000 integers in the range 0 to 1,000,000. We would need 10^6 bins, which might well be feasible, but the cost of the collecting pass would be on the order of N^2. The size of the integers is of absolutely no concern here; binsort makes only one pass to sort the values and a second pass to collect them; and, if the integers are large but confined to a small range (e.g., 1000 integers between 900,000 and 1,000,000) then any intelligent use of binsort will take that into account and use a suitable number of bins (e.g., 100,000 instead of 1,000,000). The occurrence of duplicate values is also irrelevant. Duplicates would simply go to the same slot; that's easily accommodated by making the slot a simple linked stack structure so insertion is still Θ(1). And, as far as binsort is concerned, it doesn't matter what order the duplicate elements occur in the slot. In the specific scenario described above, since the values being sorted are simple integers, all that's needed in each slot is actually just a counter. CS 2606 Data Structures and OO Devel II Test 2 6
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved