COMP 103. Mid Trimester Test 17 August 2006

Similar documents
SOLUTIONS. COMP103 Introduction to Data Structures and Algorithms

COMP103 Test. 5 Sept, 2007

EXAMINATIONS 2015 COMP103 INTRODUCTION TO DATA STRUCTURES AND ALGORITHMS

EXAMINATIONS 2017 TRIMESTER 2

EXAMINATIONS 2016 TRIMESTER 2

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

CS171 Midterm Exam. October 29, Name:

EXAMINATIONS 2012 MID YEAR. COMP103 Introduction to Data Structures and Algorithms SOLUTIONS

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

COMP 103 Introduction to Data Structures and Algorithms

EXAMINATIONS 2005 END-YEAR. COMP 103 Introduction to Data Structures and Algorithms

Model Solutions. COMP 103: Mid-term Test. 21st of August, 2014

Prelim 2, CS2110. SOLUTION

CS 12 Fall 2003 Solutions for mid-term exam #2

Sorting. Weiss chapter , 8.6

WITH SOLUTIONS!!! WARNING: THIS COPY CONTAINS SOLUTIONS!!! COMP103 Introduction to Data Structures and Algorithms

Day 10. COMP1006/1406 Summer M. Jason Hinek Carleton University

ECE 242 Data Structures and Algorithms. Advanced Sorting II. Lecture 17. Prof.

CS 151 Name Final Exam December 17, 2014

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

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

EXAMINATIONS 2006 SUMMER TRIMESTER. COMP103 Introduction to Data Structures and Algorithms

Prelim 2 SOLUTION. 5:30 PM, 25 April Total Question Name Short Search/ Collections Trees Graphs

Computer Science 62. Midterm Examination

Sorting. Sorting in Arrays. SelectionSort. SelectionSort. Binary search works great, but how do we create a sorted array in the first place?

2/14/13. Outline. Part 5. Computational Complexity (2) Examples. (revisit) Properties of Growth-rate functions(1/3)

1 P a g e A r y a n C o l l e g e \ B S c _ I T \ C \

Sorting. Sorting. Stable Sorting. In-place Sort. Bubble Sort. Bubble Sort. Selection (Tournament) Heapsort (Smoothsort) Mergesort Quicksort Bogosort

Total Score /1 /20 /41 /15 /23 Grader

CS 151 Name Final Exam December 17, 2014

Model Solutions. COMP 103: Test April, 2013

COS 226 Algorithms and Data Structures Fall Midterm

COS 226 Midterm Exam, Spring 2009

APJ ABDUL KALAM TECHNOLOGICAL UNIVERSITY THIRD SEMESTER B.TECH DEGREE EXAMINATION, JULY 2017 CS205: DATA STRUCTURES (CS, IT)

COP 3502 Spring 2018 Study Union Review

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

Divide and Conquer Algorithms: Advanced Sorting

9/10/12. Outline. Part 5. Computational Complexity (2) Examples. (revisit) Properties of Growth-rate functions(1/3)

IT 4043 Data Structures and Algorithms

Model Solutions. COMP 103: Test May, 2013

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

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

COMP103 Summer: Midterm

U N I V E R S I T Y O F W E L L I N G T O N EXAMINATIONS 2018 TRIMESTER 2 COMP 103 INTRODUCTION TO DATA STRUCTURES AND ALGORITHMS

COMP Data Structures

LINKED LISTS cs2420 Introduction to Algorithms and Data Structures Spring 2015

CSCI 6620 Data Structures

COMP 250. Lecture 8. stack. Sept. 25, 2017

Data Structures and Algorithms 2018

Module Contact: Dr Geoff McKeown, CMP Copyright of the University of East Anglia Version 1

Sorting. Quicksort analysis Bubble sort. November 20, 2017 Hassan Khosravi / Geoffrey Tien 1

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

V.S.B ENGINEERING COLLEGE DEPARTMENT OF INFORMATION TECHNOLOGY I IT-II Semester. Sl.No Subject Name Page No. 1 Programming & Data Structures-I 2

Unit Outline. Comparing Sorting Algorithms Heapsort Mergesort Quicksort More Comparisons Complexity of Sorting 2 / 33

COMP 103. Data Structures and Algorithms

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

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)

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

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

About this exam review

Midterm I Exam Principles of Imperative Computation Frank Pfenning, Tom Cortina, William Lovas. September 30, 2010

for (int outercounter = nums.length - 1; outercounter > 0 && swappedthatturn; outercounter --

EXAMINATIONS 2009 END-OF-YEAR. COMP 202 / SWEN 202 Formal Methods of Computer Science / Formal Foundations of Software Engineering

Arrays and functions Multidimensional arrays Sorting and algorithm efficiency

Data Structures and Algorithms Notes

CS 112 Midterm Exam Fall 2016

OF VICTORIA EXAMINATIONS- DECEMBER 2010 CSC

Algorithm Efficiency & Sorting. Algorithm efficiency Big-O notation Searching algorithms Sorting algorithms

COMP 250. Lecture 7. Sorting a List: bubble sort selection sort insertion sort. Sept. 22, 2017

CP222 Computer Science II. Searching and Sorting

CSCI 136 Data Structures & Advanced Programming. Lecture 12 Fall 2018 Profs Bill & Jon

ECE368 Exam 2 Spring 2016

CS 231 Data Structures and Algorithms Fall Algorithm Analysis Lecture 16 October 10, Prof. Zadia Codabux

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING B.E SECOND SEMESTER CS 6202 PROGRAMMING AND DATA STRUCTURES I TWO MARKS UNIT I- 2 MARKS

University of Waterloo CS240, Winter 2010 Assignment 2

Family Name:... Other Names:... ID Number:... Signature... Model Solutions. COMP 103: Test 1. 9th August, 2013

You must include this cover sheet. Either type up the assignment using theory3.tex, or print out this PDF.

Draw a diagram of an empty circular queue and describe it to the reader.

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

CS200 Final Exam Fall 2007

CS 455 Final Exam Fall 2012 [Bono] Dec. 17, 2012

Computer Science Foundation Exam. May 6, Computer Science. Section 1A. No Calculators! KEY. Score: 50

Chapter 7 Sorting. Terminology. Selection Sort

COS 226 Algorithms and Data Structures Spring Midterm Exam

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

Computer Science 302 Spring 2018 Practice Examination for the Second Examination,

CS 367: Introduction to Data Structures Midterm Sample Questions

COMP 103 : Test. 2019, Jan 9 ** WITH SOLUTIONS **

CS111: PROGRAMMING LANGUAGE II

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

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

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

Points off Total off Net Score. CS 314 Final Exam Spring 2016

Remember to also pactice: Homework, quizzes, class examples, slides, reading materials.

CSI33 Data Structures

CS 314 Exam 2 Spring

! Determine if a number is odd or even. ! Determine if a number/character is in a range. ! Assign a category based on ranges (wind speed)

data structures and algorithms lecture 6

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

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

Transcription:

Name ID: COMP 103 Mid Trimester Test 17 August 2006 Time: 90 minutes Marks: 90 Answer all questions. Non programmable calculators permitted Unannotated foreign language dictionaries permitted 1. Collection Types 16 2. ArrayList 12 3. Sorting 30 4. Linked Lists 17 5. Using Collections 15 90

Spare page 2

Question 1. Collection Types. [16 Marks] (a) [4 marks] Which collection type would be a good choice for representing the collection of people waiting to be served at a supermarket checkout? Explain why. (b) [4 marks] Which collection type would be a good choice for storing information about which employees are currently inside a building? Explain why. (c) [4 marks] Which collection type would be a good choice for storing the information needed to retrieve automobile ownership records based on number plate? Explain why. (d) [4 marks] Name a collection type that has constrained access and state the ways in which the access is constrained. 3

Question 2 ArrayList [12 Marks] (a) [3 Marks] Draw a diagram showing the result of inserting the following three items into an ArrayList that initially contains [ Hum, Dance, Bee ] insert Buzz at index 2, insert Hive at index 2, insert Net at index 0. count: data: (b) [4 Marks] Draw a diagram showing how ensurecapacity increases the capacity of an ArrayList when the array becomes full. Label the steps on your diagram to make the sequence clear. 4

(c) [5 Marks] Consider the following clear method for the ArrayList class that removes all the items in an ArrayList. It uses the remove method, which removes the item at a given index). Assume that the count field stores the number of items in the ArrayList. public void clear(){ } int max = count; for (int j = 0; j < max; j++) remove(0); What is the cost of this method, expressed in terms of n = the initial size of the list? Justify your answer. 5

Question 3 Sorting [30 Marks] (a) [8 marks] For each of the following sort algorithms, state its average case cost and worst case cost (using big-o notation), whether it is stable, and whether it is in-place. Average case Worst case Stable? In-place? Insertion Sort: MergeSort: QuickSort: Radix Sort: (b) [4 marks] Show how Bubble Sort sorts the following list of six items by showing the state of the list after each swap. [ A, B, D, F, E, C ] 6

(c) [7 marks] Show how Quicksort sorts the following list of 9 items by showing the state of the list after each call to partition You may use the partition algorithm described in the lectures. You may also use another standard partition algorithm, but you must then describe it very briefly. [ J, H, G, V, U, K, L, H, U ] 7

(d) [7 marks] Outline the Insertion sort algorithm using pseudo code. (e) [4 marks] Explain why InsertionSort is more efficient than QuickSort or MergeSort if you know that the list is almost sorted. 8

Spare Page. 9

Question 4 Linked Lists [17 Marks] (a) [2 Marks] Suppose the variable mylist contains a linked list of three items ( A, B, and C ). Draw a diagram of the linked list. mylist: (b) [2 marks] Show the changes to the linked list in (a) after the following statement: mylist: mylist = new LinkedNode( X, mylist.next); (c) [2 marks] Show the changes to the original linked list in (a) after the following statement: mylist: mylist.next.next = new LinkedNode( Y, null) (d) [2 marks] Show the changes to the original linked list in (a) after the following statement: mylist: mylist.next.next.next = mylist.next; 10

(e) [4 Marks] Suppose you implemented a Stack using a linked list with a header node as shown below, and chose to use the last node of the linked list as the top of the stack (where items are pushed and popped). Explain why this is a bad design. Top (f) [5 Marks] Suppose you were implementing a Queue using a linked list and a header node containing two fields: front and back. Draw a diagram of how you would implement the queue, showing a queue with three elements. Explain why you chose this implementation. 11

Question 5. Using Collections [15 Marks] Most programming languages require that the syntax is properly nested. For example, an if statement cannot start inside a while loop but end outside the loop. A compiler must therefore check that every opening item has a matching closing item, and that the constructs are properly nested. Consider a language that doesn t use brackets or braces, but uses the keywords if and fi to open and close an if statement, and the keywords do and od to open and close a loop. The program xxx do xxx xxx if yyy yyy fi xxx od zzz would be properly nested, but the programs xxx do xxx if yyy od xxx fi and xxx do yyy if yyy od zzz would not be properly nested. Complete the following method that takes an argument containing a List of the words in a program and returns true if the program is correctly nested, and returns false otherwise. Assume that the only opening and closing words are if, fi, do, and od, and that all other words can be ignored. public boolean checknested(list<string> program){ } 12