COMP 250 Midterm #2 March 11 th 2013

Similar documents
Faculty of Science FINAL EXAMINATION COMP-250 A Introduction to Computer Science School of Computer Science, McGill University

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

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

CSE 373 Winter 2009: Midterm #1 (closed book, closed notes, NO calculators allowed)

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

COS 226 Algorithms and Data Structures Fall Midterm

EXAMINATIONS 2015 COMP103 INTRODUCTION TO DATA STRUCTURES AND ALGORITHMS

COMP 103. Data Structures and Algorithms

Computer Science 136 Exam 2

Programming Abstractions

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

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

CS171 Final Practice Exam

9/26/2018 Data Structure & Algorithm. Assignment04: 3 parts Quiz: recursion, insertionsort, trees Basic concept: Linked-List Priority queues Heaps

Department of Computer Science and Engineering. CSE 2011: Fundamentals of Data Structures Winter 2009, Section Z

CS171 Final Practice Exam

CPSC 211, Sections : Data Structures and Implementations, Honors Final Exam May 4, 2001

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

Assume you are given a Simple Linked List (i.e. not a doubly linked list) containing an even number of elements. For example L = [A B C D E F].

ECE250: Algorithms and Data Structures Midterm Review

UNIVERSITY OF WATERLOO DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING E&CE 250 ALGORITHMS AND DATA STRUCTURES

CS 315 Data Structures mid-term 2

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

Exam Data structures DAT036/DAT037/DIT960

CPSC 331 Term Test #2 March 26, 2007

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

c) A perfect ternary tree of height h? (In a ternary tree, each node may have up to three children.)

EXAMINATIONS 2016 TRIMESTER 2

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

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

Midterm solutions. n f 3 (n) = 3

AP Computer Science 4325

Exam Data structures DIT960/DAT036

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

: Fundamental Data Structures and Algorithms. June 06, 2011 SOLUTIONS

SOLUTIONS. COMP103 Introduction to Data Structures and Algorithms

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

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

FINAL EXAMINATION. COMP-250: Introduction to Computer Science - Fall 2011

CSE wi: Practice Midterm

ITI Introduction to Computing II

CSE 373 Sample Midterm #2 (closed book, closed notes, calculators o.k.)

UNIVERSITY OF WATERLOO DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING E&CE 250 ALGORITHMS AND DATA STRUCTURES

Chapter 5 Data Structures Algorithm Theory WS 2016/17 Fabian Kuhn

CSE Data Structures and Introduction to Algorithms... In Java! Instructor: Fei Wang. Mid-Term Exam. CSE2100 DS & Algorithms 1

CS171 Midterm Exam. October 29, Name:

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

Computer Science II Fall 2009

Programming II (CS300)

CS 216 Exam 1 Fall SOLUTION

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

Summer Final Exam Review Session August 5, 2009

CSE 332, Spring 2010, Midterm Examination 30 April 2010

COMP251: Algorithms and Data Structures. Jérôme Waldispühl School of Computer Science McGill University

CSE 214 Computer Science II Heaps and Priority Queues

FINAL EXAMINATION. COMP-250: Introduction to Computer Science - Fall 2011

CSCE 2014 Final Exam Spring Version A

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

University of Toronto Mississauga. Flip to the back cover and write down your name and student number.

Computer Science E-22 Practice Final Exam

Q1 Q2 Q3 Q4 Q5 Q6 Total

OF VICTORIA EXAMINATIONS- DECEMBER 2010 CSC

FINAL EXAMINATION. COMP-250: Introduction to Computer Science - Fall 2010

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

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

INFO1x05 Tutorial 6. Exercise 1: Heaps and Priority Queues

182 review 1. Course Goals

1.00/1.001 Introduction to Computers and Engineering Problem Solving. Final Exam

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

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

CS 231 Data Structures and Algorithms Fall Binary Search Trees Lecture 23 October 29, Prof. Zadia Codabux

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

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

(D) There is a constant value n 0 1 such that B is faster than A for every input of size. n n 0.

Basic Data Structures (Version 7) Name:

CSE 373 OCTOBER 11 TH TRAVERSALS AND AVL

CSE373 Winter 2014, Midterm Examination January 29, 2014

Algorithms and Data Structures

CH ALGORITHM ANALYSIS CH6. STACKS, QUEUES, AND DEQUES

CSL 201 Data Structures Mid-Semester Exam minutes

Trees & Tree-Based Data Structures. Part 4: Heaps. Definition. Example. Properties. Example Min-Heap. Definition

Before class. BSTs, Heaps, and PQs 2/26/13 1. Open TreeNodeExample.java Change main to:

CSE 131 Computer Science 1 Module 9a: ADT Representations. Stack and queue ADTs array implementations Buffer ADT and circular lists

Prelim 2. CS 2110, 16 November 2017, 7:30 PM Total Question Name Short Heaps Tree Collections Sorting Graph

COMP 250 Winter generic types, doubly linked lists Jan. 28, 2016

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

CE 221 Data Structures and Algorithms

MLR Institute of Technology

Largest Online Community of VU Students

Te Whare Wananga o te Upoko o te Ika a Maui EXAMINATIONS 2003 END-YEAR COMP 103. Data Structures and Algorithms

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

How much space does this routine use in the worst case for a given n? public static void use_space(int n) { int b; int [] A;

Dictionaries. Priority Queues

Computer Science 136. Midterm Examination

EXAMINATIONS 2010 END YEAR. COMP103 Introduction to Data Structures and Algorithms SOLUTIONS

Introduction to Algorithms May 14, 2003 Massachusetts Institute of Technology Professors Erik Demaine and Shafi Goldwasser.

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

CS 314 Final Fall 2012

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

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

Transcription:

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; 4 points each) a) True or False? Justify your answer briefly! When designing a hash function for a hash table implementing a dictionary, one has to make sure that two different keys are never mapped to the same bucket. b) Consider a sorted linked list containing n nodes, each storing an integer. On such a list, why is it not possible to do a binary search that runs in worst-case time O(log n)? c) A ternary tree is a tree where each node has up to three children. What is the maximum number of nodes in a ternary tree of height h? Justify your answer. d) Name the type of tree traversal algorithm that will print keys in increasing order when executed on a Binary Search Tree? No justifications are needed.

e) When using a linked list (not doubly-linked) to implement a queue ADT, is it better to implement the enqueue operation with the addlast() method and the dequeue operation with the removefirst() method, or to implement enqueue with addfirst() and dequeue with removelast()? Why? f) (2 points each) What Abstract Data Type would be the most appropriate to represent each of the following situations? No justifications are needed. 1) When a student is busy taking several courses, he works on his assignments in the order he receives them, completing first the assignment that was assigned first. 2) When another (wiser) student is busy taking several courses, she works on her assignments in the order of their due dates, completing first on the assignment that is due first. 3) When you go to the doctor, he/she can access your medical record by simply typing in your Health Insurance number. 4) Mathieu receives a lot of e-mails. He always replies to the most recently received un-answered e-mail, deletes it, and then repeats the process.

Question 2. (18 Points) Consider the Java implementation of a linked list given below. Implement in Java the method insertafter, which takes as argument two integers called marker and newelement, and inserts immediately after the node with value marker a new node with value newelement. See below for an example. If no node with value marker exists in the list, then no new node is inserted. Example: Calling insertafter(12,7) on the linked list: 5 à 2 à 6 à 12 à 9 Results in : 5 à 2 à 6 à 12 à 7 à 9 class node { public int value; public node next; }; class linkedlist { public node head; public node tail; public void insertafter(int marker, int newelement) { }; }

3) Tree traversal algorithms (20 points) a) (10 points) What would the following algorithm print when executed on the root of the tree shown on the right? No justification is needed. Algorithm WeirdTraversal(treeNode n) if (n!= null) then { WeirdTraversal( n.getleftchild() ) Print n.getkey() WeirdTraversal( n.getrightchild() ) if (n.getkey() is even) WeirdTraversal( n.getleftchild() ) else WeirdTraversal( n.getrightchild() ) } b) (10 points) Let P(n) be the total number of times the Print statement is going to be executed when the WeirdTraversal algorithm is called on the root of a full heap of n nodes (a full heap is one where the last level is full, as shown above). Write a recurrence for P(n). You do not need to solve the recurrence.

Question 4. Binary Search Trees and Heaps (16 points) a) (8 points) Consider the following Binary Search Tree. Draw the Binary Search Tree after the remove(20) operation has been performed, as seen in class. b) (8 points) Consider the following heap. Draw the Heap after the insert(4) operation has been performed, as seen in class.

Question 5 (18 points) Consider a Binary Search Tree that contains a set of distinct integer keys. Problem: Write an algorithm that determines the number of keys between Min and Max (inclusively) contained in the tree, where Min and Max are two given integers. For example, when executed on the root of the tree shown in Question 4 (a), nbkeysinrange(root, Min=12, Max=24) should return 5, because there are 5 keys with values between 12 and 24. Your algorithm must avoid visiting parts of the trees that are not necessary. Algorithm nbkeysinrange(treenode n, int Min, int Max) Input: A treenode n and two integers Min and Max Output: Number of nodes with keys in the range [Min Max] in the subtree rooted at n. /* WRITE YOUR PSEUDOCODE HERE */