COSC 2007 Data Structures II Dr Dave Goforth FA 377 (705)675-1151x2316

Slides:



Advertisements
Similar presentations
Lecture 22, Revision 1 Lecture notes Java code – CodeFromLectures folder* Example class sheets – 4 of these plus solutions Extra examples (quicksort) Lab.
Advertisements

Singly linked lists Doubly linked lists
Lecture 15 Linked Lists part 2
Linked Lists Chapter 4.
Data Structures ADT List
Data Structure Lecture-5
Ics202 Data Structures. hh tail head (b) LinkedList head tail Element datum next 3 Integer Element datum next 1 Integer Element datum next 4 Integer.
Chapter 17 Linked List Saurav Karmakar Spring 2007.
0 of 37 Stacks and Queues Lecture of 37 Abstract Data Types To use a method, need to know its essentials: signature and return type o additionally,
Linked Lists Compiled by Dr. Mohammad Alhawarat CHAPTER 04.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 17: Linked Lists.
Linked Lists. Example We would like to keep a list of inventory records – but only as many as we need An array is a fixed size Instead – use a linked.
COMP 110 Introduction to Programming Mr. Joshua Stough.
Chapter 4 Linked Structures. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 4-2 Chapter Objectives Describe the use of references to create.
Lecture 6: Linked Lists Linked lists Insert Delete Lookup Doubly-linked lists.
Chapter 4 Linked Lists. © 2005 Pearson Addison-Wesley. All rights reserved4-2 Preliminaries Options for implementing an ADT List –Array has a fixed size.
Cmp Sci 187: Midterm Review Based on Lecture Notes.
© 2004 Goodrich, Tamassia Linked Lists1. © 2004 Goodrich, Tamassia Linked Lists2 Singly Linked List (§ 4.4.1) A singly linked list is a concrete data.
Chapter 3: Arrays, Linked Lists, and Recursion
Data Structures Using C++ 2E
Chapter 4 Linked Structures – Stacks Modified. Chapter Scope Object references as links Linked vs. array-based structures Managing linked lists Linked.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
2 Preliminaries Options for implementing an ADT List Array has a fixed size Data must be shifted during insertions and deletions Linked list is able to.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 4: Linked Lists Data Abstraction & Problem Solving with.
CSE 131 Computer Science 1 Module 9: Linked Lists Using references to link objects Basic operations on linked lists Implementing a linked list of integers.
Linked Structures See Section 3.2 of the text.. First, notice that Java allows classes to be recursive, in the sense that a class can have an element.
CS162 - Topic #11 Lecture: Recursion –Problem solving with recursion –Work through examples to get used to the recursive process Programming Project –Any.
Data Structures Using Java1 Chapter 4 Linked Lists.
Department of Computer Science Data Structures Using C++ 2E Chapter 5 Linked Lists.
Week 4 - Monday.  What did we talk about last time?  Queues  Implementing queues with circular arrays.
Programmeren 1 6 september 2010 HOORCOLLEGE 2: INTERACTIE EN CONDITIES PROGRAMMEREN 1 6 SEPTEMBER 2009 Software Systems - Programming1 Programming.
APS105 Lists. Structures Arrays allow a collection of elements –All of the same type How to collect elements of different types? –Structures; in C: struct.
Chapter 5 Linked Lists II
Data Structures Using C++1 Chapter 5 Linked Lists.
Data Abstraction and Problem Solving with JAVA Walls and Mirrors Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley Data Abstraction and Problem.
CS2006- Data Structures I Chapter 5 Linked Lists III.
Sequences1 Vectors Positions Lists General Sequences Bubble Sort Algorithm.
Course: Object Oriented Programming - Abstract Data Types Unit2: ADT ListsSlide Number 1 Principles for implementing ADTs ADT operations as “walls” between.
1 Today’s Material List ADT –Definition List ADT Implementation: LinkedList.
CSC 212 Sequences & Iterators. Announcements Midterm in one week  Will cover through chapter 5 of book  Midterm will be open book, open note (but, closed.
Page 1 – Spring 2010Steffen Vissing Andersen Software Development with UML and Java 2 SDJ I2, Spring 2010 Agenda – Week 8 Linked List (a reference based.
The List ADT Reading: Sections 3.2, 3.3, 3.5.
Data Structures Doubly and Circular Lists Lecture 07: Linked Lists
Data Abstraction and Problem Solving with C++ Walls and Mirrors, Third Edition, Frank M. Carrano and Janet J. Prichard ©2002 Addison Wesley CHAPTER 4 Linked.
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
Chapter 17: Linked Lists. Objectives In this chapter, you will: – Learn about linked lists – Learn the basic properties of linked lists – Explore insertion.
Lists List Implementations. 2 Linked List Review Recall from CMSC 201 –“A linked list is a linear collection of self- referential structures, called nodes,
CSC 243 – Java Programming, Spring, 2014 Week 4, Interfaces, Derived Classes, and Abstract Classes.
Arrays, Link Lists, and Recursion Chapter 3. Sorting Arrays: Insertion Sort Insertion Sort: Insertion sort is an elementary sorting algorithm that sorts.
Given a node v of a doubly linked list, we can easily insert a new node z immediately after v. Specifically, let w the be node following v. We execute.
List Structures What is a list? A homogeneous collection of elements with a linear relationship between the elements linear relationship - each element.
CSC 243 – Java Programming, Fall, 2008 Tuesday, September 30, end of week 5, Interfaces, Derived Classes, and Abstract Classes.
Chapter 3: Fundamental Data Structures: The Array and Linked Structures Data Structures in Java: From Abstract Data Types to the Java Collections Framework.
Chapter 16: Linked Lists.
Lecture 6 of Computer Science II
Vectors 5/31/2018 9:25 AM Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and.
UNIT-3 LINKED LIST.
Chapter 4 Linked Lists.
Linked lists.
EEL 4854 IT Data Structures Linked Lists
Week 15 – Monday CS221.
Top Ten Words that Almost Rhyme with “Peas”
Linked Lists.
11-3 LINKED LISTS A linked list is a collection of data in which each element contains the location of the next element—that is, each element contains.
CS212D: Data Structures Week 5-6 Linked List.
Doubly Linked Lists Lecture 21 Tue, Mar 21, 2006.
Doubly Linked List Implementation
Figure 4.1 a) A linked list of integers; b) insertion; c) deletion.
Dynamic Data Structures and Generics
Linked lists.
Presentation transcript:

COSC 2007 Data Structures II Dr Dave Goforth FA 377 (705) x (local)

Course Objectives Abstract Data Types (ADTs) for collections of Objects JAVA 5.0 generic Collections classes Non-linear data structures that implement ADTs Design of applications using ADTs

Course Organization 6 programming assignments36% due Thursday, 10:30 AM every two weeks 1 midterm examination (2 hours)24% Tuesday June 26 – 10:00 – 11:55 AM 1 final examination (3 hours)40% Tutorial? 12:00 – 12:30 after lecture?

Review linked structures object-oriented implementation concepts linear data structures recursion

Linked lists - references variables of an object type contain addresses or references to objects Point p; p = new Point(5,-2); p p x y 5 -2

Linked lists - nodes nodes are objects that contain references to objects of their own type class Node { int data; Node next; } Node n1, n2; n1 = new Node(3,null); n2 = new Node(5,n1); n2 data next 5 data next 3 n1

Doubly-linked lists Why? – bi-directional movement in list Effect on implementation – maintain one reference to ‘current’ – no need for ‘previous’ reference BUT… – insertion and deletion more complex

Nodes for doubly-linked lists prev and next Node references current may be only reference into list data next -5 prev data next 90 prev data next 34 prev data next prev data next prev current

Nodes for doubly-linked lists head and tail of list identified by null references data next -5 prev data next 90 prev data next 34 prev current (head)(tail)

Inserting new Node before or after current? four links to manage data next -5 prev data next 90 prev data next 34 prev current data next 14 prev

Deleting a node data next -5 prev data next 90 prev data next 34 prev data next prev data next prev current current Node or before or after? four links to manage ?? ?

on empty list on list with one Node at one end of list Operations: Special cases data next -8 prev data next 23 prev data next 91 prev

operations at current node -get data, update data -insert node, delete node operations on current reference -move forward, backward, head, tail operations on list -iterate Object-oriented design Doubly-linked List methods

Assignment 1 - text editor linked structures recursion object-oriented implementation concepts linear data structures testing

Assignment 1 - text editor Evalulation code javadoc documentation testing Submission web-based automated submission May 10, 10:30 AM value 6%

The editor – ed, the line editor text is stored in a doubly-linked list of Strings (no wrap-around from line to line) changes to text occur at current line by commands at console three kinds of operation: 1.movement to another line 2.changes to text in list of Strings 3.file management

The editor – ed, updated version text is displayed in a JFrame display is updated as changes occur (still at the console) file management is by JFileChooser Assignment 1 (local)

Recursion problem decomposition –rewrite problem in terms of a reduced version of itself method structure –base case –recursive case

Recursion example problem decomposition –tired old example: factorial method structure public static int F(int n) { if (n<0) throw new IllegalArgumentException(); if (n>1) return n * F(n-1); return 1; }

Recursion in assignment no iterative structures can be used in this assignment –no “ for ” –no “ while ” –no “ do…while ” use recursive methods instead

Recursion in assignment - example public Node getHead() { Node at = this; while (at.prev != null) at = at.prev; return at; } current = current.getHead(); public class Node { int data; Node next, prev; }

Recursion in assignment - example public Node getHead() { if (prev == null) return this; return prev.getHead(); } public class Node { int data; Node next, prev; } current = current.getHead();

Static and instance methods Problem: case when current is null Static version: current = current.getHead(); current = Node.getHead(current);