# JAVA NOTES DATA STRUCTURES AND ALGORITHMS

Save this PDF as:

Size: px
Start display at page:

## Transcription

1 15 JAVA NOTES DATA STRUCTURES AND ALGORITHMS Terry Marris July LINEAR SEARCH 3.1 LEARNING OUTCOMES By the end of this lesson the student should be able to describe how a linear search algorithm works implement and test a linear search algorithm 3.2 INTRODUCTION We search through a collection of objects, looking for one object in particular. A search always has one of two outcomes: either success - we have found what we are looking for, or failure - we have not found what we are looking for. An algorithm is a sequence of statements to accomplish some task. We shall describe the linear search algorithm. The search is described as linear because we are, in affect, looking along a line of objects until either we find the one we are looking for, or we reach the end of the line. Smith Kline French Patel Singh look here move along the line until either you find what you want or you reach the end of the line and can look no further

2 LINEAR SEARCH We shall create the following To test the search algorithm we shall (a) look for the first item in the - 13 (b) look for the last item in the - 15 (c) look for an item not in the - 23 The first and last items in an represent its boundaries and therefore should always feature in any testing we do. Here is the Java code fragment to create the. final int capacity = 5; // indexed 0..4 Integer[] = new Integer[capacity]; [0] = new Integer(13); [1] = new Integer(19); [2] = new Integer(11); [3] = new Integer(17); [4] = new Integer(15); We fill the with Integer objects rather than int values because we want our search algorithm to work with any kind of object.

3 17 We display the contents of the so that we can see that it contains exactly what we think it contains. System.out.println("The contains"); String string = "[ "; for (int i = 0; i <.length; i++) { string += [i]; if (i + 1 <.length) string += ", "; string += " ]"; System.out.println(string); There are two things to notice here. First, the number of elements in the is represented by.length. length is not a method (it has no brackets); rather it is a public data field belonging to the. Second, we are assuming that the objects have a tostring() method. Now onto the linear search algorithm itself. public static String search(object[], Object tofind) { for (int i = 0; i <.length; i++) { if ([i].equals(tofind)) return "success"; return "failure"; We pass an and the object we are trying to find into the parameters and tofind. We set up an index, i, to look at each element in the in turn. If in some location i in the we find that its contents equal the object we are looking for, we return success. If we reach the end of the and have not yet found what we are looking for, it must be because it is not there; we return failure. There are three things to notice here. The linear search algorithm requires objects to have their own equals() method. The algorithm is both public and static. If the contains duplicate objects equal to the given object, it is the first object that is found.

4 18 Now for the testing. System.out.println("Searching for " + search(, new Integer(13))); System.out.println("Searching for " + search(, new Integer(15))); System.out.println("Searching for " + search(, new Integer(23))); We pass the and the object we are searching for as argument values to the search algorithm. search(, new Integer(13))); We display the value, success or failure, returned by search(). System.out.println(search(, new Integer(13))); The results of the tests are shown below. Searching for success Searching for success Searching for failure Here is the complete program.

5 19 /* LinearSearch.java Terry Marris 20 July 2001 */ public class LinearSearch { public static String search(object[], Object tofind) { for (int i = 0; i <.length; i++) { if ([i].equals(tofind)) return "success"; return "failure"; public static void main(string[] s) { final int capacity = 5; // indexed 0..4 Integer[] = new Integer[capacity]; [0] = new Integer(13); [1] = new Integer(19); [2] = new Integer(11); [3] = new Integer(17); [4] = new Integer(15); System.out.println("The contains"); String string = "[ "; for (int i = 0; i <.length; i++) { string += [i]; if (i + 1 <.length) string += ", "; string += " ]"; System.out.println(string); System.out.println("Searching for " + search(, new Integer(13))); System.out.println("Searching for " + search(, new Integer(15))); System.out.println("Searching for " + search(, new Integer(23))); The contains[ 13, 19, 11, 17, 15 ] Searching for success Searching for success Searching for failure

6 REVIEW 3.5 FURTHER READING In the next lesson we look at sorting.

7 EXERCISES 1 Explain what is meant by searching. State the two possible outcomes of any search operation. 2 Dry run the linear search algorithm two times (a) when tofind = 11 (b) when tofind = 10 (a) is started for you. tofind i i<.length tofind.equals([i]) 11 0 true false i = 0 return 2 Re-write the linear search(object [], Object) algorithm described in 3.3 above so that it returns the index where the given object is located in the given, or -1 if the does not contain the object. Test your amendments.

### COUNTING LOOPS AND ACCUMULATORS

COUNTING LOOPS AND ACCUMULATORS Two very important looping idioms are counting loops and accumulators. A counting loop uses a variable, called the loop control variable, to keep count of how many cycles

### int w = (x + x)*y - y; System.out.println("The value of w is " + w); z = w + 3; System.out.println("The value of z is now " + z);

MIT AITI Mobile Application Development in Java Lab 02: Java Basics Instructions on how to submit Lab 2 will be presented on the screen. Please follow instructions and if they are unclear, please feel

### SEARCHING AND SORTING

SEARCHING AND SORTING Searching A basic operation in computer science Problem formulation Given: Collection (array) of values A property on values Find: a value having the property in the array Examples

### Searching Algorithms

Searching Algorithms The Search Problem Problem Statement: Given a set of data e.g., int [] arr = {10, 2, 7, 9, 7, 4}; and a particular value, e.g., int val = 7; Find the first index of the value in the

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

AP Computer Science Java Mr. Clausen Program 9A, 9B PROGRAM 9A I m_sort_of_searching (20 points now, 60 points when all parts are finished) The purpose of this project is to set up a program that will

### Computing Science 114 Solutions to Final Examination Tuesday December 14, 2004

Computing Science 114 Solutions to Final Examination Tuesday December 14, 2004 INSTRUCTOR: I. E. LEONARD TIME: 3 HOURS Question 1. [10 = 5 + 5 pts] An operator is said to be overloaded when it is used

### Classes and Objects in Java Constructors. In creating objects of the type Fraction, we have used statements similar to the following:

In creating objects of the type, we have used statements similar to the following: f = new (); The parentheses in the expression () makes it look like a method, yet we never created such a method in our

### Searching and Sorting

Linear Search Searching and Sorting Binary Search Selection Sort Insertion Sort Bubble (or Exchange) Sort Exercises Unit 27 1 Linear Search Searching is the process of determining whether or not a given

### ASSIGNMENT 4 Strings, Classes, Methods, and Numbers

ASSIGNMENT 4 Strings, Classes, Methods, and Numbers COMP-202B, Winter 2009, All Sections Due: Tuesday, March 31, 2009 (23:55) You MUST do this assignment individually and, unless otherwise specified, you

### Mock exam 1 for SCJP 6

Mock exam 1 for SCJP 6 The sample test is modeled on the Sun Certification for Java TM 6 Programmer exam. The test has 50 questions and needs to be executed in 2 hours. The real exam may be a little tougher

### Software and Programming 1

Software and Programming 1 Lab 3: Strings & Conditional Statements 20 January 2016 SP1-Lab3.ppt Tobi Brodie (Tobi@dcs.bbk.ac.uk) 1 Lab Objectives This session we are concentrating on Strings and conditional

### Introduction to Programming

Introduction to Programming Lecturer: Steve Maybank Department of Computer Science and Information Systems sjmaybank@dcs.bbk.ac.uk Spring 2015 Week 2b: Review of Week 1, Variables 16 January 2015 Birkbeck

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

Computer Science S-111a: Intensive Introduction to Computer Science Using Java Handout #11 Your Name Teaching Fellow J a v a Quiz (Unit 3, Test 0 Practice) Multiple-choice questions are worth 2 points

### 1.2 Built-in Types of Data

1.2 Built-in Types of Data Introduction to Programming in Java: An Interdisciplinary Approach Robert Sedgewick and Kevin Wayne Copyright 2002 2010 1/29/11 6:40 AM! Built-in Data Types Data type. A set

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

Programming Concepts Practice Test 1 1) Which of the following is a constant, according to Java naming conventions? a. PI b. Test c. x d. radius 2) Consider the following statement: System.out.println("1

### Flow of Control. Conditional Statements. Boolean Expressions. CMPT 125: Lecture 4 Conditionals and Loops

Flow of Control CMPT 125: Lecture 4 Conditionals and Loops Tamara Smyth, tamaras@cs.sfu.ca School of Computing Science, Simon Fraser University January 17, 2009 The order in which statements are executed

### The Sequential Search (Linear Search) Mr. Dave Clausen La Cañada High School

The Sequential Search (Linear Search) Mr. Dave Clausen La Cañada High School The Sequential Search Description The Sequential (or Linear) Search examines the first element in the list and then examines

### Computer & Programming I Quiz #5 Dr. H. Assadipour 1. What is the output of the following program?

Computer & Programming I Quiz #5 Dr. H. Assadipour 1. What is the output of the following program? Driver Program public class ThingTester public static void main (String[] args) Thing one = new Thing();

### Introduction to Java Unit 6. Exercises: Arrays

Introduction to Java Unit 6. Exercises: Arrays 1. What is displayed? int [] cosmic = { 3, 6, 5, 8 ; System.out.println( cosmic[ 2 ] ); 2. What is displayed? String [] gamma = { "do", "re", "mi" ; System.out.println(

### Program Elements. Notes. Exercises CHAPTER 3

CHAPTER 3 Program Elements Notes Chapter 3 introduces the program elements that are the underlying constructs used inside an object to define the services it contributes to a program. Without these constructs,

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

Translation Translating to Java Introduction to Computer Programming The job of a programmer is to translate a problem description into a computer language. You need to be able to convert a problem description

### ASSIGNMENT 3 Methods, Arrays, and the Java Standard Class Library

ASSIGNMENT 3 Methods, Arrays, and the Java Standard Class Library COMP-202B, Winter 2010, All Sections Due: Wednesday, March 3, 2010 (23:55) You MUST do this assignment individually and, unless otherwise

### Scanner. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit.

Scanner The Scanner class is intended to be used for input. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit. For example, suppose the input

### In the example above, it is as though the elements are in two-dimensions such a table

2 1 3 2 4 4 5 5 6 6 7 8 9 10 11 12 13 Multiple-Dimensional Arrays Elements of arrays may have more than one index, i.e. In example above, it is as though elements are in two-dimensions such a table with

### Introduction to Object-Oriented Programming

Introduction to Object-Oriented Programming Programs and Methods Christopher Simpkins chris.simpkins@gatech.edu CS 1331 (Georgia Tech) Programs and Methods 1 / 8 The Anatomy of a Java Program It is customary

### (e) none of the above.

1 The default value of a static integer variable of a class in Java is, (a) 0 (b) 1 (c) Garbage value (d) Null (e) -1 2 What will be printed as the output of the following program? public class testincr

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

Mobile App Design Project #1 Java Boot Camp: Design Model for Chutes and Ladders Board Game Directions: In mobile Applications the Control Model View model works to divide the work within an application.

### CSCE 111 Exam 1 TRUE/FALSE

CSCE 111 Exam 1 FORM B TRUE/FALSE 1. Java runs differently on different CPU architectures. F 2. A declared variable is always visible to the entire method in which it is declared. F 3. Because the operator

### 2! Multimedia Programming with! Python and SDL

2 Multimedia Programming with Python and SDL 2.1 Introduction to Python 2.2 SDL/Pygame: Multimedia/Game Frameworks for Python Literature: G. van Rossum and F. L. Drake, Jr., An Introduction to Python -

### TRUE / FALSE MULTIPLE CHOICE

CS 111 Exam 3 FORM A TRUE / FALSE 1. If you write a tostring method for a class, it can be invoked automatically to output the string generated by that method. T 2. You can change the contents of a String

### Above is an example of a decision structure (conditional control structure) that executes a set of statements when a condition is true.

Visual Basic Chapter 4 Controlling Program flow with Decision Structures If condition Then End if Above is an example of a decision structure (conditional control structure) that executes a set of statements

### 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:

Lecture 7 Picking Balls From an Urn The problem: An urn has n (n = 10) balls numbered from 0 to 9 A ball is selected at random, its' is number noted, it is set aside, and another ball is selected from

### School of Informatics, University of Edinburgh Computer Science 1 Ah [03 04]

School of Informatics, University of Edinburgh Computer Science 1 Ah [03 04] CS1Ah Lecture Note 25 Binary Search Trees This lecture studies binary trees in more detail, in particular their application

### Lab Manual. CPCS204 Data Structures 1. Lab /1436H

KING ABDULAZIZ UNIVERSITY Faculty of Computing & Information Technology Department of Computer Science Lab Manual CPCS204 Data Structures 1 1435/1436H Lab - 3 Learning Procedure 1) Stage J (Journey inside-out

### AP Computer Science II Java Unit Lab Assignment # 26b

AP Computer Science II Java Unit Lab Assignment # 26b The "Knight's Tour" Program 90 & 100 Point Versions Assignment Purpose: The purpose of this assignment is to review and practice Java program coding

### Arrays - Introduction. Declaration of Arrays. Initialisation of Arrays. Creation of Arrays. Arrays, Strings and Collections [1]

Arrays - Introduction Arrays, Strings and Collections [] Rajkumar Buyya Grid Computing and Distributed Systems (GRIDS) Laboratory Dept. of Computer Science and Software Engineering University of Melbourne,

### Java Programming Language Basic Java Concepts Sample Java Program

1 Java Programming Language Basic Java Concepts Sample Java Program 2 Java Why is it special? An object-oriented programming language. (More about this later.) Developed in early 1990's by James Gosling

### Chapter 7 Multidimensional Arrays

Chapter 7 Multidimensional Arrays 7.1 Introduction Thus far, you have used one-dimensional arrays to model linear collections of elements. You can use a two-dimensional array to represent a matrix or a

### INTI COLLEGE MALAYSIA

CSC112 (F) / Page 1 of 5 INTI COLLEGE MALAYSIA CERTIFICATE IN COMPUTING AND INFORMATION TECHNOLOGY PROGRAMME CSC 112 : FUNDAMENTALS OF PROGRAMMING FINAL EXAMINATION : DECEMBER 2002 SESSION This paper consists

### CMPU102: Exam 1 Solutions Spring 2005

CMPU102: Exam 1 Solutions Spring 2005 1. Consider the following statements: int a = 4; int b = 7; b *= a; What are the resulting values of a and b? a = 4 b = 28 2. Consider the following statements: int

### Question 1 Multiple Answer Points

Page 1 of 7 Name: Questions Description: Instructions: Question 1 Multiple Answer Points Question: What are the two parts of a value of type double? significant digits length exponent mode numerator denominator

### Strings in Java and.net Venkat Subramaniam

Strings in Java and.net Venkat Subramaniam venkats@durasoftcorp.com http://www.durasoftcorp.com/download Abstract Strings are one of the most basic data types in a language, yet they have been treated

### Chapter 22. Working with Arrays Sorting Arrays

265 Chapter 22 Working with Arrays This chapter introduces fundamental algorithms for arrays sorting and searching and then finishes with a sample application that uses arrays. 22.1 Sorting Arrays Array

### Fundamentals of Programming. Laboratory 5 Methods. General-purpose and user - defined methods

Fundamentals of Programming Laboratory 5 Methods. General-purpose and user - defined methods What is a method? Block of code that receives its own identifier - i.e. can be executed using its name Different

### Stacks. Linear data structures

Stacks Linear data structures Collection of components that can be arranged as a straight line Data structure grows or shrinks as we add or remove objects ADTs provide an abstract layer for various operations

Graduate Assessment Test (Sample) CS201-203 1. Fibonacci sequence is defined by a recurrence relation. The series is: 0,1,1,2,3,5,8,13,... Write a complete recursive method/function that returns the fibonacci

### ADTs and Modules in Java and C

CMPS 101 Algorithms and Abstract Data Types ADTs and Modules in Java and C Introduction This document introduces the concepts of Modules and ADTs, and describes how to implement them in both Java and C.

### Introduction to Search Algorithms

Chapter 9: Searching, Sorting Introduction to Search Algorithms Search: locate an item in a list (array, vector, etc.) of information Two algorithms (methods) considered here: Linear search Binary search

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

Oct 4, 2013, p 1 Name: CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013 1. (max 18) 4. (max 16) 2. (max 12) 5. (max 12) 3. (max 24) 6. (max 18) Total: (max 100)

### Looping Exercises Deciding Which Loop to Use

Looping Exercises Deciding Which Loop to Use At this time you have learned four looping constructs (also called repetition statements). Each of these four loops are ideal to use in different situations.

### CISC 213- Practice Test 2

CISC 213- Practice Test 2 Part A- The following questions are multiple choice or short answer: 1. Say we define a class called ABC and we don't define any constructor. Then which of the following is true:

### Which one of the following options is a valid line of code for displaying the twenty-eighth element of somearray?

2 Points / Question 1) Consider the following line of code: int[] somearray = new int[30]; Which one of the following options is a valid line of code for displaying the twenty-eighth element of somearray?

### modifier returnvaluetype methodname(list of parameters) { // Method body; }

JAVA METHODS METHODS A Java method is similar to function in C/C++. It is a collection of statements that are grouped together to perform an operation. When you call the System.out.println method, for

### 3.1 Algorithms. Pseudocode. Searching Algorithms.

3.1 Algorithms. Pseudocode. Searching Algorithms. Outline: What is an Algorithm? Pseudocode Search Problems Sorting Problems (next) 1 3.1 Algorithms. Pseudocode. Searching Algorithms. Examples of Mathematical

### Array-Based Lists. Lists

Array-Based Lists Collections and ArrayIntList Reading: RS Ch. 15 slides created by Marty Stepp http://www.cs.washington.edu/143/ Modified by Sarah Heckman Lists list: a collection storing an ordered sequence

### Topics. Introduction to Arrays. Topics. Creating Arrays. Creating Arrays CS 146. Introduction to Programming and Algorithms Module 7

Introduction to Programming and Algorithms Module 7 CS 146 Sam Houston State University Dr. Tim McGuire Topics Module 7 discusses the following main topics: Introduction to Arrays Processing Array Contents

### Recursion, Search, Selection. Cheng, Wei COMP June 12, Title

Recursion, Search, Selection Cheng, Wei COMP110-001 June 12, 2014 Title Today Introduction to Recursion Introduction to Search & Selection Not a major focus of the final exam But you should be able to

### Ch 7 Designing Java Classes & Class structure. Methods: constructors, getters, setters, other e.g. getfirstname(), setfirstname(), equals()

Ch 7 Designing Java Classes & Class structure Classes comprise fields and methods Fields: Things that describe the class or describe instances (i.e. objects) e.g. last student number assigned, first name,

Hazırlayan Yard. Doç. Dr. Mehmet Fidan SUMMARY: INDEX NUMBERS int[] day = new int[7]; day[0] day[1] day[2] day[3] day[4] day[5] day[6] 2 6 6 4 12 54-10 Examples: day[5] = 1; if( day[5] == 4 ) break; day[5]

### This document shows how to use BlueJ to debug a Java program. We will use the SyllableCounter program in Chapter 6 as example.

This document shows how to use BlueJ to debug a Java program. We will use the SyllableCounter program in Chapter 6 as example. Let s first execute the program to see that there are bugs in the program.

### JAVA ARRAY EXAMPLE PDF

JAVA ARRAY EXAMPLE PDF Created By: Umar Farooque Khan 1 Java array example for interview pdf Program No: 01 Print Java Array Example using for loop package ptutorial; public class PrintArray { public static

### Searching & Sorting. Searching & Sorting 1

Searching & Sorting Searching & Sorting 1 The Plan Searching Sorting Java Context Searching & Sorting 2 Search (Retrieval) Looking it up One of most fundamental operations Without computer Indexes Tables

### ECE242 Data Structures and Algorithms Fall 2008

ECE242 Data Structures and Algorithms Fall 2008 2 nd Midterm Examination (120 Minutes, closed book) Name: SOLUTION_SET Student ID: Question 1 (10) 2 (20) 3 (25) 4 (10) 5 (15) 6 (20) Score NOTE: Any questions

### The first step in solving a problem recursively is to formulate a recursive definition of the problem.

Chapter 8 Recursion The subject of this chapter is recursion, an implicit application of the stack ADT. A recursive method is a method that carries out its task by making a call(s) to itself. Each recursive

### Introduction to Java

Introduction to Java The HelloWorld program Primitive data types Assignment and arithmetic operations User input Conditional statements Looping Arrays CSA0011 Matthew Xuereb 2008 1 Java Overview A high

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

Part I. Multiple Choice Questions (2 points each): 1. Which of the following is NOT a key component of object oriented programming? (a) Inheritance (b) Encapsulation (c) Polymorphism (d) Parallelism ******

### MSM2G5: Java session 1

MSM2G5: Java session 1 Paul Flavell and Richard Kaye School of Mathematics and Statistics University of Birmingham November 2000 Your objective for your first lab session with Java is to get used to the

### Repetition and Loops. Additional Python constructs that allow us to effect the (1) order and (2) number of times that program statements are executed.

New Topic Repetition and Loops Additional Python constructs that allow us to effect the (1) order and (2) number of times that program statements are executed. These constructs are the 1. while loop and

### Each value (1 through 9) must appear exactly once in each row. Each value (1 through 9) must appear exactly once in each column.

INTRODUCTION TO COMPUTER SCIENCE I PROJECT 6 Sudoku! 1 The game of Sudoku Sudoku is a popular game giving crossword puzzles a run for their money in newspapers. 1 It s a game well suited for computers

### Summit Public Schools Summit, New Jersey Grade Level / Content Area: Mathematics Length of Course: 1 Academic Year Curriculum: AP Computer Science A

Summit Public Schools Summit, New Jersey Grade Level / Content Area: Mathematics Length of Course: 1 Academic Year Curriculum: AP Computer Science A Developed By Brian Weinfeld Course Description: AP Computer

### In Java, the symbol + can be used to add numbers or to concatenate strings. This exercise illustrates both uses.

Chapter 2: Data and Expressions Lab Exercises Two Meanings of Plus In Java, the symbol + can be used to add numbers or to concatenate strings. This exercise illustrates both uses. When using a string literal

### Lecture #3. Searching, Sorting, and Algorithm Analysis

Lecture #3 Searching, Sorting, and Algorithm Analysis Topics 1 Introduction to Search Algorithms 2 Searching an Array of Objects 3 Introduction to Sorting Algorithms 4 Sorting an Array of Objects 5 Sorting

### Chapter 1: Introducing Java

Chapter 1: Introducing Java 1. What is Java? Java is a programming language offering many features that make it attractive for mathematical illustration. First, it is a high-level language providing a

### Application Development with TCP/IP. Brian S. Mitchell Drexel University

Application Development with TCP/IP Brian S. Mitchell Drexel University Agenda TCP/IP Application Development Environment Client/Server Computing with TCP/IP Sockets Port Numbers The TCP/IP Application

### Grundlæggende Programmering IT-C, Forår 2001. Written exam in Introductory Programming

Written exam in Introductory Programming IT University of Copenhagen, June 11, 2001 English version All materials are permitted during the exam, except computers. The exam questions must be answered in

### Searching and Sorting Arrays

L E S S O N S E T 8 Searching and Sorting Arrays PURPOSE PROCEDURE 1. To introduce the concept of a search routine 2. To introduce the linear and binary searches 3. To introduce the concept of a sorting

### 6.092: Introduction to Java. Lecture 1: Types, Variables, Methods

6.092: Introduction to Java Lecture 1: Types, Variables, Methods Outline Intro to Java Types and variables Operators Methods The Computer Memory Central Processing Unit (CPU) Input/Output (IO) Devices

### Java How to Program, 9/e

Java How to Program, 9/e Education, Inc. All Rights Reserved. 1 Any computing problem can be solved by executing a series of actions in a specific order. An algorithm is a procedure for solving a problem

### Java Program Coding Standards 4002-217-9 Programming for Information Technology

Java Program Coding Standards 4002-217-9 Programming for Information Technology Coding Standards: You are expected to follow the standards listed in this document when producing code for this class. Whether

### Java CPD (I) Frans Coenen Department of Computer Science

Java CPD (I) Frans Coenen Department of Computer Science Content Session 1, 12:45-14:30 (First Java Programme, Inheritance, Arithmetic) Session 2, 14:45-16:45 (Input and Programme Constructs) Materials

### CMSC 433 Section 0101 Fall 2012 Midterm Exam #2

Name: CMSC 433 Section 0101 Fall 2012 Midterm Exam #2 Directions: Test is closed book, closed notes, no electronics. Answer every question; write solutions in spaces provided. Use backs of pages for scratch

### Can you design an algorithm that searches for the maximum value in the list?

The Science of Computing I Lesson 2: Searching and Sorting Living with Cyber Pillar: Algorithms Searching One of the most common tasks that is undertaken in Computer Science is the task of searching. We

### Unit 2: Libraries, Packages, Components, Types, and Variables

Unit 2: Libraries, Packages, Components, Types, and Variables Preview of Coming Attractions In this unit be sure to look for different types of libraries packages import command primitive types and component

### Software Testing and Maintenance 1

Input Space Partitioning Introduction Equivalence Partitioning Boundary-Value Analysis Summary Software Testing and Maintenance 1 The Test Selection Problem The input domain of a program consists of all

### Programming Languages CIS 443

Course Objectives Programming Languages CIS 443 0.1 Lexical analysis Syntax Semantics Functional programming Variable lifetime and scoping Parameter passing Object-oriented programming Continuations Exception

### Java Interview Prep E2 Series Java Interview Prep

Object Oriented Programming 1. What is the difference between object oriented and object based languages? Programming languages that support abstraction, encapsulation, inheritance and polymorphism are

C++ How to Program, 8/e 1992-2012 by Pearson Education, Inc. 1992-2012 by Pearson Education, Inc. 1992-2012 by Pearson Education, Inc. We ve studied fixed-size data structures such as one-dimensional arrays

### MIDTERM 1 REVIEW WRITING CODE POSSIBLE SOLUTION

MIDTERM 1 REVIEW WRITING CODE POSSIBLE SOLUTION 1. Write a loop that computes (No need to write a complete program) 100 1 99 2 98 3 97... 4 3 98 2 99 1 100 Note: this is not the only solution; double sum

### Java How to Program, 5/e Test Item File 1 of 6

Java How to Program, 5/e Test Item File 1 of 6 Chapter 7 Section 7.2 7.2 Q1: Which of the following statements about arrays are true? A.Arrays are a group of variables containing values that all have the

### CMSC131. Polymorphism and Arrays

CMSC131 Data Structures, Generics, ArrayList, the notion of a "for each" loop, the Stack Polymorphism and Arrays With polymorphism, we can have (for example) the interfaces Animal and Comparable and classes

### Singleton vs utility class

Singleton vs utility class at first glance, the singleton pattern does not seem to offer any advantages to using a utility class i.e., a utility class with non-final static fields looks a lot like a single

### Intro to Programming in Java Practice Midterm

600.107 Intro to Programming in Java Practice Midterm This test is closed book/notes. SHORT ANSWER SECTION [18 points total] 1) TRUE/FALSE - Please circle your choice: Tr for true, Fa for false. [1 point

### Quiz 4 Solutions EECS 211: FUNDAMENTALS OF COMPUTER PROGRAMMING II. 1 Q u i z 4 S o l u t i o n s

Quiz 4 Solutions Q1: What value does function mystery return when called with a value of 4? int mystery ( int number ) { if ( number

### CS 101: Practice Questions for Test 2 SOLUTIONS

CS 101: Practice Questions for Test 2 SOLUTIONS 1. Write a Java application which prompts the user to enter integers from the screen until the end of file character is entered, computes the sum of the

### The student should be comfortable with using String class methods, messages, parameters, methods, selections and iterations.

1 12 HASH SETS Terry Marris 28 April 2001 12.1 OBJECTIVES By the end of this lesson the student should be able to understand what a set is use the HashSet operations use the Iterator operations 12.2 PRE-REQUISITES

### Algorithms and Data Structures Written Exam Proposed SOLUTION

Algorithms and Data Structures Written Exam Proposed SOLUTION 2005-01-07 from 09:00 to 13:00 Allowed tools: A standard calculator. Grading criteria: You can get at most 30 points. For an E, 15 points are

### INTERFACES AND ITERATORS

INTERFACES AND ITERATORS 1 Interfaces for defining ADTs While studying the Queue ADT, we saw: How to define an interface using the keyword interface. How to write a class that implements an interface using

### IMPERATIVE PROGRAMMING C LANGUAGE

J.NAWROCKI, M. ANTCZAK, H. ĆWIEK, W. FROHMBERG, A. HOFFA, M. KIERZYNKA, S. WĄSIK IMPERATIVE PROGRAMMING C LANGUAGE EX. 1. Write in C language programs described below, compile them and tentatively debug: