Computer Science II Data Structures

Similar documents
Welcome to CSL 201 Data Structures

CS 231 Data Structures and Algorithms, Fall 2016

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

Announcements. 1. Forms to return today after class:

CSCI 136 Data Structures & Advanced Programming. Fall 2018 Instructors Bill Lenhart & Bill Jannen

Java Primer 1: Types, Classes and Operators

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

CISC 3130 Data Structures Fall 2018

CS2013 Course Syllabus Spring 2018 Lecture: Mon/Wed 2:00 P.M. 2:50 P.M. SH C259 Lab: Mon/Wed 2:50 P.M. 4:00 P.M. SH C259

Introduction to Data Structures

Computer Science 210: Data Structures

CS 251 Intermediate Programming Methods and Classes

CS 251 Intermediate Programming Methods and More

CSCE 210/2201 Data Structures and Algorithms. Prof. Amr Goneid

CSCE 210/2201 Data Structures and Algorithms. Prof. Amr Goneid. Fall 2018

You must pass the final exam to pass the course.

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

CS 240 Fall Mike Lam, Professor. Just-for-fun survey:

Object Oriented Programming: In this course we began an introduction to programming from an object-oriented approach.

CS/ENGRD 2110 Object-Oriented Programming and Data Structures Spring 2012 Thorsten Joachims

1 Epic Test Review 2 Epic Test Review 3 Epic Test Review 4. Epic Test Review 5 Epic Test Review 6 Epic Test Review 7 Epic Test Review 8

COE318 Lecture Notes Week 4 (Sept 26, 2011)

CS61BL. Lecture 1: Welcome to CS61BL! Intro to Java and OOP Testing Error-handling

Assignment 1 due Monday at 11:59pm

ESC101 : Fundamental of Computing

Solutions Manual. Data Structures and Algorithms in Java, 5th edition International Student Version. M. T. Goodrich and R.

Getting started with Java

8/27/13. An intro to programming* *Java. Announcements. Professor Rodger. The Link. UTAs start TONIGHT!

CISC 3130 Data Structures Spring 2018

EECS168 Exam 3 Review

CSCI 136 Data Structures & Advanced Programming. Spring 2018 Instructors Bill Jannen & Jon Park

Programming Languages and Techniques (CIS120)

More on Arrays CS 16: Solving Problems with Computers I Lecture #13

JAVA MOCK TEST JAVA MOCK TEST II

CS 11 java track: lecture 1

Java Bytecode (binary file)

CS 106 Introduction to Computer Science I

COE318 Lecture Notes Week 5 (Oct 3, 2011)

Arrays. Array Definition

CS18000: Problem Solving And Object-Oriented Programming

CS 1302 Chapter 9 (Review) Object & Classes

APCS Semester #1 Final Exam Practice Problems

COMP 2150 CS 2: Object-Oriented Programming and Data Structure Fall 2018 Dr. James Yu

Array. Prepared By - Rifat Shahriyar

COE318 Lecture Notes Week 6 (Oct 10, 2011)

BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I

VE281 Data Structures and Algorithms. Introduction and Asymptotic Algorithm Analysis

Course: Honors AP Computer Science Instructor: Mr. Jason A. Townsend

MARKING KEY The University of British Columbia MARKING KEY Computer Science 260 Midterm #2 Examination 12:30 noon, Thursday, March 15, 2012

Java Programming. MSc Induction Tutorials Stefan Stafrace PhD Student Department of Computing

Software Practice 1 Basic Grammar

Lecture 1: Overview & Intro to Java

CSE115 / CSE503 Introduction to Computer Science I. Dr. Carl Alphonce 343 Davis Hall Office hours:

CS 101 Fall 2006 Midterm 1 Name: ID:

CSC 172 Data Structures and Algorithms. Fall 2017 TuTh 3:25 pm 4:40 pm Aug 30- Dec 22 Hoyt Auditorium

Data Structures and Algorithms in Java. Second Year Software Engineering

Programming II (CS300)

Java Fundamentals (II)

CS2013 Course Syllabus Spring 2017 Lecture: Friday 8:00 A.M. 9:40 A.M. Lab: Friday 9:40 A.M. 12:00 Noon

CS 206 Introduction to Computer Science II

Computer Science II Lecture 1 Introduction and Background

Outline. Object Oriented Programming. Course goals. Staff. Course resources. Assignments. Course organization Introduction Java overview Autumn 2003

KOMAR UNIVERSITY OF SCIENCE AND TECHNOLOGY (KUST)

Lecture 2. COMP1406/1006 (the Java course) Fall M. Jason Hinek Carleton University

Object Oriented Design: Identifying Objects

COMP Data Structures

Software and Programming 1

Chapter 6 Classes and Objects

COMP Data Structures

CS 351: Design of Large Programs.

Unit 4: Classes and Objects Notes

CS 3270 Mobile Development for Android Syllabus

Lesson 10A OOP Fundamentals. By John B. Owen All rights reserved 2011, revised 2014

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub

Spring 2003 Instructor: Dr. Shahadat Hossain. Administrative Matters Course Information Introduction to Programming Techniques

San José State University Department of Computer Science CS049J, Programming in Java, Section 2, Fall, 2016

Review: Object Diagrams for Inheritance. Type Conformance. Inheritance Structures. Car. Vehicle. Truck. Vehicle. conforms to Object

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

Prelim 1 Solutions. CS 2110, March 10, 2015, 5:30 PM Total Question True False. Loop Invariants Max Score Grader

Two Types of Types. Primitive Types in Java. Using Primitive Variables. Class #07: Java Primitives. Integer types.

CS171:Introduction to Computer Science II

Programming with Java

Faculty of Science FINAL EXAMINATION

CS 112 Programming 2. Lecture 10. Abstract Classes & Interfaces (1) Chapter 13 Abstract Classes and Interfaces

COMP251: Algorithms and Data Structures. Jérôme Waldispühl School of Computer Science McGill University

Arrays & Linked Lists

Basic Operations jgrasp debugger Writing Programs & Checkstyle

BCIS 3630 Dr. GUYNES SPRING 2018 TUESDAY SECTION [JAN version] GRADER COURSE WEBSITE

CS 110 Practice Final Exam originally from Winter, Instructions: closed books, closed notes, open minds, 3 hour time limit.

Java and C I. CSE 351 Spring Instructor: Ruth Anderson

CPSC 2380 Data Structures and Algorithms

CS Programming I: Arrays

MIDTERM REVIEW. midterminformation.htm

Object oriented programming. Instructor: Masoud Asghari Web page: Ch: 3

CHAPTER 7 OBJECTS AND CLASSES

Object-Oriented Programming

CSE030 Fall 2012 Final Exam Friday, December 14, PM

Before We Begin. Class Implementation II. Introduction to Computer Science II. Overview (1): Administrative Details (1):

Programming Languages and Techniques (CIS120)

61A LECTURE 1 FUNCTIONS, VALUES. Steven Tang and Eric Tzeng June 24, 2013

Transcription:

Computer Science II Data Structures Instructor Sukumar Ghosh 201P Maclean Hall Office hours: 10:30 AM 12:00 PM Mondays and Fridays Course Webpage homepage.cs.uiowa.edu/~ghosh/2116.html

Course Syllabus Constructs in Java, the language we will use Algorithm complexity and Big-O notation Arrays, Linked lists Solving problems using recursion Stacks, queues, lists and trees Searching and sorting Priority queues, hash tables, binary search trees Graphs and basic algorithms on graphs Teaching Assistants Kyle Diederich Adrian Pereira Thamer Alsulaiman Dhuv Vyas

About this course Main class (AAA) and six sections A01-A06 Discussion sections meet on Thursdays only. You must go to your own section. Textbook Goodrich, Tamassia, and Goldwasser: Data Structures and Algorithms in Java (Sixth edition), Wiley, ISBN 978-1-118-77133-4. Prerequisites Computer Science I (CS: 1210 / 22C:016/ ENGR 2730) (Note: CS 2210: Discrete Structures is a corequisite, if not taken as a prerequisite earlier)

Grading Eight Home assignments (30%) Two quizzes (2x5%= 10%) Two in-class midterms (2x20%=40%), and (Monday, Sep 26 and on Monday, Oct 31) One Final exam (20 %) Limited collaboration is OK, assuming you have first spent some time (about 60 minutes) working on the problem yourself. However, your solution should not be a copy (whole or in part) of a fellow student. Late Homework Policy Quota of two days for the entire semester

How Java works Java program Compiler Bytecode Java Virtual Machine Result

Which IDE will we use? We will use NetBeans. You can download it on your machines. They are installed in all lab machines. WE will demonstrate it today in the class.

Object-oriented programming An Object is a repository of data Typed data. Always declare before you use. Primitive types. int, char, boolean, float etc Class. A template for creating objects Think of shoppinglist as a class. We can define two objects for this class. Example: sugar coffee milk mylist pencil paper stapler yourlist Object mylist belongs to the Class ShoppingList. A Class denotes the type of object

Class Class

Class Human{ Public int age; Public String name; Public void introduce() { System.out.println( I m + name + and I m + age + years old ) } } Now, continue as Human Alice = new Human();// Create Alice Alice.age = 21; // Set Alice s fields Alice.name = Alice ; Alice.introduce( );

Structure of a Java program public class MyFirstJavaProgram { public static void main(string []args) { System.out.println("Hello World"); } } Class = blueprint of an object Class name starts with a capital letter Object = instance of a class, created using a constructor Instance variables = Unique set of variables for an object Methods = Actions to manipulate data Method name starts with lower case letters Program file name = Must exactly match the class name. Saved as filename.java Package = a group of related class definitions

What are public, private, protected? These are Access Control Modifiers. Private: Visible to the class only Public: Visible to the world No modifier: Visible to the package, the default Protected: Visible to the package and all subclasses

Organization of a class 1. Constants 2. Instance variables 3. Constructors 4. Methods

More on Types Primitive types. Integer, Boolean, character etc Boolean true or false Char A character (like s ) Byte 8-bit integer -128 to +127 Short 16-bit integer -32768 to + 32767 Int 32-bit integer Long 64-bit integer Float 32-bit floating-point number Double 32-bit floating-point number Reference variables. A variable whose type is a class is called a reference variable. c = new Car( ) mylist = new ShoppingList( )

Method A Method is a procedure or a function that operates on an object to produce a result. An accessor method returns a value. An update method only makes changes in the fields, but no value (void) is returned. Objects are manipulated by methods. Consider a Rectangle class, and an object R belonging to this class Rectangle R; R = new Rectangle(5,-10,100,200); int w = R.getWidth(); // This is OK

In the above example, getwidth is a method that returns the width of the rectangle. Note. If you write Rectangle R; int w = R. getwidth(); // This is wrong! It will not work since R is just the name of a handle. The object has not been created yet. Static modifier (of a method or a variable) The value is associated with the entire class, and not to a particular instance of it) Abstract method Contains only the signature but no body Final method Attributed to a variable that does not change. A final method cannot be overridden by a subclass.

Objects and Methods Let us start with strings (sequence of characters). Constructors are used to initialize a new object or a variable, and always use the name of the class. String s1; // Declare a string variable s1 = new String ( ); //Assign a value, an empty string String s2 = new String ( ); // Short cut String String s1 s2 s1 = Hello ; //See below String String s1 s2 Hello

s2 = s1; // See below, both point to the same string String String s1 s2 Hello So, how to make a separate string s2 with Hello? s2 = new String (s1); or s2 = Hello ; Java strings are immutable objects, so instead of modifying a string create a new one. Let us look at a method: s2 = s1.touppecase( )// touppercase is a method // Here, s2 will be a new string HELLO String s3 = s2. concat(! ) // s3 = s2 +!

That is, s3 becomes a new string HELLO! Java will also allow s2 = s2 +! // Now s2 = HELLO! But it involves copying the old string and adding! to it to generate a new string, and then switch the reference from s the handle s2. It is inefficient for long strings. The StringBuilder class allows efficient editing of strings, and in essence creates a mutable string. We will discuss it later.

Arrays Consists of a numbered list of variables. An array variable is a reference variable. So int[ ] X; Is only a declaration, and no allocation is made. To construct an array by allocation space in the memory, use the new operator int[ ] X = new int[8] and then initialize it. c b l u e 0 1 2 3 char [ ] c; // Creates an array of char c = new char[4] // Creates array of size 4 c[0] = b ; c[1] = l ; c[2] = u c[3] = e

An array is an immutable object. The first index is always zero (not 1). int[] A = new int[4] ; int[] B = new int[6] ; for (int i = 0 ; i < A.length ; i++) A[i] = 10 ; for (int i = 0 ; i < B.length ; i++) B[i] = 20 ; B = A; // what happens here? See below. {Note: A.length gives the length of the array A} A B 10 10 10 10 20 20 20 20 20 20 A B 10 10 10 10 20 20 20 20 20 20

An array can also contain reference to objects. string[ ] X = new string[6] string[0] = Rene string[1] = joseph

Multidimensional Arrays int[][] mymatrix = new int[8][10] ; Java will treat this as an array of arrays. So, mymatrix[7] will denote the seventh row of the (8x10) matrix. class MultiDimArrayDemo { public static void main(string[] args) { String[][] names = { {"Mr. ", "Mrs. ", "Ms. "}, {"Smith", "Jones", Ford } }; // Mr. Smith System.out.println(names[0][0] + names[1][0]); // Ms. Jones System.out.println(names[0][2] + names[1][1]); // Mrs. Ford System.out.println(names[0][1] + names[1][2]); } }

Example: Game entries In an event in the Rio Olympics, we want to record the best six scores, sorted in the non-decreasing, and save them in an array. Each array element is a GameEntry that consists of a pair: name and score.

Here is the GameEntry class.

Here is the Scoreboard class. Think of how to update the scoreboard when a new score (Tammy 170) or (Hillary, 100) is recorded.