THE UNIVERSITY OF WESTERN AUSTRALIA

Similar documents
THE UNIVERSITY OF WESTERN AUSTRALIA

Queues. CITS2200 Data Structures and Algorithms. Topic 5

Lists. CITS2200 Data Structures and Algorithms. Topic 9

Week 4 Stacks & Queues

csci 210: Data Structures Stacks and Queues

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

1 P age DS & OOPS / UNIT II

CS171 Midterm Exam. October 29, Name:

Introduction to Data Structures. Introduction to Data Structures. Introduction to Data Structures. Data Structures

Basic Data Structures

if (Q.head = Q.tail + 1) or (Q.head = 1 and Q.tail = Q.length) then throw F ullqueueexception if (Q.head = Q.tail) then throw EmptyQueueException

Basic Data Structures 1 / 24

Introduction to Data Structures

Amortized Analysis. 0.1 Amortized Case Analysis. CITS2200 Data Structures and Algorithms

Linked Structures. See Section 3.2 of the text.

CS 231 Data Structures and Algorithms Fall DDL & Queue Lecture 20 October 22, Prof. Zadia Codabux

Queues. Queue ADT Queue Implementation Priority Queues

COS 226 Algorithms and Data Structures Spring Midterm

CS 216 Exam 1 Fall SOLUTION

CS 206 Introduction to Computer Science II

Department of Computer Science Admission Test for PhD Program. Part I Time : 30 min Max Marks: 15

INFO1x05 Tutorial 6. Exercise 1: Heaps and Priority Queues

Computer Science First Exams Pseudocode Standard Data Structures Examples of Pseudocode

INSTITUTE OF AERONAUTICAL ENGINEERING

COP 3502 (Computer Science I) Test #3: Data Structures Date: 11/1/2013 VERSION A

Computer Science CS221 Test 2 Name. 1. Give a definition of the following terms, and include a brief example. a) Big Oh

NATIONAL UNIVERSITY OF SINGAPORE

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

COS 226 Algorithms and Data Structures Fall Midterm

ADVANCED DATA STRUCTURES USING C++ ( MT-CSE-110 )

COMP250: Stacks. Jérôme Waldispühl School of Computer Science McGill University. Based on slides from (Goodrich & Tamassia, 2004)

Abstract Data Type: Stack

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

Data Structure Advanced

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

Summer Final Exam Review Session August 5, 2009

CH ALGORITHM ANALYSIS CH6. STACKS, QUEUES, AND DEQUES

Linear Structures. Linear Structure. Implementations. Array details. List details. Operations 4/18/2013

Linked List. April 2, 2007 Programming and Data Structure 1

Queues COL 106. Slides by Amit Kumar, Shweta Agrawal

Data Abstraction and Specification of ADTs

Computer Science 62. Bruce/Mawhorter Fall 16. Midterm Examination. October 5, Question Points Score TOTAL 52 SOLUTIONS. Your name (Please print)

DNHI Homework 3 Solutions List, Stacs and Queues

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

CMSC 132: Object-Oriented Programming II. Stack and Queue

Lecture 3: Stacks & Queues

1. Introduction. Lists. 2. List windows. Data Structures and Algorithms

We've tried to include the common errors and grading standard for every question.

Linear Structures. Linear Structure. Implementations. Array details. List details. Operations 2/10/2013

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

8. Fundamental Data Structures

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified)

Sample Question Paper

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

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

Basic Data Structures (Version 7) Name:

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

EXAMINATIONS 2011 Trimester 2, MID-TERM TEST. COMP103 Introduction to Data Structures and Algorithms SOLUTIONS

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

CSCE 2014 Final Exam Spring Version A

Data Structure (CS301)

MIDTERM EXAMINATION Spring 2010 CS301- Data Structures

Computer Science 302 Spring 2007 Practice Final Examination: Part I

CS-141 Exam 2 Review November 10, 2017 Presented by the RIT Computer Science Community

CSE 143 SAMPLE MIDTERM

Data Structures. Outline. Introduction Linked Lists Stacks Queues Trees Deitel & Associates, Inc. All rights reserved.

PA3 Design Specification

Queues Fall 2018 Margaret Reid-Miller

Module 2: Priority Queues

CS 315 Data Structures mid-term 2

Module 2: Priority Queues

End-Term Examination Second Semester [MCA] MAY-JUNE 2006

CSC 1052 Algorithms & Data Structures II: Linked Queues

Please note that if you write the mid term in pencil, you will not be allowed to submit a remark request.

NATIONAL UNIVERSITY OF SINGAPORE

Wentworth Institute of Technology COMP201 Computer Science II Spring 2015 Derbinsky. Stacks and Queues. Lecture 11.

CE204 Data Structures and Algorithms Part 2

data structures and algorithms lecture 6

15110 Principles of Computing, Carnegie Mellon University - CORTINA. Binary Search. Required: List L of n unique elements.

University of Palestine. Final Exam 2 nd semester 2014/2015 Total Grade: 50

CS 206 Introduction to Computer Science II

STACKS AND QUEUES. Problem Solving with Computers-II

COSC160: Data Structures: Lists and Queues. Jeremy Bolton, PhD Assistant Teaching Professor

CS24 Week 4 Lecture 2

Keeping Order:! Stacks, Queues, & Deques. Travis W. Peters Dartmouth College - CS 10

FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- MARCH, 2012 DATA STRUCTURE (Common to CT and IF) [Time: 3 hours

CS301 - Data Structures Glossary By

Standard ADTs. Lecture 19 CS2110 Summer 2009

Department of Computer Science and Technology

A6-R3: DATA STRUCTURE THROUGH C LANGUAGE


CMSC Introduction to Algorithms Spring 2012 Lecture 7

EXAMINATIONS 2012 Trimester 1, MID-TERM TEST. COMP103 Introduction to Data Structures and Algorithms SOLUTIONS

CS 8391 DATA STRUCTURES

Fundamentals of Data Structure

A queue is a linear collection whose elements are added on one end and removed from the other

CSCA48 Winter 2018 Week 3: Priority Queue, Linked Lists. Marzieh Ahmadzadeh, Nick Cheng University of Toronto Scarborough

Linear Data Structures

Queues. Virtuelle Fachhochschule. Prof. Dr. Debora Weber-Wulff

CS24 Week 8 Lecture 1

Transcription:

THE UNIVERSITY OF WESTERN AUSTRALIA MID SEMESTER EXAMINATION April 2016 SCHOOL OF COMPUTER SCIENCE & SOFTWARE ENGINEERING DATA STRUCTURES AND ALGORITHMS CITS2200 This Paper Contains: 6 Pages 10 Questions Time allowed : Forty five minutes Marks for this paper total 10. Candidates should answer ALL Questions.

Q1. f(x) = O(log 2 n), g(x) = O(n log n) and h(x) = O(n). Which of the following statements is true? (A) g(x) = O(f(x)) (B) h(x) = O(f(x)) (C) g(x) = O(h(x)) (D) f(x) = O(g(x)) Q2. The time complexity of the merge method in the Merge Sort algorithm is: (A) O(log n) (B) O(1) (C) O(n) (D) none of the above. Q3. The time complexity of the Partition method in the Quick Sort algorithm is: (A) O(n) (B) O(n 2 ) (C) O(log n) (D) constant time. 2

Q4. The following is the code for the dequeue() method for the recursive or linked implementation of a Queue: public Object dequeue () throws Underflow{ if (!isempty()){ Object o = first.item; <missing line 1.> if (isempty()) <missing line 2.> return o; else throw new Underflow("dequeuing from empty queue"); The missing lines are: (A) 1.first = first.successor; 2.last = last.successor; (B) 1.first = first.successor; 2.last = null; (C) 1.first = null; 2.last = null; (D) 1.first.successor = first; 2.last = null; 3

Q5. The following is the code for previous method in a singly linked list. It shifts the position of the window one position to the left, i.e., previous to the current position: public void previous (WindowLinked w) throws OutOfBounds { if (!isbeforefirst(w)) { Link current = before.successor; Link previous = before; while (current!= w.link) { <missing line 1.> current = current.successor; <missing line 2.>; else throw new OutOfBounds ("Calling previous before start of list."); The missing lines are: (A) 1. current=previous; 2. w.link = previous; (B) 1. previous = current; 2. w.link = current; (C) 1. previous = current; 2. w.link = previous; (D) 1. current = previous; 2. w.link = current; Q6. We want to add an extra method called multidequeue to the implementation of a Queue. multidequeue(n) removes n elements from the front of a Queue. If we perform n multidequeue operations, the amortized cost is: (A) O(n); (B) O(n 2 ); (C) O(n 3 ); (D) O(1); 4

Q7. The number of edges in a tree with n nodes is: (A) n 1; (B) n; (C) n log n; (D) n 2 ; Q8. We have a tree with n nodes. Which of the following statements about its height cannot be true? (A) The height is O(log n); (B) The height is n 2 ; (C) The height is O(n log n); (D) The height is 6; Q9. Which of the following statements is incorrect? (A) The worst-case complexity of insertion sort is O(n 2 ); (B) The worst-case complexity of merge sort is O(n log n); (C) The worst-case complexity of quick sort is O(n log n); (D) The worst-case complexity of quick sort is O(n 2 ); 5

Q10. We want to implement a method called popeye(i) for the stack data structure. Given a stack stack1 and an integer i, popeye(i) pops the i-th item from the top of stack1 and keeps stack1 otherwise as it was before. In other words, the only difference in the state of stack1 before and after the popeye(i) operation is that the ith item from the top will be missing. We will assume that underflow will not occur during a popeye(i) operation. We propose two strategies for implementing popeye(i). 1. We use an additional queue called queue1. We pop the first i 1 items from the top of stack1 one by one and enqueue those items in queue1 as we pop each item from stack1. We then pop the ith item from stack1 and return it as a result of the execution of the popeye(i) method. We next dequeue each item from queue1 and push it onto stack1 until queue1 is empty. 2. We use an additional stack called stack2. We pop the first i 1 items from the top of stack1 one by one and push those items into stack2 as we pop each item from stack1. We then pop the ith item from stack1 and return it as a result of the execution of the popeye(i) method. We next pop each item from stack2 and push it onto stack1, until stack2 is empty. Which of the following statements is true? (A) Both strategies correctly implement the popeye(i) method. (B) Only the first strategy correctly implements the popeye(i) method. (C) None of the strategies correctly implements the popeye(i) method. (D) Only the second strategy correctly implements the popeye(i) method. END OF PAPER 6