COSC 2011: Assignment 1 (v.4)

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

McGill University School of Computer Science COMP-202A Introduction to Computing 1

Data Structures and Algorithms Key to Homework 1

CS171 Midterm Exam. October 29, Name:

Mandatory Assignment 1, INF 4130, 2017

Complexity, General. Standard approach: count the number of primitive operations executed.

COS 226 Algorithms and Data Structures Fall Midterm

Pace University. Fundamental Concepts of CS121 1

Programming Problems 22nd Annual Computer Science Programming Contest

Randomized Queues and Deques

Question: Total Points: Score:

Outline. runtime of programs algorithm efficiency Big-O notation List interface Array lists

Midterm I - CSE11 Fall 2013 CLOSED BOOK, CLOSED NOTES 50 minutes, 100 points Total.

Question: Total Points: Score:

COMP 103. Mid Trimester Test 17 August 2006

TOPIC 8 MORE ON WHILE LOOPS

Jump Statements. The keyword break and continue are often used in repetition structures to provide additional controls.

University of Waterloo CS240 Winter 2018 Assignment 2. Due Date: Wednesday, Jan. 31st (Part 1) resp. Feb. 7th (Part 2), at 5pm

Computer Science 302 Spring 2007 Practice Final Examination: Part I

Final Examination CS 125 Introduction to Computer Science Fall Hours

Deliverables. Problem Description

CS 101 Fall 2005 Midterm 2 Name: ID:

Sorting. Bubble Sort. Selection Sort

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;

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

Announcements. Lab Friday, 1-2:30 and 3-4:30 in Boot your laptop and start Forte, if you brought your laptop

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

Question: Total Points: Score:

About this exam review

Cosc 241 Programming and Problem Solving Lecture 9 (26/3/18) Collections and ADTs

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

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

NATIONAL UNIVERSITY OF SINGAPORE

CSE wi: Practice Midterm

public class Q1 { public int x; public static void main(string[] args) { Q1 a = new Q1(17); Q1 b = new Q1(39); public Q1(int x) { this.

CSE373 Fall 2013, Midterm Examination October 18, 2013

CS 101 Fall 2006 Midterm 3 Name: ID:

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

Binary Search. Roland Backhouse February 5th, 2001

Data Structures and Algorithms, Winter term 2018 Practice Assignment 3

Nested Loops. A loop can be nested inside another loop.

CS 201, Fall 2016 Oct 28th Exam 2. Question 1. [5 points] Consider the following static method:

Jump Statements. The keyword break and continue are often used in repetition structures to provide additional controls.

BSc. (Hons.) Software Engineering. Examinations for / Semester 2

CS 113 MIDTERM EXAM 2 SPRING 2013

COMP-202: Foundations of Programming. Lecture 8: for Loops, Nested Loops and Arrays Jackie Cheung, Winter 2016

Exam 1 Prep. Dr. Demetrios Glinos University of Central Florida. COP3330 Object Oriented Programming

University of Waterloo CS240, Winter 2010 Assignment 2

COS 126 Exam 2 Review Part 1

Lab Exercise 1. Objectives: Part 1. Introduction

Data Structures Brett Bernstein

CS2 Practical 1 CS2A 22/09/2004

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

Csci 102: Sample Exam

CS 455 Final Exam Spring 2018 [Bono] May 8, 2018

Control Flow: Loop Statements

C22a: Problem Solving using Recursion

The smallest element is the first one removed. (You could also define a largest-first-out priority queue)

CSE 143 SAMPLE MIDTERM

Some Sample AP Computer Science A Questions - Solutions

CS 261 Data Structures. Big-Oh Analysis: A Review

CS 6353 Compiler Construction Project Assignments

COMPUTER SCIENCE. Paper 1

Faculty of Science COMP-202A - Introduction to Computing I (Fall 2008) Midterm Examination

Arrays. Eng. Mohammed Abdualal

2018 Pummill Relay problem statement

Lecture 6: Divide-and-Conquer

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

Outline. Parts 1 to 3 introduce and sketch out the ideas of OOP. Part 5 deals with these ideas in closer detail.

Computer Science 1 Ah

ALGORITHM ANALYSIS. cs2420 Introduction to Algorithms and Data Structures Spring 2015

(Refer Slide Time: 1:27)

CMPSCI 187: Programming With Data Structures. Lecture 12: Implementing Stacks With Linked Lists 5 October 2011

Maps and Binary Search

Name CIS 201 Midterm II: Chapters 1-8

SOLUTIONS. COMP103 Introduction to Data Structures and Algorithms

Following is the general form of a typical decision making structure found in most of the programming languages:

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

Repetition Algorithms

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

(f) Given what we know about linked lists and arrays, when would we choose to use one data structure over the other?

1.00 Introduction to Computers and Engineering Problem Solving. Quiz 1 March 7, 2003

Dynamic Dictionaries. Operations: create insert find remove max/ min write out in sorted order. Only defined for object classes that are Comparable

H212 Introduction to Software Systems Honors

CS 367: Introduction to Data Structures Midterm Sample Questions

Admin. CS 112 Introduction to Programming. Counting Down: Code Puzzle. Counting Down: Code Puzzle

CSE332 Summer 2010: Final Exam

COMP-202: Foundations of Programming. Lecture 3: Boolean, Mathematical Expressions, and Flow Control Sandeep Manjanna, Summer 2015

Priority queues. Priority queues. Priority queue operations

CSE505, Fall 2012, Midterm Examination October 30, 2012

Data Structures. Alice E. Fischer. Lecture 4, Fall Alice E. Fischer Data Structures L4... 1/19 Lecture 4, Fall / 19

CSE 247 Data Structures and Algorithms Fall Exam I

Question: Total Points: Score:

Cosc 241 Programming and Problem Solving Lecture 17 (30/4/18) Quicksort

CSCI 135 Exam #0 Fundamentals of Computer Science I Fall 2012

CIS 110 Introduction to Computer Programming 8 October 2013 Midterm

Question: Total Points: Score:

CS 314 Midterm 2 Fall 2012

Exam 2. Programming I (CPCS 202) Instructor: M. G. Abbas Malik. Total Marks: 40 Obtained Marks:

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

Transcription:

Department of Computer Science and Engineering COSC 2011: Assignment 1 (v.4) Due Date - Friday, October 10 by Noon For any of the following exercises, you may assume that you have access to an efficient sort routine, say mergesort or heapsort, which sorts an array of comparable objects in worst-case running-time of O(n log n). 1. Algorithm Design: Algorithm for Breaking a Secret Key (15 %) 1 Consider a set of n words (S). Each word (w) in S has a unique value of asciisum(w), which is obtained by summing up the ASCII values of all characters in w. The access to a database is protected with a secret-key consisting of two words, i.e. a secret-key in the form of [ID, Password] pair. Each of the two components has been chosen from S (ID, Password S). Together, the selected ID and Password satisfy the following m is a positive integer constant. asciisum(id) + asciisum(password) = m Lock ID ***** Password ******** Figure 1 Secret Lock Now, assume that all words from S and the value of m are known to us. Design an O(n log(n))-time algorithm that searches through all possible pair combinations [ID, Password] of words from S, until the right one (i.e. the actual secret-key) is found. Describe your algorithm both in English and in pseudo-code or Java. Mention any additional data structure used, and explain in detail why the timecomplexity is O(n log(n)). If you decide to describe your algorithm in java, you can assume that there is a class Lock, with a method public boolean unlock(string ID, String Password). (Lock L).unlock(word1, word2) returns true if the right combination of word-arguments is used; otherwise it returns false. This method runs in O(1) time. You can also assume asciisum(string word) is public. 1 15% of the overall mark for this assignment.

2. Algorithm Design: Sorting Lego Objects (15 %) Consider an array of n Lego objects. Each Lego has a method colour() that returns the value red, blue, or white. Write in pseudo-code a linear-time algorithm that rearranges the array of Legoes so that the red Lego objects come first, the blue Lego objects come next, and the white Lego objects some last. Explain briefly but convincingly why your algorithm is O(n). 3. Algorithm Design and Analysis: 2-D Array Manipulation (15 %) (a) Suppose that each row of an nxn array A consists of positive and negative real numbers such that in any row of A, all the negative numbers come before any positive number in that row. Assuming A is already in memory, describe a method running in O(n) time for finding the row of A with the most positive numbers. Give a pseudo-code description of your algorithm. (b) Suppose further that the number of positive numbers in row i is at most the number of positive numbers in row (i+1) for i=0,1,..,(n-1). Assuming A is already in memory, describe a method running in O(n) time for counting negative numbers in the array A. Give a pseudo-code description of your algorithm. (c) Finally, assume that the array from (b) also satisfies the following: there are m negative and (n-m) positive numbers in the first row (0 m n); there are k negative and (n-k) positive numbers in the last row (where 0 k m must be satisfied, based on (b)); A(i,j)=A(i+1,j) if both positive, or both negative. Propose a minimum running-time algorithm for sorting array A row-wise, that is which sorts each row. Give a pseudo-code description of your algorithm and its running time in Big-O notation. Your algorithm should be O(n 2 ) for full credit. 4. Algorithm Analysis: Big-Θ Notation (15 %) Determine the Θ running time of the following algorithm in terms of n: for i = 1 to n for j = 1 to i*i if (j%i == 0) for k=1 to j sum ++ Show clearly the steps of how you have derived the solution.

5. Project Question (40 %) Background information Self-Organizing Lists: Search in a linked list requires that a half of the nodes be visited on average, if the search (i.e., request) probabilities are uniformly distributed among the list elements. If however, the most frequently searched elements get placed near the front of the list, the average search time improves. (Linked) lists with such property are called selforganizing. There are many different strategies for placing the most frequently searched items near the front, one of them being simple move-to-front. According to simple move-to-front, every time your search for an element (and find it), you move the element to the front of the list. In general, this strategy is a gamble, since some items may be searched for once, and never again. However, after a series of subsequent searches, such items would slowly sink to the end of the list, while the ones that have been searched for more frequently would remain close to the front. Through this project, you will be required to design and implement an ordinary and a selforganizing list, and compare their performance in terms of complexity of their search operations. Project Description A movie-rental company has decided to create a database of all its movies-titles, using a simple List ADT. The interface of this ADT should look as follows: public interface MovieList { public int size(); public boolean isempty(); public boolean searchmovie(string title); public String remove(movie p); public Movie insert(string title); The company is committed to providing the best possible service to its customers, so it wants to know which actual implementation of the database (i.e., MovieList interface) would result in the minimum average search-time for a movie. The company possesses files with the access records from previous years, which can be used for test purposes. Two such files are available at: http://www.cs.yorku.ca/course/2011/project/movie/movieaccessyear2001.dat http://www.cs.yorku.ca/course/2011/project/movie/movieaccessyear2002.dat (The above two files can be downloaded together from: http://www.cs.yorku.ca/course/2011/project/movie/movieaccessdatfiles.zip) Version 3 Note: We replaced MovieAccessYear200X with larger files of 100,000 titles each, rather than the 1,000 titles each that we had before. This is because some people did not see a time difference between the two MovieLists (ordinary and self-organizing) with the smaller files. You can still access the original files (if you need to for some reason) at: http://www.cs.yorku.ca/course/2011/project/movie/movieaccessyear2001_1k.dat http://www.cs.yorku.ca/course/2011/project/movie/movieaccessyear2002_1k.dat

You are asked to conduct this analysis and propose the best possible List design to the company. The analysis should involve these steps: (1) create Movie class, analogous to Position class - as discussed in class, and 5.2.2 of the textbook. Besides element() method, which returns (String) movietitle, the interface of this ADT should include another method public int accesscount(), which returns the number of times than an instance of Movie class (i.e., its movietitle) has been accessed. (1) create OrdinaryMoveList class, a simple straight-forward implementation of MovieList interface. (2) create SelfOrganizingMovieList class, an implementation of MovieList interface that includes the basic functionality of self-organizing lists, as described in the Background Information. (3) create MovieListComparator class, this class contains the titles of all available movies, stored in a form of an array, and main method. (An outline of this class and its required functionality is given below, and can also be accessed at the following URL: www.cs.yorku.ca/course/2011/project/movie/movielistcomparator.html ) (4) create SearchTimer class, an auxiliary class responsible for the run-time measurement of a series of search operations on a MovieList. (An outline of this class and its required functionality is also given below.) public class MovieListComparator { / * class variables */ public final static String[ ] moviecollection = { Casablanca, Cast Away, Forrest Gump, Ghost, Gladiator, Midnight Cowboy, One Flew Over the Cuckoo's Nest, The Dead Poet Society, The Godfather, Tootsie ; OrdinaryMovieList list1; SelfOrganizedMovieList list2; String[ ] accessedmovies = new String[100000]; /* constructor */ public MovieListComparator() { /* store moviecollection in an empty movielist */ public void storeinlist(movielist list) { ; /* from a given file, read a list of previously accessed movies (one title per line), and store the list in accessedmovies array */ public void readaccessedmovies(string filename) { ; /* within main method of MovieListComparator the following should be executed: (1) create instances of list1 and list2, and store the content of MovieCollection array in each; (2) prompt the user for the name of the file with a previous access record, and store this list in accessedmovies array; (3) by using SearchTimer class, measure the times required to search movie titles from accessedmovies in list1 and list2; (4) print out the results from (3) and state which list provides a better overall performance for the given access record; (5) print out each title from moviecollection and the number of times it has been accessed during (3). */ public static void main(string[ ] args) {

public class SearchTimer { / * class variables */ MovieList ML; int executiontime; /* constructor */ public SearchTimer(MovieList L) { ML = L; /* perform searches for testtitles on ML, and return the overall execution time in milliseconds */ public int measure(string[] testtitles, int numberoftesttitles) { HINT: Implement measure() method of SearchTimer class using Java s System.currentTimeMillis() method.