Data Structures and Abstract Data Types "Get your data structures correct first, and the rest of the program will write itself." - David Jones.

Slides:



Advertisements
Similar presentations
Transparency No. 1 Java Collection API : Built-in Data Structures for Java.
Advertisements

Data Structures.
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.
Computer Science 112 Fundamentals of Programming II Overview of Collections.
Working With Collections in the AP ™ Java Subset 2003 ACTE Convention © 2003 by Kenneth A. Lambert.
CS Data Structures II Review COSC 2006 April 14, 2017
CS 307 Fundamentals of Computer Science 1 Abstract Data Types many slides taken from Mike Scott, UT Austin.
Java Collections Framework COMP53 Oct 24, Collections Framework A unified architecture for representing and manipulating collections Allows collections.
Unit 11 1 Unit 11: Data Structures H We explore some simple techniques for organizing and managing information H This unit focuses on: Abstract Data Types.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Fall 2007CS 2251 Iterators and Tree Traversals. Fall 2007CS 2252 Binary Trees In a binary tree, each node has at most two subtrees A set of nodes T is.
CS 104 Introduction to Computer Science and Graphics Problems Data Structure & Algorithms (4) Data Structures 11/18/2008 Yang Song.
24-Jun-15 Introduction to Collections. 2 Collections A collection is a structured group of objects Java 1.2 introduced the Collections Framework Collections.
1 Data Structures  We can now explore some advanced techniques for organizing and managing information  Chapter 12 of the book focuses on: dynamic structures.
Data Structures & Java Collections Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Chapter 12 Collections. © 2004 Pearson Addison-Wesley. All rights reserved12-2 Collections A collection is an object that helps us organize and manage.
CS 307 Fundamentals of Computer Science ADTS and Generic Data Structures 1 Topic 12 ADTS, Data Structures, Java Collections and Generic Data Structures.
1 Frameworks Part 2. 2 Collections Framework Java API contains library of useful data structures Collections library also serves as framework for adding.
Java's Collection Framework
16-Aug-15 Air Force Institute of Technology Electrical and Computer Engineering Object-Oriented Programming in Java Topic : Interfaces, Copying/Cloning,
C o n f i d e n t i a l Developed By Nitendra NextHome Subject Name: Data Structure Using C Title: Overview of Data Structure.
1 Collection, Iterable, and Iterator Interfaces The Collection Interface and its Hierarchy The Iterable and Iterator Interfaces For-each Loops with Iterable.
SEG4110 – Advanced Software Design and Reengineering TOPIC G Java Collections Framework.
Java Collections Framework A presentation by Eric Fabricant.
Sets and Maps Part of the Collections Framework. The Set interface A Set is unordered and has no duplicates Operations are exactly those for Collection.
FEN 2012UCN Technology - Computer Science 1 Data Structures and Collections Principles revisited.NET: –Two libraries: System.Collections System.Collections.Generics.
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.
Collections in Java. Kinds of Collections Collection --a group of objects, called elements –Set-- An unordered collection with no duplicates SortedSet.
Computer Science Department Data Structures and Algorithms Lecture 1.
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
Data structures and algorithms in the collection framework 1 Part 2.
Big Java Chapter 16.
Data Design and Implementation. Definitions of Java TYPES Atomic or primitive type A data type whose elements are single, non-decomposable data items.
Data structures Abstract data types Java classes for Data structures and ADTs.
1/20/03A2-1 CS494 Interfaces and Collection in Java.
HIT2037- HIT6037 Software Development in Java 22 – Data Structures and Introduction.
Chapter 12: Collections by Lewis and Loftus (Updated by Dan Fleck) Coming up: Collections.
Elementary Data Organization. Outline  Data, Entity and Information  Primitive data types  Non primitive data Types  Data structure  Definition 
Collections Data structures in Java. OBJECTIVE “ WHEN TO USE WHICH DATA STRUCTURE ” D e b u g.
SETS AND MAPS Collections of Data. Advanced Data Structures Often referred to as the Java Collections Framework…. Set and map data types Hash tables Binary.
Ordered Linked Lists using Abstract Data Types (ADT) in Java Presented by: Andrew Aken.
Data Structures Chapter 6. Data Structure A data structure is a representation of data and the operations allowed on that data. Examples: 1.Array 2.Record.
Week 2 - Friday.  What did we talk about last time?  Computing Big Oh.
Copyright (c) Systems and Computer Engineering, Carleton University * Object-Oriented Software Development Unit 13 The Collections Framework.
2 Obaid Ullah HOD Computer Science Dept. Superior University Sialkot Campus.
IMPLEMENTING ARRAYLIST COMP 103. RECAP  Comparator and Comparable  Brief look at Exceptions TODAY  Abstract Classes - but note that the details are.
Sets and Maps Part of the Collections Framework. 2 The Set interface A Set is unordered and has no duplicates Operations are exactly those for Collection.
CS-2852 Data Structures LECTURE 2 Andrew J. Wozniewicz Image copyright © 2010 andyjphoto.com.
Introduction to Objects and Encapsulation Computer Science 4 Mr. Gerb Reference: Objective: Understand Encapsulation and abstract data types.
JAVA COLLECTIONS LIBRARY School of Engineering and Computer Science, Victoria University of Wellington COMP T2, Lecture 2 Marcus Frean.
Collections Dwight Deugo Nesa Matic
Object Oriented Programming in Java Habib Rostami Lecture 7.
3-1 Java's Collection Framework Another use of polymorphism and interfaces Rick Mercer.
 2016, Marcus Biel, ArrayList Marcus Biel, Software Craftsman
1 CS162: Introduction to Computer Science II Abstract Data Types.
Using the Java Collection Libraries COMP 103 # T2
Set Collection A Bag is a general collection class that implements the Collection interface. A Set is a collection that resembles a Bag with the provision.
Fundamentals of Programming II Overview of Collections
Cinda Heeren / Geoffrey Tien
structures and their relationships." - Linus Torvalds
structures and their relationships." - Linus Torvalds
JAVA Collections Framework Set Interfaces & Implementations
Collections Framework
Data Structures II AP Computer Science
structures and their relationships." - Linus Torvalds
Abstract Data Types (ADTs)
Presentation transcript:

Data Structures and Abstract Data Types "Get your data structures correct first, and the rest of the program will write itself." - David Jones

Abstract Data Types  Abstract Data Types (aka ADTs) are descriptions of how a data type will work without implementation details  Description can be a formal, mathematical description  Java interfaces are a form of ADTs –some implementation details start to creep in CS Computer Science II

Data Structures  A Data Structure is: –an implementation of an abstract data type and –"An organization of information, usually in computer memory", for better algorithm efficiency." aList List Object size myElements 5 A C E B A

CS Computer Science II Data Structure Concepts  Data Structures are containers: –they hold other data –arrays are a data structure –... so are lists  Other types of data structures: –stack, queue, tree, binary search tree, hash table, dictionary or map, set, and on and on –en.wikipedia.org/wiki/List_of_data_structuresen.wikipedia.org/wiki/List_of_data_structures  Different types of data structures are optimized for certain types of operations

CS Computer Science II Core Operations  Data Structures have three core operations –a way to add things –a way to remove things –a way to access things  Details of these operations depend on the data structure –Example: List, add at the end, access by location, remove by location  More operations added depending on what data structure is designed to do

Implementing ADTs  When implementing an ADT, the operations and behaviors are already specified –think Java interface  But what use as the internal storage container for the concrete data type? –the internal storage container is used to hold the items in the collection –initially slim pickings for choice of storage containers: arrays anyone? –later add linked structures –now often an implementation of an ADT (which use arrays or linked structures) CS Computer Science II

Bags and Sets  Simplest ADT is a Bag –items can be added, removed, accessed –no implied order to the items –duplicates allowed  Set –same as a bag, except duplicate elements not allowed –union, intersection, difference, subset CS Computer Science II

Lists  Items have a position in this Collection –Random access or not?  Array Lists –internal storage container is native array  Linked Lists public class Node {private Object data; private Node next; } first last CS Computer Science II

Stacks  Collection with access only to the last element inserted –Last in first out –push (insert) –pop (remove) –peek (top item) –make empty TopData4 Data3 Data2 Data1 CS Computer Science II

Queues  Collection with access only to the item that has been present the longest –first in,first out or last in, last out –enqueue (insert) –dequeue (remove) –front Data4Data3Data2Data1 Front Back CS Computer Science II

Stacks and Queues in the Java Collection API  No queue in the Java collections ADT  Stack extends Vector (which is almost exactly like ArrayList) –Hmmm?  One reason the Java Collections Library is often said to be broken  no Queue in Collection API CS Computer Science II

Trees  Similar to a linked list public class TreeNode {private Object data; private TreeNode left; private TreeNode right; } Root CS Computer Science II

Other Types of Trees  Binary Search Trees –sorted values  Heaps –sorted via a different algorithm  AVL and Red-Black Trees –binary search trees that stay balanced  Splay Trees  B Trees CS Computer Science II

HashTables  Take a key, apply function  f(key) = hash value  store data or object based on hash value  Sorting O(N), access O(1) if a perfect hash function and enough memory for table  How deal with collisions? CS Computer Science II

Other ADTs  Maps –a.k.a. Dictionary –Collection of items with a key and associated values –similar to hash tables, and hash tables often used to implement Maps  Graphs –Nodes with unlimited connections between other nodes  Sparse vectors and sparse matrices CS Computer Science II

Generic Containers  ADTs or Collection classes should be generic –only write them once, hold lots or all types of data –Java achieves genericity through inheritance and polymorphism  ADTs have an internal storage container –What is storing the stuff, –implementation vs. abstraction –in Java, usually holds Objects. Why? CS Computer Science II

ADTs and Data Structures in Programming Languages  Modern programming languages usually have a library of data structures –Java collections frameworkJava collections framework –C++ standard template libraryC++ standard template library –.Net framework (small portion of VERY large library).Net framework –Python lists and tuples –Lisp lists

CS Computer Science II Data Structures in Java  Part of the Java Standard Library is the Collections Framework –In class we will create our own data structures and discuss the data structures that exist in Java  A library of data structures  Built on two interfaces –Collection –Iterator  ections/index.html ections/index.html

CS Computer Science II The Java Collection Interface  A generic collection  Can hold any object data type  Which type a particular collection will hold is specified when declaring an instance of a class that implements the Collection interface  Helps guarantee type safety at compile time

CS Computer Science II Methods in the Collection interface public interface Collection {public boolean add(E o) public boolean addAll(Collection c) public void clear() public boolean contains(Object o) public boolean containsAll(Collection c) public boolean equals(Object o) public int hashCode() public boolean isEmpty() public Iterator iterator() public boolean remove(Object o) public boolean removeAll(Collection c) public boolean retainAll(Collection c) public int size() public Object[] toArray() public T[] toArray(T[] a) }

CS Computer Science II The Java ArrayList Class  Implements the List interface and uses an array as its internal storage container  It is a list, not an array  The array that actual stores the elements of the list is hidden, not visible outside of the ArrayList class  All actions on ArrayList objects are via the methods  ArrayLists are generic. –They can hold objects of any type!

CS Computer Science II ArrayList's (Partial) Class Diagram AbstractCollection Object AbstractList ArrayList Iterable Collection List

ArrayList Specification