HIT2037- HIT6037 Software Development in Java 22 – Data Structures and Introduction.

Slides:



Advertisements
Similar presentations
Stacks, Queues, and Linked Lists
Advertisements

Chapter 24 Lists, Stacks, and Queues
Lists and the Collection Interface Chapter 4. Chapter Objectives To become familiar with the List interface To understand how to write an array-based.
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++)
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.
Chapter 5 Queues Modified. Chapter Scope Queue processing Comparing queue implementations 5 - 2Java Software Structures, 4th Edition, Lewis/Chase.
COMP 103 Linked Stack and Linked Queue.
1 Chapter 24 Lists Stacks and Queues. 2 Objectives F To design list with interface and abstract class (§24.2). F To design and implement a dynamic list.
CS 307 Fundamentals of Computer Science 1 Abstract Data Types many slides taken from Mike Scott, UT Austin.
CS 206 Introduction to Computer Science II 10 / 26 / 2009 Instructor: Michael Eckmann.
Lists and the Collection Interface Chapter 4. Chapter 4: Lists and the Collection Interface2 Chapter Objectives To become familiar with the List interface.
1 Data Structures  We can now explore some advanced techniques for organizing and managing information  Chapter 12 of the book focuses on: dynamic structures.
Fall 2007CS 2251 Lists and the Collection Interface Chapter 4.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 26 Implementing Lists, Stacks,
Liang, Introduction to Java Programming, Tenth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 20 Lists, Stacks, Queues, and Priority.
1 Stack Data : a collection of homogeneous elements arranged in a sequence. Only the first element may be accessed Main Operations: Push : insert an element.
Stacks, Queues, and Deques
© 2004 Pearson Addison-Wesley. All rights reserved12-1 Chapter 12 : Collections Intermediate Java Programming Summer 2007.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 22 Lists, Stacks, Queues, and Priority.
Java Collections. Collections, Iterators, Algorithms CollectionsIteratorsAlgorithms.
SEG4110 – Advanced Software Design and Reengineering TOPIC G Java Collections Framework.
Copyright © Texas Education Agency, Advanced Computer Programming Data Structures: Collections.
ISOM MIS 215 Module 3 – Stacks and Queues. ISOM Where are we? 2 Intro to Java, Course Java lang. basics Arrays Introduction NewbieProgrammersDevelopersProfessionalsDesigners.
Chapter 3 List Stacks and Queues. Data Structures Data structure is a representation of data and the operations allowed on that data. Data structure is.
Data Structures and Abstract Data Types "Get your data structures correct first, and the rest of the program will write itself." - David Jones.
Lists Based on content from: Java Foundations, 3rd Edition.
Java Collections An Introduction to Abstract Data Types, Data Structures, and Algorithms David A Watt and Deryck F Brown © 2001, D.A. Watt and D.F. Brown.
Jan 12, 2012 Introduction to Collections. 2 Collections A collection is a structured group of objects Java 1.2 introduced the Collections Framework Collections.
The Java Collections Framework (JCF) Introduction and review 1.
Information and Computer Sciences University of Hawaii, Manoa
111 © 2002, Cisco Systems, Inc. All rights reserved.
1/ 124 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 18 Programming Fundamentals using Java 1.
COMP 103 Linked Lists. 2 RECAP-TODAY RECAP  Linked Structures: LinkedNode  Iterating and printing Linked Nodes  Inserting and removing Linked Nodes.
LinkedList Many slides from Horstmann modified by Dr V.
CSS446 Spring 2014 Nan Wang  Java Collection Framework ◦ LinkedList ◦ Set ◦ Map 2.
Queue FIFO (First In First Out) Java Doc peek, element offer poll, add
A data structure is a type of data storage ….similar to an array. There are many data structures in Java (Stacks, Queues, LinkedList, Sets, Maps, HashTables,
Week 3 - Friday.  What did we talk about last time?  Stacks  Array implementation of a stack.
COP INTERMEDIATE JAVA Data Structures. A data structure is a way of organizing a collection of data so that it can be manipulated effectively. A.
CIS3023: Programming Fundamentals for CIS Majors II Summer 2010 Ganesh Viswanathan Generics and Collections Course Lecture Slides 19 th July 2010 “Never.
Chapter 12: Collections by Lewis and Loftus (Updated by Dan Fleck) Coming up: Collections.
CSS446 Spring 2014 Nan Wang.  To understand the implementation of linked lists and array lists  To analyze the efficiency of fundamental operations.
Collections Data structures in Java. OBJECTIVE “ WHEN TO USE WHICH DATA STRUCTURE ” D e b u g.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 20 Lists, Stacks, Queues, and Priority.
Collections Mrs. C. Furman April 21, Collection Classes ArrayList and LinkedList implements List HashSet implements Set TreeSet implements SortedSet.
1 Stacks (Continued) and Queues Array Stack Implementation Linked Stack Implementation The java.util.Stack class Queue Abstract Data Type (ADT) Queue ADT.
© 2011 Pearson Addison-Wesley. All rights reserved 8 B-1 Chapter 8 (continued) Queues.
1 Chapter 24 Implementing Lists, Stacks, Queues, and Priority Queues Jung Soo (Sue) Lim Cal State LA.
Collections ABCD ABCD Head Node Tail Node array doubly linked list Traditional Arrays and linked list: Below is memory representation of traditional.
Week 4 - Monday CS221.
Marcus Biel, Software Craftsman
Csc 2720 Data structure Instructor: Zhuojun Duan
Chapter 20 Lists, Stacks, Queues, and Priority Queues
Chapter 12: Data Structures
Road Map CS Concepts Data Structures Java Language Java Collections
structures and their relationships." - Linus Torvalds
Linked Lists.
structures and their relationships." - Linus Torvalds
Chapter 24 Implementing Lists, Stacks, Queues, and Priority Queues
Collections Framework
Road Map CS Concepts Data Structures Java Language Java Collections
Queues cont. Chapter 8 © 2011 Pearson Addison-Wesley. All rights reserved.
Stacks, Queues, and Deques
CS 240 – Advanced Programming Concepts
structures and their relationships." - Linus Torvalds
Chapter 20 Lists, Stacks, Queues, and Priority Queues
Queues.
Presentation transcript:

HIT2037- HIT6037 Software Development in Java 22 – Data Structures and Introduction

2 Content Introduction to data structures Introduction to sorting Introduction to searching

3 What is a Data Structure? We have already worked out how to store objects in an ArrayList However, there are other “Data Structures” that allow us to store collections of objects Each structure has different strengths and weaknesses One structure might be perfect for one application and terrible for another

4 Linked List “ A link list has a number of nodes each of which has a reference to the next node” [1] Key features  Good where items need to be removed or added in the middle of the list ( just change the reference)  Sequential access is efficient  Java provides a LinkedList in the util package  LinkedList  An iterator can be used with a LinkedList  See simulation

5 Linked List – Some Operations addLast(E e) addFirst(E e) add(int index, E element) getFirst() getLast() indexOf(Object o) peekFirst() peekLast() Other data structures such as Stacks and Queues are often based on Linked Lists Linked Lists do not do this efficiently. They only allow sequential access Items in the list do not need to be stored in order in memory Variations include Circular lists, link from head to tail Double linked lists, traverse forward and backwards

6 Queue Implements “first in first out” Example “a queue of jobs to do” Java provides a Queue class in the util package Important operations  add (E e) // returns true if it works  poll() // retrieves head or returns false (check this)  peek() // retrieves head but does not remove  remove() // retrieves and removes head of queue Why use it? “Conceptually what we want”[2] A pipe Items you want to deal with order of arrival (Time?)

7 Stack Implements “last in first out” “What does the stack do in the computers memory?” Java provides a Stack class in the util package Important operations  push (E e) // add item to the stack  pop() // take item off the top of the stack  peek() //get without removing  empty() // see if stack is empty  search(Object o) // returns position of object in stack Its interesting to note this class inherits from Vector Why use a stack, Good for reversing a series of operations Open 1 open 2 open 3 Now go back, undo [3]

8 Hash Table, (from the api) “This class implements a hashtable, which maps keys to values. Any non-null object can be used as a key or as a value.”

9 References [1] Cay Horstmann, Java Concepts, 5 th Edition, [2], [3],