Outline Resource Introduction Usage Testing Exercises. Linked Lists COMP SCI / SFWR ENG 2S03. Department of Computing and Software McMaster University

Similar documents
Outline Resource Introduction Usage Testing Exercises. Linked Lists COMP SCI / SFWR ENG 2S03. Department of Computing and Software McMaster University

HW #4. (mostly by) Salim Sarımurat. 1) Insert 6 2) Insert 8 3) Insert 30. 4) Insert S a.

Skip Lists. What is a Skip List. Skip Lists 3/19/14

Queues. Principles of Computer Science II. Basic features of Queues

CMSC 132, Object-Oriented Programming II Summer Lecture 1:

WHAT IS A SKIP LIST? S 2 S 1. A skip list for a set S of distinct (key, element) items is a series of lists

Verifying Java-KE Programs

RANDOMIZED ALGORITHMS

CMSC 132, Object-Oriented Programming II Summer Lecture 6:

Math 105 Course Outline

Searching, mainly via Hash tables

Introduction to Computing II (ITI 1121) FINAL EXAMINATION

Introduction to Computing II (ITI1121) FINAL EXAMINATION

Python & Numpy A tutorial

Measuring Goodness of an Algorithm. Asymptotic Analysis of Algorithms. Measuring Efficiency of an Algorithm. Algorithm and Data Structure

Creating Basemaps to Manage Buildings and Facilities

Lecture 5: Sep. 23 &25

Binary Search Trees. Motivation

Skip List. CS 561, Lecture 11. Skip List. Skip List

Computation Theory Finite Automata

Lists, Stacks, and Queues (plus Priority Queues)

CalPhy. Spring 2015 with A. Aho Programming Languages & Translators

ITI Introduction to Computing II

Information Retrieval

SFWR ENG/COMP SCI 2S03 Principles of Programming

Lecture 4: Stacks and Queues

Data Structures. Outline. Introduction. Andres Mendez-Vazquez. December 3, Data Manipulation Examples

Binary Search Trees. Lecture 29 Section Robb T. Koether. Hampden-Sydney College. Fri, Apr 8, 2016

1 Lecture 8: Interpolating polynomials.

Discrete-event simulations

/463 Algorithms - Fall 2013 Solution to Assignment 4

Recursion - 1. Recursion. Recursion - 2. A Simple Recursive Example

Introduction to Computer Programming, Spring Term 2018 Practice Assignment 1 Discussion:

1 ListElement l e = f i r s t ; / / s t a r t i n g p o i n t 2 while ( l e. next!= n u l l ) 3 { l e = l e. next ; / / next step 4 } Removal

Collision. Kuan-Yu Chen ( 陳冠宇 ) TR-212, NTUST

Height, Size Performance of Complete and Nearly Complete Binary Search Trees in Dictionary Applications

Outline. 1 Merging. 2 Merge Sort. 3 Complexity of Sorting. 4 Merge Sort and Other Sorts 2 / 10

The Kerbal Space Program

Design of discrete-event simulations

Hashing. Dictionaries Hashing with chaining Hash functions Linear Probing

Stacks. Definitions Operations Implementation (Arrays and Linked Lists) Applications (system stack, expression evaluation) Data Structures 1 Stacks

1 Trees. Listing 1: Node with two child reference. public class ptwochildnode { protected Object data ; protected ptwochildnode l e f t, r i g h t ;

LAB 2. HYPOTHESIS TESTING IN THE BIOLOGICAL SCIENCES- Part 2

1 Binomial Probability [15 points]

Lecture 7: Trees and Structural Induction

Mathematical Background. Unsigned binary numbers. Powers of 2. Logs and exponents. Mathematical Background. Today, we will review:

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Dynamic Programming II Date: 10/12/17

Introduction to Computer Programming, Spring Term 2018 Practice Assignment 1 Discussion:

ITI Introduction to Computing II

CIVL Why are we studying probability and statistics? Learning Objectives. Basic Laws and Axioms of Probability

Lecture 2. Introduction to ESRI s ArcGIS Desktop and ArcMap

E23: Hotel Management System Wen Yunlu Hu Xing Chen Ke Tang Haoyuan Module: EEE 101

Independence, Variance, Bayes Theorem

Introduction to Engineering Analysis - ENGR1100 Course Description and Syllabus Tuesday / Friday Sections. Spring '13.

Error Detection and Correction: Small Applications of Exclusive-Or

The Greedy Method. Design and analysis of algorithms Cs The Greedy Method

CSE613: Parallel Programming, Spring 2012 Date: May 11. Final Exam. ( 11:15 AM 1:45 PM : 150 Minutes )

SFWR ENG/COMP SCI 2S03 Principles of Programming

Introduction to functions

McCreight's suffix tree construction algorithm

COMP232 - Mathematics for Computer Science

Project 2: Hadoop PageRank Cloud Computing Spring 2017

arxiv: v2 [cs.ds] 9 Nov 2017

Mathematics. ( : Focus on free Education) (Chapter 16) (Probability) (Class XI) Exercise 16.2

Compiling Techniques

Two hours UNIVERSITY OF MANCHESTER SCHOOL OF COMPUTER SCIENCE. Date: Thursday 17th May 2018 Time: 09:45-11:45. Please answer all Questions.

Strongly Agree Agree

Ukkonen's suffix tree construction algorithm

Chapter 5 Data Structures Algorithm Theory WS 2017/18 Fabian Kuhn

COMP9319 Web Data Compression and Search. Lecture 2: Adaptive Huffman, BWT

Data Structures and Algorithms Winter Semester

A linear equation in two variables is generally written as follows equation in three variables can be written as

Introduction to Computing II (ITI 1121) MIDTERM EXAMINATION

Parameter Learning With Binary Variables

A BASE SYSTEM FOR MICRO TRAFFIC SIMULATION USING THE GEOGRAPHICAL INFORMATION DATABASE

Chapter 35 out of 37 from Discrete Mathematics for Neophytes: Number Theory, Probability, Algorithms, and Other Stuff by J. M. Cargal.

UCSD CSE 21, Spring 2014 [Section B00] Mathematics for Algorithm and System Analysis

Machine Learning: Pattern Mining

Heaps and Priority Queues

Chemical Engineering 3P04 Process Control Tutorial # 1 Learning goals

Lecture 1 Introduction to Probability and Set Theory Text: A Course in Probability by Weiss

Welcome to NR502 GIS Applications in Natural Resources. You can take this course for 1 or 2 credits. There is also an option for 3 credits.

Computer Science Introductory Course MSc - Introduction to Java

INF2220: algorithms and data structures Series 1

Chart 3 Data in Array

Searching. Constant time access. Hash function. Use an array? Better hash function? Hash function 4/18/2013. Chapter 9

Saudi Journal of Engineering and Technology. DOI: /sjeat ISSN (Print)

Integrated Electricity Demand and Price Forecasting

SWER ENG 2DM3 Tutorial 2

Abstract Data Types. EECS 214, Fall 2017

Introduction to Python and its unit testing framework

Welcome to Comp 411! 2) Course Objectives. 1) Course Mechanics. 3) Information. I thought this course was called Computer Organization

IS 709/809: Computational Methods in IS Research Fall Exam Review

Accurate 3D-Modeling of User Inputted Molecules

Outline. Martingales. Piotr Wojciechowski 1. 1 Lane Department of Computer Science and Electrical Engineering West Virginia University.

Computer Science Introductory Course MSc - Introduction to Java

Project 3: Hadoop Blast Cloud Computing Spring 2017

Turing Machines Part II

CS60007 Algorithm Design and Analysis 2018 Assignment 1

Math 1021, Linear Algebra 1. Section: A at 10am, B at 2:30pm

Transcription:

COMP SCI / SFWR ENG 2S03 Department of Computing and Software McMaster University Week 10: November 10 - November 14

Outline 1 Resource 2 Introduction Nodes Illustration 3 Usage Adding Finding and Removing 4 Testing Exceptions Fixtures 5 Exercises

Resource Some of the following material is adapted from: Mughal, Khalid. Java Actually : A Comprehensive Primer in Programming. Australia: Course Technology/Cenage Learning, 2008. Virginia Tech for the Linked List image

Linked lists are dynamic data structures which A. Can create new data on demand B. Have an extra field to store a reference C. Data manipulation can be done by changing references

(continued) Some of the properties of linked lists include A. List of items which are called nodes B. Have a head and a tail Head points to the first node in the list Tail points to the last node in the list C. Every node has a pointer to the next node D. Because of this, lists are not limited in size like arrays!

Nodes Nodes are what make up a linked list. They are records which contain a data element as well as a pointer to the next element in the list. If the pointer is null, that means that the node is at the tail of the list. p u b l i c c l a s s Node<E> { p r i v a t e E data ; // E can be any type e x c e p t p r i m i t i v e s p r i v a t e Node next ;.. }

- Illustration

Using Java Java has a built-in linked list implementation that we will use. Linked lists can be created using any object type. import j a v a. u t i l. L i n k e d L i s t // Do t h i s always! L i n k e d L i s t <S t r i n g > s t r i n g s = new L i n k e d L i s t <S t r i n g >(); L i n k e d L i s t <I n t e g e r > i n t s = new L i n k e d L i s t <I n t e g e r >();

- Adding You can add elements to a linked list by A. Appending to the tail or B. Adding to a specific index // add (E element ) // add ( i n t index, E element ) l i s t. add ( " Hello, " ) ; l i s t. add ( 1, " world! " ) ;

- Finding and Removing When we want to remove and item from a linked list, we must first find its index value. // indexof ( Object o ) // remove ( i n t i n d e x ) l i s t. add ( " Hello, world! " ) ; l i s t. remove ( l i s t. indexof ( " Hello, world! " ) ) ; // L i s t i s now empty!

Testing for Exceptions Using JUnit you can test for an exception being thrown by your code such as A. IndexOutOfBoundsException B. IOException C. ArithmeticException

Testing for Exceptions - Example @Test ( e x p e c t e d= IndexOutOfBoundsException. c l a s s ) p u b l i c void empty ( ) { new L i n k e d L i s t <I n t e g e r >(). get ( 0 ) ; }

Testing Fixtures Using JUnit, you can also specify the state of your program pre-class or pre-test A. @BeforeClass B. @AfterClass C. @Before D. @After

Testing Fixtures - Example @ B e f o r e C l a s s p u b l i c s t a t i c void s e t u p ( ) { Point t e s t P o i n t = new Point ( 0, 5 ) ; i n t t e s t V a l u e = 5 ; }

Exercises There are many methods that are provided by Java for linked lists. You can find them online at http://docs.oracle.com/javase/7/docs/api/java/ util/linkedlist.html In the exercises that follow, be sure to refer to the documentation for any methods not mentioned here!