CS 112 Midterm. 1. The assignment double x = (double) 4; is an example of a narrowing conversion.

Similar documents
Questions 1 through 25 are worth 2 points each. Choose one best answer for each.

AP Computer Science Java Mr. Clausen Program 9A, 9B

Sample CSE8A midterm Multiple Choice (circle one)

You are to simulate the process by making a record of the balls chosen, in the sequence in which they are chosen. Typical output for a run would be:

QUEUES. Primitive Queue operations. enqueue (q, x): inserts item x at the rear of the queue q

1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

1. The memory address of the first element of an array is called A. floor address B. foundation addressc. first address D.

CompuScholar, Inc. Alignment to Utah's Computer Programming II Standards

CSC148 Lecture 8. Algorithm Analysis Binary Search Sorting

CompSci-61B, Data Structures Final Exam

Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language

A TOOL FOR DATA STRUCTURE VISUALIZATION AND USER-DEFINED ALGORITHM ANIMATION

1) Which of the following is a constant, according to Java naming conventions? a. PI b. Test c. x d. radius

Masters programmes in Computer Science and Information Systems. Object-Oriented Design and Programming. Sample module entry test xxth December 2013

Class Overview. CSE 326: Data Structures. Goals. Goals. Data Structures. Goals. Introduction

Basic Programming and PC Skills: Basic Programming and PC Skills:

CSE373: Data Structures and Algorithms Lecture 3: Math Review; Algorithm Analysis. Linda Shapiro Winter 2015

CSE 2123 Collections: Sets and Iterators (Hash functions and Trees) Jeremy Morris

J a v a Quiz (Unit 3, Test 0 Practice)

Introduction to Programming System Design. CSCI 455x (4 Units)

Introduction to Java

The Tower of Hanoi. Recursion Solution. Recursive Function. Time Complexity. Recursive Thinking. Why Recursion? n! = n* (n-1)!

Data Structures. Level 6 C Module Descriptor

CmpSci 187: Programming with Data Structures Spring 2015

Linked Lists, Stacks, Queues, Deques. It s time for a chainge!

DATA STRUCTURES USING C

1.00 Lecture 1. Course information Course staff (TA, instructor names on syllabus/faq): 2 instructors, 4 TAs, 2 Lab TAs, graders

Arrays. Atul Prakash Readings: Chapter 10, Downey Sun s Java tutorial on Arrays:

Dalhousie University CSCI 2132 Software Development Winter 2015 Lab 7, March 11

CSE 326, Data Structures. Sample Final Exam. Problem Max Points Score 1 14 (2x7) 2 18 (3x6) Total 92.

Symbol Tables. Introduction

22c:31 Algorithms. Ch3: Data Structures. Hantao Zhang Computer Science Department

This lecture. Abstract data types Stacks Queues. ADTs, Stacks, Queues Goodrich, Tamassia

Data Structures and Algorithms Written Examination

Introduction to Object-Oriented Programming

Introduction to Programming

Data Structures in the Java API

Graduate Assessment Test (Sample)

Introduction to Data Structures

Algorithms. Margaret M. Fleck. 18 October 2010

Chapter 3: Restricted Structures Page 1

Linked Lists Linked Lists, Queues, and Stacks

10CS35: Data Structures Using C

Using Files as Input/Output in Java 5.0 Applications

System.out.println("\nEnter Product Number 1-5 (0 to stop and view summary) :

Java Software Structures

AP Computer Science Static Methods, Strings, User Input

Algorithms and Data Structures Written Exam Proposed SOLUTION

Sorting revisited. Build the binary search tree: O(n^2) Traverse the binary tree: O(n) Total: O(n^2) + O(n) = O(n^2)

Analysis of a Search Algorithm

Section 6 Spring 2013

Practical Session 4 Java Collections

MIDTERM 1 REVIEW WRITING CODE POSSIBLE SOLUTION

CHAPTER 4 ESSENTIAL DATA STRUCTRURES

LINKED DATA STRUCTURES

API for java.util.iterator. ! hasnext() Are there more items in the list? ! next() Return the next item in the list.

Java Basics: Data Types, Variables, and Loops

St S a t ck a ck nd Qu Q eue 1

Collections in Java. Arrays. Iterators. Collections (also called containers) Has special language support. Iterator (i) Collection (i) Set (i),

Moving from CS 61A Scheme to CS 61B Java

Sorting Algorithms. Nelson Padua-Perez Bill Pugh. Department of Computer Science University of Maryland, College Park

BSc (Hons) Business Information Systems, BSc (Hons) Computer Science with Network Security. & BSc. (Hons.) Software Engineering

16. Recursion. COMP 110 Prasun Dewan 1. Developing a Recursive Solution

Building Java Programs

COMPUTER SCIENCE. Paper 1 (THEORY)

AP Computer Science AB Syllabus 1

1.00 Lecture 35. Data Structures: Introduction Stacks, Queues. Reading for next time: Big Java: Data Structures

Sample Questions Csci 1112 A. Bellaachia

Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007

Building Java Programs

UIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming

PES Institute of Technology-BSC QUESTION BANK

Master of Sciences in Informatics Engineering Programming Paradigms 2005/2006. Final Examination. January 24 th, 2006

Last not not Last Last Next! Next! Line Line Forms Forms Here Here Last In, First Out Last In, First Out not Last Next! Call stack: Worst line ever!

Mobile App Design Project #1 Java Boot Camp: Design Model for Chutes and Ladders Board Game

Data Structures and Data Manipulation

Java Cheatsheet. Tim Coppieters Laure Philips Elisa Gonzalez Boix

Chapter 7: Sequential Data Structures

Exam study sheet for CS2711. List of topics

cs2010: algorithms and data structures

Part I. Multiple Choice Questions (2 points each):

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

Introduction to Java. CS 3: Computer Programming in Java

Binary Heap Algorithms

Common Data Structures

Functions Recursion. C++ functions. Declare/prototype. Define. Call. int myfunction (int ); int myfunction (int x){ int y = x*x; return y; }

Data Structure and Algorithm I Midterm Examination 120 points Time: 9:10am-12:10pm (180 minutes), Friday, November 12, 2010

COSC Introduction to Computer Science I Section A, Summer Question Out of Mark A Total 16. B-1 7 B-2 4 B-3 4 B-4 4 B Total 19

D06 PROGRAMMING with JAVA

Data Structures and Algorithms Stacks and Queues

Unit 6. Loop statements

Software Engineering Techniques

Converting a Number from Decimal to Binary

Java Coding Practices for Improved Application Performance

dictionary find definition word definition book index find relevant pages term list of page numbers

Queues Outline and Required Reading: Queues ( 4.2 except 4.2.4) COSC 2011, Fall 2003, Section A Instructor: N. Vlajic

Software Testing. Definition: Testing is a process of executing a program with data, with the sole intention of finding errors in the program.

AP Computer Science Java Subset

Transcription:

Name: Solution Key CS 112 Midterm There are 7 problems on the exam. The first and last are mandatory, and you may eliminate any one of problems 2 6 by drawing an X through it. Problem 1 is worth 10 points, and all other problems are worth 18. Please write in pen if possible. If you need more room, use the back of the sheet and tell me this on the front sheet of that problem. Problem 1 (10 pts -- Mandatory). (/) Write or to the LEFT of the statement. 1. The assignment double x = (double) 4; is an example of a narrowing conversion. 2. In the boolean expression ( A && B ), if the expression A evaluates to true, the second expression B will not be evaluated. 3. The break statement quits the current iteration of a loop and starts the next one. 4. Local variables in a class can never be defined as public. 5. Generic classes in Java can only be instantiated by reference types. 6. From the point of view of Θ(...) complexity, the worst-case complexity of inserting a new element into an array is the same whether it is ordered or unordered. 7. If f(n) = ~ g(n) then it must be the case that f(n) = Θ(g(n)). 8. The average case complexity of an algorithm can never be worse (i.e., take longer) than the worst-case complexity. 9. The scope of a member of a class is the same whether it is declared static or not static. 10. Strings in Java are immutable, that is, you can not change the characters in a String once you have created it.

Problem 4. Suppose you have a stack for integers with the normal push() and pop() operations. Now suppose you have a sequence of push(...) and pop() operations in the following form: push( 0 ); push( 1 ); push( 2 ); etc. push( 9 ); That is, you push the digits 0... 9 in order, and then before, in between, and after these pushes, you do some number of pops (possibly 0). Which of the following sequences could possibly be printed out by such a sequence (there may be more than one)? Write possible or not possible next to each one. (A) 4 6 8 7 5 3 2 9 0 1 NOT! (B) 8 7 6 5 4 3 2 1 0 9 (C) 4 3 2 1 0 5 6 7 8 9 (D) 9 8 7 6 5 4 3 2 1 0

Problem 5. For each function f from the following list of functions, determine the simplest function g that makes the equality f(n) = ϴ(g(N)) true. Represent your answer as an equality (e.g., p(n) = ϴ(N 2 )). The first one is done for you as a model for the rest of your answers. a(n) = 2 N + N 2 5 a(n) = ϴ(2 N ) b(n) = log(n 3 ) + log(2n) b(n) = ϴ( log(n) ) c(n) = 8N + 5*sqrt(N) c(n) = ϴ( N ) d(n) = 12N + N* sqrt(n) + N*log(N) d(n) = ϴ( N 1.5 ) e(n) = log 3 (N) + log(n) + 5 e(n) = ϴ( log 3 (N) ) f(n) = 50 +!! f(n) = ϴ( 1 )

Problem 6. This is a question about Java and has two parts. (A) What is the output of the following lines of Java code? int a = 9; double b = a / 2.0; int c = a / 2; double d = a / 2; String e = c + "c"; a = a % 6; System.out.println("a = " + a); a = 3 System.out.println("b = " + b); b = 4.5 System.out.println("c = " + c); c = 4 System.out.println("d = " + d); d = 4.0 System.out.println("e = " + e); e = 4c (B) Consider the program shown below. public class Problem3 { public static void main(string[] args) { int g = 1; if (g > 0) { int h = foo(g); System.out.println( ); // blank for part a public static int foo(int r) { int s; for (s = 0; s < 5; s++) { System.out.println("bar"); return ; // blank for part b a. Which of the variables (g, h, r, s) could be used in the first blank? g b. Which of the variables (g, h, r, s) could be used in the second blank? r, s

Problem 7. (MANDATORY) For the following algorithms, for the first set, state the worst-case and average-case time (in terms of Θ ) for performing the indicating operation. For the second set, simply give the Θ(...N...) estimate for the indicated situation. The number of items stored in each data structure is N. Assume for each row that you are using the algorithms we discussed in class. Algorithm Worst Case Θ(...) Average Case Θ(...) Find an element in an unordered array. Θ( N ) Θ( N ) Delete an element from an ordered array. Θ( N ) Θ( N ) Dequeue a key from a queue implemented as a ring buffer with resizing Enqueue a key into a queue implemented as a ring buffer with resizing Θ( 1 ) Θ( 1 ) Θ( N ) Θ( N ) Find an element in an ordered array. Θ( log(n) ) Θ( log(n) ) Partition (as in Quicksort) a array of size N. Θ( N ) Θ( N ) Merge two ordered lists, each of size N/2. Θ( N ) Θ( N ) Algorithm and Data Input Θ(...) using Selection Sort Θ( N 2 ) using Insertion Sort Θ( N ) using Mergesort Θ( N log(n) ) using Quicksort Θ( N 2 )