COSC 2011: Assignment 1 (v.4)

Size: px
Start display at page:

Download "COSC 2011: Assignment 1 (v.4)"

Transcription

1 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 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.

3 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: (The above two files can be downloaded together from: 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:

4 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 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: ) (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) {

5 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.

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

CPSC 211, Sections : Data Structures and Implementations, Honors Final Exam May 4, 2001 CPSC 211, Sections 201 203: Data Structures and Implementations, Honors Final Exam May 4, 2001 Name: Section: Instructions: 1. This is a closed book exam. Do not use any notes or books. Do not confer with

More information

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

McGill University School of Computer Science COMP-202A Introduction to Computing 1 McGill University School of Computer Science COMP-202A Introduction to Computing 1 Midterm Exam Thursday, October 26, 2006, 18:00-20:00 (6:00 8:00 PM) Instructors: Mathieu Petitpas, Shah Asaduzzaman, Sherif

More information

Data Structures and Algorithms Key to Homework 1

Data Structures and Algorithms Key to Homework 1 Data Structures and Algorithms Key to Homework 1 January 31, 2005 15 Define an ADT for a set of integers (remember that a set may not contain duplicates) Your ADT should consist of the functions that can

More information

CS171 Midterm Exam. October 29, Name:

CS171 Midterm Exam. October 29, Name: CS171 Midterm Exam October 29, 2012 Name: You are to honor the Emory Honor Code. This is a closed-book and closed-notes exam. You have 50 minutes to complete this exam. Read each problem carefully, and

More information

Mandatory Assignment 1, INF 4130, 2017

Mandatory Assignment 1, INF 4130, 2017 Mandatory Assignment 1, INF 4130, 2017 Deadline: Monday October 2. First: Read the general requirements for mandatory assignments at the department here: Norwegian: https://www.uio.no/studier/admin/obligatoriske-aktiviteter/mn-ifi-obliger-retningslinjer.html

More information

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

Complexity, General. Standard approach: count the number of primitive operations executed. Complexity, General Allmänt Find a function T(n), which behaves as the time it takes to execute the program for input of size n. Standard approach: count the number of primitive operations executed. Standard

More information

COS 226 Algorithms and Data Structures Fall Midterm

COS 226 Algorithms and Data Structures Fall Midterm COS 226 Algorithms and Data Structures Fall 2017 Midterm This exam has 10 questions (including question 0) worth a total of 55 points. You have 0 minutes. This exam is preprocessed by a computer, so please

More information

Pace University. Fundamental Concepts of CS121 1

Pace University. Fundamental Concepts of CS121 1 Pace University Fundamental Concepts of CS121 1 Dr. Lixin Tao http://csis.pace.edu/~lixin Computer Science Department Pace University October 12, 2005 This document complements my tutorial Introduction

More information

Programming Problems 22nd Annual Computer Science Programming Contest

Programming Problems 22nd Annual Computer Science Programming Contest Programming Problems 22nd Annual Computer Science Programming Contest Department of Mathematics and Computer Science Western Carolina University 5 April 2011 Problem One: Add Times Represent a time by

More information

Randomized Queues and Deques

Randomized Queues and Deques Randomized Queues and Deques Write a generic ADT for a randomized queue or for a deque. The goal of this assignment is to implement elementary data structures using arrays and linked lists, and to get

More information

Question: Total Points: Score:

Question: Total Points: Score: CS 170 Exam 1 Section 000 Fall 2014 Name (print): Instructions: Keep your eyes on your own paper and do your best to prevent anyone else from seeing your work. Do NOT communicate with anyone other than

More information

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

Outline. runtime of programs algorithm efficiency Big-O notation List interface Array lists Outline runtime of programs algorithm efficiency Big-O notation List interface Array lists Runtime of Programs compare the following two program fragments: int result = 1; int result = 1; for (int i=2;

More information

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

Midterm I - CSE11 Fall 2013 CLOSED BOOK, CLOSED NOTES 50 minutes, 100 points Total. Midterm I - CSE11 Fall 2013 CLOSED BOOK, CLOSED NOTES 50 minutes, 100 points Total. Name: ID: Problem 1) (8 points) For the following code segment, what are the values of i, j, k, and d, after the segment

More information

Question: Total Points: Score:

Question: Total Points: Score: CS 170 Exam 1 Section 000 Spring 2015 Name (print): Instructions: Keep your eyes on your own paper and do your best to prevent anyone else from seeing your work. Do NOT communicate with anyone other than

More information

COMP 103. Mid Trimester Test 17 August 2006

COMP 103. Mid Trimester Test 17 August 2006 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

More information

TOPIC 8 MORE ON WHILE LOOPS

TOPIC 8 MORE ON WHILE LOOPS 1 TOPIC 8 MORE ON WHILE LOOPS Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B. Ericson, and instructor materials prepared by B. Ericson.

More information

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

Jump Statements. The keyword break and continue are often used in repetition structures to provide additional controls. Jump Statements The keyword break and continue are often used in repetition structures to provide additional controls. break: the loop is terminated right after a break statement is executed. continue:

More information

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

University of Waterloo CS240 Winter 2018 Assignment 2. Due Date: Wednesday, Jan. 31st (Part 1) resp. Feb. 7th (Part 2), at 5pm University of Waterloo CS240 Winter 2018 Assignment 2 version: 2018-02-04 15:38 Due Date: Wednesday, Jan. 31st (Part 1) resp. Feb. 7th (Part 2), at 5pm Please read the guidelines on submissions: http://www.student.cs.uwaterloo.ca/~cs240/

More information

Computer Science 302 Spring 2007 Practice Final Examination: Part I

Computer Science 302 Spring 2007 Practice Final Examination: Part I Computer Science 302 Spring 2007 Practice Final Examination: Part I Name: This practice examination is much longer than the real final examination will be. If you can work all the problems here, you will

More information

Final Examination CS 125 Introduction to Computer Science Fall Hours

Final Examination CS 125 Introduction to Computer Science Fall Hours University of Illinois at Urbana-Champaign Department of Computer Science Final Examination CS 125 Introduction to Computer Science Fall 2009 3 Hours Last Name: First Name: NetID: @ illinois.edu PLEASE

More information

Deliverables. Problem Description

Deliverables. Problem Description Deliverables Programming Project: GridWorld Due dates: Part I: June 28 at the beginning of class (hardcopy) Part II: Jun 5 at the beginning of class (electronic submission) In this project you will design

More information

CS 101 Fall 2005 Midterm 2 Name: ID:

CS 101 Fall 2005 Midterm 2 Name:  ID: This exam is open text book but closed-notes, closed-calculator, closed-neighbor, etc. Questions are worth different amounts (in particular, the final two questions are worth substantially more than any

More information

Sorting. Bubble Sort. Selection Sort

Sorting. Bubble Sort. Selection Sort Sorting In this class we will consider three sorting algorithms, that is, algorithms that will take as input an array of items, and then rearrange (sort) those items in increasing order within the array.

More information

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;

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; 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; } if (n

More information

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

CS61B, Fall 2011 Final Examination (corrected) P. N. Hilfinger CS61B, Fall 2011 Final Examination (corrected) P. N. Hilfinger READ THIS PAGE FIRST. Your exam should contain 16 problems on 16 pages. Officially, it is worth 50 points. This is an open-book test. You

More information

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

Announcements. Lab Friday, 1-2:30 and 3-4:30 in Boot your laptop and start Forte, if you brought your laptop Announcements Lab Friday, 1-2:30 and 3-4:30 in 26-152 Boot your laptop and start Forte, if you brought your laptop Create an empty file called Lecture4 and create an empty main() method in a class: 1.00

More information

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

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University 0/6/6 CS Introduction to Computing II Wayne Snyder Department Boston University Today Conclusions on Iterative Sorting: Complexity of Insertion Sort Recursive Sorting Methods and their Complexity: Mergesort

More information

Question: Total Points: Score:

Question: Total Points: Score: CS 170 Exam 1 Section 000 Spring 2015 Name (print): Instructions: Keep your eyes on your own paper and do your best to prevent anyone else from seeing your work. Do NOT communicate with anyone other than

More information

About this exam review

About this exam review Final Exam Review About this exam review I ve prepared an outline of the material covered in class May not be totally complete! Exam may ask about things that were covered in class but not in this review

More information

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

Cosc 241 Programming and Problem Solving Lecture 9 (26/3/18) Collections and ADTs 1 Cosc 241 Programming and Problem Solving Lecture 9 (26/3/18) Collections and ADTs Michael Albert michael.albert@cs.otago.ac.nz Keywords: abstract data type, collection, generic class type, stack 2 Collections

More information

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

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University 9/5/6 CS Introduction to Computing II Wayne Snyder Department Boston University Today: Arrays (D and D) Methods Program structure Fields vs local variables Next time: Program structure continued: Classes

More information

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

Instructions. Definitions. Name: CMSC 341 Fall Question Points I. /12 II. /30 III. /10 IV. /12 V. /12 VI. /12 VII. CMSC 341 Fall 2013 Data Structures Final Exam B Name: Question Points I. /12 II. /30 III. /10 IV. /12 V. /12 VI. /12 VII. /12 TOTAL: /100 Instructions 1. This is a closed-book, closed-notes exam. 2. You

More information

NATIONAL UNIVERSITY OF SINGAPORE

NATIONAL UNIVERSITY OF SINGAPORE NATIONAL UNIVERSITY OF SINGAPORE SCHOOL OF COMPUTING EXAMINATION FOR CS1020 Semester 2: AY2011/12 CS1020 Data Structures and Algorithms I April 2012 Time allowed: 2 hours Matriculation number: INSTRUCTIONS

More information

CSE wi: Practice Midterm

CSE wi: Practice Midterm CSE 373 18wi: Practice Midterm Name: UW email address: Instructions Do not start the exam until told to do so. You have 80 minutes to complete the exam. This exam is closed book and closed notes. You may

More information

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.

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. CS 201, Fall 2013 Oct 2nd Exam 1 Name: Question 1. [5 points] What output is printed by the following program (which begins on the left and continues on the right)? public class Q1 { public int x; public

More information

CSE373 Fall 2013, Midterm Examination October 18, 2013

CSE373 Fall 2013, Midterm Examination October 18, 2013 CSE373 Fall 2013, Midterm Examination October 18, 2013 Please do not turn the page until the bell rings. Rules: The exam is closed-book, closed-note, closed calculator, closed electronics. Please stop

More information

CS 101 Fall 2006 Midterm 3 Name: ID:

CS 101 Fall 2006 Midterm 3 Name:  ID: You only need to write your name and e-mail ID on the first page. This exam is CLOSED text book, closed-notes, closed-calculator, closed-neighbor, etc. Questions are worth different amounts, so be sure

More information

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

CS 455 Final Exam Fall 2012 [Bono] Dec. 17, 2012 Name: USC loginid (e.g., ttrojan): CS 455 Final Exam Fall 2012 [Bono] Dec. 17, 2012 There are 6 problems on the exam, with 70 points total available. There are 7 pages to the exam, including this one;

More information

Binary Search. Roland Backhouse February 5th, 2001

Binary Search. Roland Backhouse February 5th, 2001 1 Binary Search Roland Backhouse February 5th, 2001 Outline 2 An implementation in Java of the card-searching algorithm is presented. Issues concerning the correctness of the implementation are raised

More information

Data Structures and Algorithms, Winter term 2018 Practice Assignment 3

Data Structures and Algorithms, Winter term 2018 Practice Assignment 3 German University in Cairo Media Engineering and Technology Prof. Dr. Slim Abdennadher Dr. Wael Abouelsaadat Data Structures and Algorithms, Winter term 2018 Practice Assignment 3 Exercise 3-1 Search in

More information

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

Nested Loops. A loop can be nested inside another loop. Nested Loops A loop can be nested inside another loop. Nested loops consist of an outer loop and one or more inner loops. Each time the outer loop is repeated, the inner loops are reentered, and started

More information

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

CS 201, Fall 2016 Oct 28th Exam 2. Question 1. [5 points] Consider the following static method: CS 201, Fall 2016 Oct 28th Exam 2 Name: Question 1. [5 points] Consider the following static method: public static int mystery(int[] arr) { int x = 0; for (int i = 0; i < arr.length; i++) { x += arr[i];

More information

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

Jump Statements. The keyword break and continue are often used in repetition structures to provide additional controls. Jump Statements The keyword break and continue are often used in repetition structures to provide additional controls. break: the loop is terminated right after a break statement is executed. continue:

More information

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

BSc. (Hons.) Software Engineering. Examinations for / Semester 2 BSc. (Hons.) Software Engineering Cohort: BSE/04/PT Examinations for 2005-2006 / Semester 2 MODULE: OBJECT ORIENTED PROGRAMMING MODULE CODE: BISE050 Duration: 2 Hours Reading Time: 5 Minutes Instructions

More information

CS 113 MIDTERM EXAM 2 SPRING 2013

CS 113 MIDTERM EXAM 2 SPRING 2013 CS 113 MIDTERM EXAM 2 SPRING 2013 There are 18 questions on this test. The value of each question is: 1-15 multiple choice (3 pts) 17 coding problem (15 pts) 16, 18 coding problems (20 pts) You may get

More information

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

COMP-202: Foundations of Programming. Lecture 8: for Loops, Nested Loops and Arrays Jackie Cheung, Winter 2016 COMP-202: Foundations of Programming Lecture 8: for Loops, Nested Loops and Arrays Jackie Cheung, Winter 2016 Review What is the difference between a while loop and an if statement? What is an off-by-one

More information

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

Exam 1 Prep. Dr. Demetrios Glinos University of Central Florida. COP3330 Object Oriented Programming Exam 1 Prep Dr. Demetrios Glinos University of Central Florida COP3330 Object Oriented Programming Progress Exam 1 is a Timed Webcourses Quiz You can find it from the "Assignments" link on Webcourses choose

More information

University of Waterloo CS240, Winter 2010 Assignment 2

University of Waterloo CS240, Winter 2010 Assignment 2 University of Waterloo CS240, Winter 2010 Assignment 2 Due Date: Wednesday, February 10, at 5:00pm Please read http://www.student.cs.uwaterloo.ca/~cs240/w10/guidelines.pdf for guidelines on submission.

More information

COS 126 Exam 2 Review Part 1

COS 126 Exam 2 Review Part 1 COS 126 Exam 2 Review Part 1 Programming Exam 2 Part 1 (ADT) Q. Can you implement a simple abstract data type? Example (Fall 2016). Part 1. Implement a data type ColorHSB.java for HSB colors. This time,

More information

Lab Exercise 1. Objectives: Part 1. Introduction

Lab Exercise 1. Objectives: Part 1. Introduction Objectives: king Saud University College of Computer &Information Science CSC111 Lab Object II All Sections - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

More information

Data Structures Brett Bernstein

Data Structures Brett Bernstein Data Structures Brett Bernstein Lecture 8: Iterators, Maps, and Hashtables Exercises 1. Show how to print out the elements of a doubly linked list in reverse order. 2. What are the Java API classes that

More information

CS2 Practical 1 CS2A 22/09/2004

CS2 Practical 1 CS2A 22/09/2004 CS2 Practical 1 Basic Java Programming The purpose of this practical is to re-enforce your Java programming abilities. The practical is based on material covered in CS1. It consists of ten simple programming

More information

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

Introduction to Algorithms October 12, 2005 Massachusetts Institute of Technology Professors Erik D. Demaine and Charles E. Leiserson Quiz 1. Introduction to Algorithms October 12, 2005 Massachusetts Institute of Technology 6.046J/18.410J Professors Erik D. Demaine and Charles E. Leiserson Quiz 1 Quiz 1 Do not open this quiz booklet until you

More information

Csci 102: Sample Exam

Csci 102: Sample Exam Csci 102: Sample Exam Duration: 65 minutes Name: NetID: Student to your left: Student to your right: DO NOT OPEN THIS EXAM UNTIL INSTRUCTED Instructions: Write your full name and your NetID on the front

More information

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

CS 455 Final Exam Spring 2018 [Bono] May 8, 2018 Name: USC NetID (e.g., ttrojan): CS 455 Final Exam Spring 2018 [Bono] May 8, 2018 There are 9 problems on the exam, with 74 points total available. There are 12 pages to the exam (6 pages double-sided),

More information

Control Flow: Loop Statements

Control Flow: Loop Statements Control Flow: Loop Statements A loop repeatedly executes a of sub-statements, called the loop body. Python provides two kinds of loop statements: a for-loop and a while-loop. This exercise gives you practice

More information

C22a: Problem Solving using Recursion

C22a: Problem Solving using Recursion CISC 3115 TY3 C22a: Problem Solving using Recursion Hui Chen Department of Computer & Information Science CUNY Brooklyn College 11/6/2018 CUNY Brooklyn College 1 Outline Characteristics of recursion Recursion

More information

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

The smallest element is the first one removed. (You could also define a largest-first-out priority queue) Priority Queues Priority queue A stack is first in, last out A queue is first in, first out A priority queue is least-first-out The smallest element is the first one removed (You could also define a largest-first-out

More information

CSE 143 SAMPLE MIDTERM

CSE 143 SAMPLE MIDTERM CSE 143 SAMPLE MIDTERM 1. (5 points) In some methods, you wrote code to check if a certain precondition was held. If the precondition did not hold, then you threw an exception. This leads to robust code

More information

Some Sample AP Computer Science A Questions - Solutions

Some Sample AP Computer Science A Questions - Solutions Some Sample AP Computer Science A Questions - s Note: These aren't from actual AP tests. I've created these questions based on looking at actual AP tests. Also, in cases where it's not necessary to have

More information

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

CS 261 Data Structures. Big-Oh Analysis: A Review CS 261 Data Structures Big-Oh Analysis: A Review Big-Oh: Purpose How can we characterize the runtime or space usage of an algorithm? We want a method that: doesn t depend upon hardware used (e.g., PC,

More information

CS 6353 Compiler Construction Project Assignments

CS 6353 Compiler Construction Project Assignments CS 6353 Compiler Construction Project Assignments In this project, you need to implement a compiler for a language defined in this handout. The programming language you need to use is C or C++ (and the

More information

COMPUTER SCIENCE. Paper 1

COMPUTER SCIENCE. Paper 1 COMPUTER SCIENCE Paper 1 (THEORY) Three hours (Candidates are allowed additional 15 minutes for only reading the paper. They must NOT start writing during this time) ----------------------------------------------------------------------------------------------------------------------------------

More information

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

Faculty of Science COMP-202A - Introduction to Computing I (Fall 2008) Midterm Examination First Name: Last Name: McGill ID: Section: Faculty of Science COMP-202A - Introduction to Computing I (Fall 2008) Midterm Examination Tuesday, November 4, 2008 Examiners: Mathieu Petitpas [Section 1] 18:30

More information

Arrays. Eng. Mohammed Abdualal

Arrays. Eng. Mohammed Abdualal Islamic University of Gaza Faculty of Engineering Computer Engineering Department Computer Programming Lab (ECOM 2114) Created by Eng: Mohammed Alokshiya Modified by Eng: Mohammed Abdualal Lab 9 Arrays

More information

2018 Pummill Relay problem statement

2018 Pummill Relay problem statement 2018 Pummill Relays CS Problem: Minimum Spanning Tree Missouri State University For information about the Pummill Relays CS Problem, please contact: KenVollmar@missouristate.edu, 417-836-5789 Suppose there

More information

Lecture 6: Divide-and-Conquer

Lecture 6: Divide-and-Conquer Lecture 6: Divide-and-Conquer COSC242: Algorithms and Data Structures Brendan McCane Department of Computer Science, University of Otago Types of Algorithms In COSC242, we will be looking at 3 general

More information

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

CSE 332 Spring 2013: Midterm Exam (closed book, closed notes, no calculators) Name: Email address: Quiz Section: CSE 332 Spring 2013: Midterm Exam (closed book, closed notes, no calculators) Instructions: Read the directions for each question carefully before answering. We will

More information

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

Outline. Parts 1 to 3 introduce and sketch out the ideas of OOP. Part 5 deals with these ideas in closer detail. OOP in Java 1 Outline 1. Getting started, primitive data types and control structures 2. Classes and objects 3. Extending classes 4. Using some standard packages 5. OOP revisited Parts 1 to 3 introduce

More information

Computer Science 1 Ah

Computer Science 1 Ah UNIVERSITY OF EDINBURGH course CS0077 COLLEGE OF SCIENCE AND ENGINEERING SCHOOL OF INFORMATICS Computer Science 1 Ah Resit Examination Specimen Solutions Date: Monday 1st September 2003 Time: 09:30 11:00

More information

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

ALGORITHM ANALYSIS. cs2420 Introduction to Algorithms and Data Structures Spring 2015 ALGORITHM ANALYSIS cs2420 Introduction to Algorithms and Data Structures Spring 2015 1 administrivia 2 -assignment 2 is due Friday at midnight -note change in due date, and time -tutoring experiment http://doodle.com/89cbb4u5n5acy9ag

More information

(Refer Slide Time: 1:27)

(Refer Slide Time: 1:27) Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi Lecture 1 Introduction to Data Structures and Algorithms Welcome to data

More information

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

CMPSCI 187: Programming With Data Structures. Lecture 12: Implementing Stacks With Linked Lists 5 October 2011 CMPSCI 187: Programming With Data Structures Lecture 12: Implementing Stacks With Linked Lists 5 October 2011 Implementing Stacks With Linked Lists Overview: The LinkedStack Class from L&C The Fields and

More information

Maps and Binary Search

Maps and Binary Search CITS2200 Data Structures and Algorithms Topic 10 Maps and Binary Search Definitions what is a map (or function)? Specification List-based representation (singly linked) Sorted block representation binary

More information

Name CIS 201 Midterm II: Chapters 1-8

Name CIS 201 Midterm II: Chapters 1-8 Name CIS 201 Midterm II: Chapters 1-8 December 15, 2010 Directions: This is a closed book, closed notes midterm. Place your answers in the space provided. The point value for each question is indicated.

More information

SOLUTIONS. COMP103 Introduction to Data Structures and Algorithms

SOLUTIONS. COMP103 Introduction to Data Structures and Algorithms T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I VUW V I C T O R I A UNIVERSITY OF WELLINGTON Student ID:....................... EXAMINATIONS 2011 MID YEAR COMP103 Introduction to Data

More information

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

Following is the general form of a typical decision making structure found in most of the programming languages: Decision Making Decision making structures have one or more conditions to be evaluated or tested by the program, along with a statement or statements that are to be executed if the condition is determined

More information

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

Computer Science 302 Spring 2018 Practice Examination for the Second Examination, Computer Science 302 Spring 2018 Practice Examination for the Second Examination, March 7, 2018 Name: No books, notes, or scratch paper. Use pen or pencil, any color. Use the rest of this page and the

More information

Repetition Algorithms

Repetition Algorithms Repetition Algorithms Repetition Allows a program to execute a set of instructions over and over. The term loop is a synonym for a repetition statement. A Repetition Example Suppose that you have been

More information

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

CSE373 Fall 2013, Final Examination December 10, 2013 Please do not turn the page until the bell rings. CSE373 Fall 2013, Final Examination December 10, 2013 Please do not turn the page until the bell rings. Rules: The exam is closed-book, closed-note, closed calculator, closed electronics. Please stop promptly

More information

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

(f) Given what we know about linked lists and arrays, when would we choose to use one data structure over the other? CSM B Hashing & Heaps Spring 0 Week 0: March 0, 0 Motivation. (a) In the worst case, how long does it take to index into a linked list? Θ(N) (b) In the worst case, how long does it take to index into an

More information

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

1.00 Introduction to Computers and Engineering Problem Solving. Quiz 1 March 7, 2003 1.00 Introduction to Computers and Engineering Problem Solving Quiz 1 March 7, 2003 Name: Email Address: TA: Section: You have 90 minutes to complete this exam. For coding questions, you do not need to

More information

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

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

More information

H212 Introduction to Software Systems Honors

H212 Introduction to Software Systems Honors Introduction to Software Systems Honors Lecture #04: Fall 2015 1/20 Office hours Monday, Wednesday: 10:15 am to 12:00 noon Tuesday, Thursday: 2:00 to 3:45 pm Office: Lindley Hall, Room 401C 2/20 Printing

More information

CS 367: Introduction to Data Structures Midterm Sample Questions

CS 367: Introduction to Data Structures Midterm Sample Questions LAST NAME (PRINT): FIRST NAME (PRINT): CS 367: Introduction to Data Structures Midterm Sample Questions Friday, July 14 th 2017. 100 points (26% of final grade) Instructor: Meena Syamkumar 1. Fill in these

More information

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

Admin. CS 112 Introduction to Programming. Counting Down: Code Puzzle. Counting Down: Code Puzzle Admin CS 112 Introduction to Programming Variable Scoping; Nested Loops; Parameterized Methods Yang (Richard) Yang Computer Science Department Yale University 308A Watson, Phone: 432-6400 Email: yry@cs.yale.edu

More information

CSE332 Summer 2010: Final Exam

CSE332 Summer 2010: Final Exam CSE332 Summer 2010: Final Exam Closed notes, closed book; calculator ok. Read the instructions for each problem carefully before answering. Problems vary in point-values, difficulty and length, so you

More information

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

COMP-202: Foundations of Programming. Lecture 3: Boolean, Mathematical Expressions, and Flow Control Sandeep Manjanna, Summer 2015 COMP-202: Foundations of Programming Lecture 3: Boolean, Mathematical Expressions, and Flow Control Sandeep Manjanna, Summer 2015 Announcements Slides will be posted before the class. There might be few

More information

Priority queues. Priority queues. Priority queue operations

Priority queues. Priority queues. Priority queue operations Priority queues March 30, 018 1 Priority queues The ADT priority queue stores arbitrary objects with priorities. An object with the highest priority gets served first. Objects with priorities are defined

More information

CSE505, Fall 2012, Midterm Examination October 30, 2012

CSE505, Fall 2012, Midterm Examination October 30, 2012 CSE505, Fall 2012, Midterm Examination October 30, 2012 Rules: The exam is closed-book, closed-notes, except for one side of one 8.5x11in piece of paper. Please stop promptly at Noon. You can rip apart

More information

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

Data Structures. Alice E. Fischer. Lecture 4, Fall Alice E. Fischer Data Structures L4... 1/19 Lecture 4, Fall / 19 Data Structures Alice E. Fischer Lecture 4, Fall 2018 Alice E. Fischer Data Structures L4... 1/19 Lecture 4, Fall 2018 1 / 19 Outline 1 Ordered Lists 2 Sorted Lists Tail Pointers 3 Doubly Linked Lists

More information

CSE 247 Data Structures and Algorithms Fall Exam I

CSE 247 Data Structures and Algorithms Fall Exam I CSE 247 Data Structures and Algorithms Fall 2016 Given: 29 February 2016 Exam I Due: End of session This exam is closed-book, closed-notes. No electronic devices or resources of any kind are allowed. The

More information

Question: Total Points: Score:

Question: Total Points: Score: CS 170 Exam 2 Section 002 Fall 2013 Name (print): Instructions: Keep your eyes on your own paper and do your best to prevent anyone else from seeing your work. Do NOT communicate with anyone other than

More information

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

Cosc 241 Programming and Problem Solving Lecture 17 (30/4/18) Quicksort 1 Cosc 241 Programming and Problem Solving Lecture 17 (30/4/18) Quicksort Michael Albert michael.albert@cs.otago.ac.nz Keywords: sorting, quicksort The limits of sorting performance Algorithms which sort

More information

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

CSCI 135 Exam #0 Fundamentals of Computer Science I Fall 2012 CSCI 135 Exam #0 Fundamentals of Computer Science I Fall 2012 Name: This exam consists of 7 problems on the following 6 pages. You may use your single- side hand- written 8 ½ x 11 note sheet during the

More information

CIS 110 Introduction to Computer Programming 8 October 2013 Midterm

CIS 110 Introduction to Computer Programming 8 October 2013 Midterm CIS 110 Introduction to Computer Programming 8 October 2013 Midterm Name: Recitation # (e.g., 201): Pennkey (e.g., eeaton): My signature below certifies that I have complied with the University of Pennsylvania

More information

Question: Total Points: Score:

Question: Total Points: Score: CS 170 Exam 2 Section 001 Fall 2014 Name (print): Instructions: Keep your eyes on your own paper and do your best to prevent anyone else from seeing your work. Do NOT communicate with anyone other than

More information

CS 314 Midterm 2 Fall 2012

CS 314 Midterm 2 Fall 2012 Points off 1 2 3 4 5 Total off Net Score CS 314 Midterm 2 Fall 2012 Your Name_ Your UTEID Circle yours TA s name: John Zihao Instructions: 1. There are 5 questions on this test. 2. You have 2 hours to

More information

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

Exam 2. Programming I (CPCS 202) Instructor: M. G. Abbas Malik. Total Marks: 40 Obtained Marks: كلية الحاسبات وتقنية المعلوما Exam 2 Programming I (CPCS 202) Instructor: M. G. Abbas Malik Date: November 22, 2015 Student Name: Student ID: Total Marks: 40 Obtained Marks: Instructions: Do not open this

More information

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

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University CS 112 Introduction to Computing II Wayne Snyder Department Boston University Today Recursive Sorting Methods and their Complexity: Mergesort Conclusions on sorting algorithms and complexity Next Time:

More information