UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger

Similar documents
DO NOT. UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N.

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger.

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger

CS61B, Fall 2015 Final Examination (with corrections) P. N. Hilfinger

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger.

CS61B, Fall 2011 Final Examination (corrected) P. N. Hilfinger

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger.

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger.

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger.

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger.

CS61B, Fall 2007 Final Examination P. N. Hilfinger

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger. Test #1 (corrected)

CS61B, Spring 2006 Final Examination P. N. Hilfinger

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger and Josh Hug

CS61B, Fall 2009 Final Examination (revised) P. N. Hilfinger

DO NOT. UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N.

COS 226 Midterm Exam, Spring 2009

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

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

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

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

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

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. Fall 2016.

CS61BL. Lecture 5: Graphs Sorting

CSE548, AMS542: Analysis of Algorithms, Fall 2012 Date: October 16. In-Class Midterm. ( 11:35 AM 12:50 PM : 75 Minutes )

University of Toronto Department of Electrical and Computer Engineering. Midterm Examination. ECE 345 Algorithms and Data Structures Fall 2012

Cornell University Computer Science 211 Second Preliminary Examination 18 April 2006

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

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

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

ECE368 Exam 2 Spring 2016

DATA STRUCTURES AND ALGORITHMS

Introduction to Algorithms October 12, 2005 Massachusetts Institute of Technology Professors Erik D. Demaine and Charles E. Leiserson Quiz 1.

UNIVERSITY OF CALIFORNIA

Data Structures in Java

Data Structures and Algorithms

1 / 20 2 / 20 3 / 20 4 / 20 5 / 20

Unit 6 Chapter 15 EXAMPLES OF COMPLEXITY CALCULATION

Sorting and Selection

Sorting is ordering a list of objects. Here are some sorting algorithms

Lecture 5: Sorting Part A

8. Binary Search Tree

DO NOT REPRODUCE. CS61B, Fall 2008 Test #3 (revised) P. N. Hilfinger

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

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

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

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

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

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

Comparisons. Θ(n 2 ) Θ(n) Sorting Revisited. So far we talked about two algorithms to sort an array of numbers. What is the advantage of merge sort?

CPSC 311: Analysis of Algorithms (Honors) Exam 1 October 11, 2002

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

Princeton University Computer Science COS226: Data Structures and Algorithms. Midterm, Fall 2013

- 1 - Handout #22S May 24, 2013 Practice Second Midterm Exam Solutions. CS106B Spring 2013

CSL 201 Data Structures Mid-Semester Exam minutes

ECE 2035 A Programming HW/SW Systems Spring problems, 5 pages Exam Three 13 April Your Name (please print clearly)

Comparisons. Heaps. Heaps. Heaps. Sorting Revisited. Heaps. So far we talked about two algorithms to sort an array of numbers

Sorting. Popular algorithms: Many algorithms for sorting in parallel also exist.

COMP Data Structures

CS 61B Summer 2005 (Porter) Midterm 2 July 21, SOLUTIONS. Do not open until told to begin

Searching in General

CS-141 Exam 2 Review April 4, 2015 Presented by the RIT Computer Science Community

COS 226 Algorithms and Data Structures Spring Midterm

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

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

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

Jana Kosecka. Linear Time Sorting, Median, Order Statistics. Many slides here are based on E. Demaine, D. Luebke slides

Computer Science E-22 Practice Final Exam

Chapter 10. Sorting and Searching Algorithms. Fall 2017 CISC2200 Yanjun Li 1. Sorting. Given a set (container) of n elements

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

INF2220: algorithms and data structures Series 1

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

Properties of a heap (represented by an array A)

Multiple-choice (35 pt.)

lecture notes September 2, How to sort?

CSE373 Fall 2013, Midterm Examination October 18, 2013

Algorithms and Data Structures (INF1) Lecture 7/15 Hua Lu

Data Structure Lecture#16: Internal Sorting (Chapter 7) U Kang Seoul National University

SAMPLE OF THE STUDY MATERIAL PART OF CHAPTER 6. Sorting Algorithms

COS 226 Algorithms and Data Structures Fall Midterm

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

CS126 Final Exam Review

4.4 Algorithm Design Technique: Randomization

Practice final for EECS 380, 2001: Prof Markov

DUKE UNIVERSITY Department of Computer Science. Test 2: CompSci 100

Real-world sorting (not on exam)

CS 315 Data Structures Spring 2012 Final examination Total Points: 80

COS 126 Written Exam 2, Fall 2009

Week 10. Sorting. 1 Binary heaps. 2 Heapification. 3 Building a heap 4 HEAP-SORT. 5 Priority queues 6 QUICK-SORT. 7 Analysing QUICK-SORT.

Summer Final Exam Review Session August 5, 2009

Topics for CSCI 151 Final Exam Wednesday, May 10

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

Exam Datastrukturer. DIT960 / DIT961, VT-18 Göteborgs Universitet, CSE

Hiroki Yasuga, Elisabeth Kolp, Andreas Lang. 25th September 2014, Scientific Programming

Comp Intermediate Programming EXAM #2 March 30, 2005 Rice University - Instructors: Cox & Nguyen

Parallel Sorting Algorithms

CSCI 102L - Data Structures Midterm Exam #2 Spring 2011

COS 226 Algorithms and Data Structures Fall Midterm

CHAPTER 7 Iris Hui-Ru Jiang Fall 2008

Module 2: Classical Algorithm Design Techniques

Transcription:

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division CS61B Fall 2011 P. N. Hilfinger Test #2 (with corrections) READ THIS PAGE FIRST. Please do not discuss this exam with people who haven t taken it. Your exam should contain 8 problems on 7 pages. Officially, it is worth 20 points (out of a total of 200). This is an open-book test. You have fifty minutes to complete it. You may consult any books, notes, or other inanimate objects available to you. You may use any program text supplied in lectures, problem sets, or solutions. Please write your answers in the spaces provided in the test. Make sure to put your name, login, and lab section in the space provided below. Put your login and initials clearly on each page of this test and on any additional sheets of paper you use for your answers. Be warned: my tests are known to cause panic. Fortunately, this reputation is entirely unjustified. Just read all the questions carefully to begin with, and first try to answer those parts about which you feel most confident. Do not be alarmed if some of the answers are obvious. Should you feel an attack of anxiety coming on, feel free to jump up and run around the outside of the building once or twice. Your name: Login: Login of person to your Left: Right: Discussion TA: 1. /3 6. /2 2. /3 7. /4 3. /2 8. /2 4. /3 9. /1 5. / TOT /20 1

Test #2 Login: Initials: 2 1. [3 points] Consider insertion sort, merge sort, and quicksort. For each algorithm, what is the worst-case asymptotic bound on the running time for a list of N elements if you know additionally that: the input is already sorted? the input is reversely sorted? the input is a list containing N copies of the same number? Condition Insertion Sort Merge Sort Quicksort Sorted Reverse sorted N copies

Test #2 Login: Initials: 3 2. [3 points] We want a data structure,t, on which we can perform the following operations with the given complexity (N being the number of elements already inserted in the data structure): insert(x, T) insert a new element in O(lg N) time. contains(x, T) check if the structure contains element x in O(lg N) time. delete(k, T) delete the k th smallest element in O(lg N) time, where we take k to be a constant. Out of all the data structures given below, which one(s) would you pick? For any you reject, explain briefly. Simply circle those that you accept; no explanation is necessary. a heap a red-black tree a binary search tree an unsorted linked list a sorted linked list an unsorted array a sorted array a hash table (nothing said about the hash function)

Test #2 Login: Initials: 4 3. [2 points] In doing Project #2, Bill Bucket has written the following function: /** Returns a copy of A that is unaffected by subsequent operations on * A. */ public static int[][] copy(int[][] A) { int[][] result = new int[a.length][]; for (int i = 0; i < A.length; i += 1) { result[i] = A[i]; return result; Devise a unit test that shows that this method does not work (does not fulfill its documentation). @Test public void checkcopy() { 4. [3 points] Starting from the max-heap on the left, we remove the largest element and insert 20. The resulting heap is shown on the right. Assume that all values are unique and that 20 is not in the original heap. 20 10 10 Fill in the blank nodes in both heaps to show one possible way that this result could come about.

Test #2 Login: Initials: 5 5. [1 point] What non-mathematical property do the numbers 31, 45, 66, 99, and 500 have in common? 6. [2 points] Show the steps taken by quicksort on the following unordered list, assuming that the pivot node is always the first item in the (sub)list being sorted, and the array is sorted in place. 36 22 15 56 48 90 72 06 To show a step, show the contents of the array at the beginning of each call (initial or recursive) on the quicksort procedure. Assume that we sort all the way down to the trivial case of subarrays of size 1.

Test #2 Login: Initials: 6 7. [4 points] A certain binary search tree representation uses the following representation /** A binary tree node. The empty tree is represented by null. */ class BinNode { /** Returns my left child. */ BinNode left() {... /** Returns my right child. */ BinNode right() {... /** Returns my parent, or null if I am the root of the entire * tree. */ BinNode parent() {... /** Returns my key value (label). */ ValueType label() {...... Fill in the following functions to conform to their comments. /** True iff B is the left child of another node. */ static boolean amleftchild(binnode b) { return ; /** Returns the node in B s tree that contains the value next larger * than B s. Assumes that the tree I am part of is a binary search * tree and that all its values are unique. Returns null if G is * the node containing the largest value. Does not call label(). */ static BinNode next(binnode b) {

Test #2 Login: Initials: 7 8. [2 points] Consider a hash table that uses a very good hashing function one that (miraculously) always distributes keys evenly across the bins in the table. Assuming the hash table expands at need to maintain a load factor of 3, What can you say about the worst-case time for adding an item to the table when it contains N items to begin with? What can you say about the worst-case time for adding N items to the table when it contains N items to begin with? 9. [1 point] I create a list of integers by calling semirandomlist(b, 10), using the following method: static void semirandomlist(int[] A, int jiggle) { Random R = new Random(); for (int i = 0; i < A.length; i += 1) { A[i] = i + R.nextInt(jiggle); (The nextint(jiggle) call produces a random integer 0 and <jiggle.) Having done this, I sort B using insertion sort. What can you say about the time required to do so? Be as precise as possible.