Matrix and Linked List ADTs

Slides:



Advertisements
Similar presentations
Chapter 22 Implementing lists: linked implementations.
Advertisements

Transparency No. 1 Java Collection API : Built-in Data Structures for Java.
Lists and the Collection Interface Chapter 4. Chapter Objectives To become familiar with the List interface To understand how to write an array-based.
ITEC200 Week04 Lists and the Collection Interface.
COMP 121 Week 9: AbstractList and ArrayList. Objectives List common operations and properties of Lists as distinct from Collections Extend the AbstractCollection.
Data Structures A data structure is a collection of data organized in some fashion that permits access to individual elements stored in the structure This.
Chapter 6 The Collections API. Simple Container/ Iterator Simple Container Shape [] v = new Shape[10]; Simple Iterator For( int i=0 ; i< v.length ; i++)
INTERFACES IN JAVA 1.Java Does not support Multiple Inheritance directly. Multiple inheritance can be achieved in java by the use of interfaces. 2.We need.
M180: Data Structures & Algorithms in Java
Stacks, Queues, and Deques. 2 A stack is a last in, first out (LIFO) data structure Items are removed from a stack in the reverse order from the way they.
Lecture 18: 4/11/2003CS148 Spring CS148 Introduction to Programming II Ayman Abdel-Hamid Department of Computer Science Old Dominion University Lecture.
Mutable, Immutable, and Cloneable Objects Chapter 15.
Java Collections. Lecture Objectives To understand the concepts of Java collections To be able to implement Java programs based on Collections.
Lists and the Collection Interface Chapter 4. Chapter 4: Lists and the Collection Interface2 Chapter Objectives To become familiar with the List interface.
Fall 2007CS 2251 Lists and the Collection Interface Chapter 4.
Cmp Sci 187: Midterm Review Based on Lecture Notes.
Data Structures Using C++ 2E
SEG4110 – Advanced Software Design and Reengineering TOPIC G Java Collections Framework.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
U n i v e r s i t y o f H a i l 1 ICS 202  2011 spring  Data Structures and Algorithms 
1 Chapter 16-1 Linked Structures Dale/Weems. 2 Chapter 16 Topics l Meaning of a Linked List l Meaning of a Dynamic Linked List l Traversal, Insertion.
COMP 103 Linked Lists. 2 RECAP-TODAY RECAP  Linked Structures: LinkedNode  Iterating and printing Linked Nodes  Inserting and removing Linked Nodes.
Data Structures Using Java1 Chapter 4 Linked Lists.
09-1 Queues and List-Based ADT Implementations Problem Set: PS3 due Wednesday, March 7 Wellesley College CS230 Lecture 09 Monday, February 26 Handout #18.
COMP 121 Week 11: Linked Lists.
© 2006 Pearson Addison-Wesley. All rights reserved5 B-1 Chapter 5 (continued) Linked Lists.
Computer Science 209 Software Development Inheritance and Composition.
1 Stacks (Continued) and Queues Array Stack Implementation Linked Stack Implementation The java.util.Stack class Queue Abstract Data Type (ADT) Queue ADT.
Slides prepared by Rose Williams, Binghamton University Chapter 16 Collections and Iterators.
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
Topic 13 Iterators. 9-2 Motivation We often want to access every item in a data structure or collection in turn We call this traversing or iterating over.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 18 List ADT Animated Version.
IKI 10100: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Lecture1.
CSC 243 – Java Programming, Spring, 2014 Week 4, Interfaces, Derived Classes, and Abstract Classes.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Java From Control Structures through Data Structures by.
CH 1-4 : INTRODUCTION ACKNOWLEDGEMENT: THE SLIDES ARE PREPARED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH, TAMASSIA AND.
Lists and the Collection Interface Chapter 4. Chapter 4: Lists and the Collection Interface2 Chapter Objectives To become familiar with the List interface.
Chapter 3 Lists, Stacks, Queues. Abstract Data Types A set of items – Just items, not data types, nothing related to programming code A set of operations.
1 Iterators & the Collection Classes. 2 » The Collection Framework classes provided in the JAVA API(Application Programmer Interface) contains many type.
Iterators.
Chapter 5: The List Abstract Data Type
The List ADT.
CSCI-255 LinkedList.
Linked Lists Chapter 5 (continued)
CS2006- Data Structures I Chapter 5 Linked Lists I.
John Hurley Cal State LA
Stacks.
Linked lists Motivation: we can make arrays, but their functionality is slightly limited and can be difficult to work with Biggest issue: size management.
Top Ten Words that Almost Rhyme with “Peas”
Chapter 16-2 Linked Structures
THURSDAY, OCTOBER 17 IN LAB
" A list is only as strong as its weakest link. " - Donald Knuth
Abstract Class As per dictionary, abstraction is the quality of dealing with ideas rather than events. For example, when you consider the case of ,
Programming II (CS300) Chapter 07: Linked Lists and Iterators
CS2013 Lecture 4 John Hurley Cal State LA.
Dynamic Data Structures and Generics
Generic Classes and Methods
CSE 501N Fall ‘09 13: Interfaces and Multiple Representation
Chapter 16 Linked Structures
Computer Science and Engineering
Review CSE116 2/21/2019 B.Ramamurthy.
Collections Framework
Dynamic Data Structures and Generics
Chapter 4 Queues.
Programming II (CS300) Chapter 02: Using Objects Java ArrayList Class
Linked Lists Chapter 5 (continued)
Recursive Objects Singly Linked Lists.
Stacks, Queues, and Deques
Linked Lists Chapter 5 (continued)
Java Generics & Iterators
Presentation transcript:

Matrix and Linked List ADTs B.Ramamurthy (Still in Chapter 4)

Topics for Discussion Matrix interface And an implementation Singly-linked List Linked List from Java API Summary

Matrix Interface public interface Matrix { double get (int i, int j); void put (int i, int j, double d); Matrix transpose(); Matrix times (Matrix matrix); Matrix plus (Matrix matrix); }

An Implementation : Dense Matrix From an interface definition there can be many implementations. For example, dense matrix, sparse matrix, triangular matrix, may have different semantics for the methods specified in the interface.

Data Fields and Constructor public class DenseMatrix implements Matrix { protected int numberOfRows; protected int numberOfColumns; protected double[][] array; public DenseMatrix (int numberOfRows, int numberOfColumns) { this.numberOfRows = numberOfRows; this.numberOfColumns = numberOfColumns; array = new double[numberOfRows][numberOfColumns]; } //others

times method public Matrix times (Matrix mat) { DenseMatrix arg = (DenseMatrix) mat; if (numberOfColumns != arg.numberOfRows) // throw exception DenseMatrix result = new DenseMatrix(numberOfRows, arg.numberOfColumns);

times method (contd.) for (int j = 0; j< numberOfRows; j++) for (int k= 0; k< arg.numberOfColumns;k++) {double sum = 0; for (int p =0; p< numberOfColumns; p++) sum = sum + array[j][p] *arg[p][k]; result.array[j][k] = sum; } return result; }

Linked List Linked data representation and algorithms that manipulate them are an important component of study in CS. Linked representations are used when it is difficult to predict the size and shape of the data structures needed.

A node of linked list public class ListNode { ItemType item; ListNode link; } some times you have explicit representation for a head and or tail. 5/30/2019 B.Ramamurthy

Linked List class LinkedList // data int length; ListNode firstNode; // methods public int size() public bool insertNode(ItemType it) public bool insertLast(ItemType it) public bool deleteLast() public ListNode search(ItemType it) public bool equals(LinkedList ll) public String toString()

JDK1.2 Linked List Object AbstractCollection Collection AbstractList AbstractSequentialList List, java.io.Serializable, java.lang.Cloneable LinkedList

LinkedList’s inheritance Most of the direct linked list functionality is defined in the interface List. Serializable defines the disk archiving functionality. Cloenable defined the cloning ability. LinkedList class defines the variables needed for storing the header and size. A ListIterator class offers the Iterator facility.

LinkedList methods List interface and how LinkedList implements them. Look at /util/lang/jdk1.2/docs/index.html for more details. Among the methods a special method called iterator is important many of the Collection classes. This is proper way carry out an operation on “on all” elements of a collection.

ListIterator Usage: LinkedList myList = new LinkedList(); // fill it up with data ListIterator k = myList.listIterator(); while(k.hasNext()) { // process the elements myProcess(k.next()); System.out.println(k.next()); }