CS 307 Fundamentals of Computer Science 1 Abstract Data Types many slides taken from Mike Scott, UT Austin.

Slides:



Advertisements
Similar presentations
Data Structures.
Advertisements

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.
Priority Queues. 2 Priority queue A stack is first in, last out A queue is first in, first out A priority queue is least-first-out The “smallest” element.
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.
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.
Java's Collection Framework
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.
SEG4110 – Advanced Software Design and Reengineering TOPIC G Java Collections Framework.
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.
Data Structures and Abstract Data Types "Get your data structures correct first, and the rest of the program will write itself." - David Jones.
Computer Science Department Data Structures and Algorithms Lecture 1.
Introduction to Data Structures Fall 2008 Dr. David A. Gaitros
Jan 12, 2012 Introduction to Collections. 2 Collections A collection is a structured group of objects Java 1.2 introduced the Collections Framework Collections.
PRESENTED BY: RAJKRISHNADEEPAK.VUYYURU SWAMYCHANDAN.DONDAPATI VINESHKUMARREDDY.LANKA RAJSEKHARTIRUMALA KANDURI ALAN.
Information and Computer Sciences University of Hawaii, Manoa
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.
1 Heaps and Priority Queues Starring: Min Heap Co-Starring: Max Heap.
Topic 24 Heaps "You think you know when you can learn, are more sure when you can write even more when you can teach, but certain when you can program."
Data structures Abstract data types Java classes for Data structures and ADTs.
Priority Queues Dr. David Matuszek
CSS446 Spring 2014 Nan Wang  Java Collection Framework ◦ LinkedList ◦ Set ◦ Map 2.
1/20/03A2-1 CS494 Interfaces and Collection in Java.
HIT2037- HIT6037 Software Development in Java 22 – Data Structures and Introduction.
ELC 310 Day 24. © 2004 Pearson Addison-Wesley. All rights reserved12-2 Agenda Questions? Problem set 5 Parts A & B Corrected  Good results  2 A’s, 1.
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 
Data Structures academy.zariba.com 1. Lecture Content 1.Linear Data Structures 2.Trees and Graphs* 3.Dictionaries and Hash Tables 4.Homework 2.
Collections Data structures in Java. OBJECTIVE “ WHEN TO USE WHICH DATA STRUCTURE ” D e b u g.
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.
Data Structures for Midterm 2. C++ Data Structure Runtimes.
Sets and Maps Sets Maps The Comparator Interface Sets and Maps in Java Collections API – TreeSet – TreeMap Review for Exam Reading:
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.
Abstract Data Type EnhanceEdu.
2 Obaid Ullah HOD Computer Science Dept. Superior University Sialkot Campus.
Week 15 – Wednesday.  What did we talk about last time?  Review up to Exam 1.
Introduction to Objects and Encapsulation Computer Science 4 Mr. Gerb Reference: Objective: Understand Encapsulation and abstract data types.
1 Principles revisited.NET: Two libraries: System.Collections System.Collections.Generics Data Structures and Collections.
Collections Dwight Deugo Nesa Matic
3-1 Java's Collection Framework Another use of polymorphism and interfaces Rick Mercer.
1 CS162: Introduction to Computer Science II Abstract Data Types.
Using the Java Collection Libraries COMP 103 # T2
G64ADS Advanced Data Structures
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
Efficiency of in Binary Trees
Map interface Empty() - return true if the map is empty; else return false Size() - return the number of elements in the map Find(key) - if there is an.
Topic 16 Queues Adapted from Mike Scott’s materials.
structures and their relationships." - Linus Torvalds
structures and their relationships." - Linus Torvalds
JAVA Collections Framework Set Interfaces & Implementations
- Alan Perlis Topic 24 Heaps "You think you know when you can learn,
Introduction to Computer Science for Majors II
Introduction to Data Structure
Data Structures II AP Computer Science
structures and their relationships." - Linus Torvalds
Abstract Data Types (ADTs)
Presentation transcript:

CS 307 Fundamentals of Computer Science 1 Abstract Data Types many slides taken from Mike Scott, UT Austin

CS 307 Fundamentals of Computer Science 2 Data Structures  Data structure is a representation of data and the operations allowed on that data.

CS 307 Fundamentals of Computer Science 3 Abstract Data Types  In Object Oriented Programming data and the operations that manipulate that data are grouped together in classes  Abstract Data Types (ADTs) or data structures or collections store data and allow various operations on the data to access and change it

CS 307 Fundamentals of Computer Science 4 Why Abstract?  Specify the operations of the data structure and leave implementation details to later –in Java use an interface to specify operations  many, many different ADTs –picking the right one for the job is an important step in design –"Get your data structures correct first, and the rest of the program will write itself." -Davids Johnson  High level languages often provide built in ADTs, –the C++ STL, the Java standard library

CS 307 Fundamentals of Computer Science 5 The Core Operations  Every Collection ADT should provide a way to: –add an item –remove an item –find, retrieve, or access an item  Many, many more possibilities –is the collection empty –make the collection empty –give me a sub set of the collection –and on and on and on…  Many different ways to implement these items each with associated costs and benefits

CS 307 Fundamentals of Computer Science 6 Implementing ADTs  when implementing an ADT the operations and behaviors are already specified –think Java interface  Implementer’s first choice is what to use as the internal storage container for the concrete data type –the internal storage container is used to hold the items in the collection –often an implementation of an ADT –initially slim pickings for choice of storage containers: arrays anyone?

CS 307 Fundamentals of Computer Science 7 The Grand Tour  Why study ADTs?  Why reimplement some of them?  How many of you will actually go out and create your own linked list ADT from scratch?  Remember, the primary goal is to learn how to learn how to use and create ADTs –also learn the behavior of some of the more conventional ADTs

CS 307 Fundamentals of Computer Science 8 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 307 Fundamentals of Computer Science 9 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 307 Fundamentals of Computer Science 10 Stacks  Collection with access only to the last element inserted  Last in first out  insert/push  remove/pop  top  make empty TopData4 Data3 Data2 Data1

CS 307 Fundamentals of Computer Science 11 Queues  Collection with access only to the item that has been present the longest  Last in last out or first in first out  enqueue, dequeue, front  priority queues and deque Data4Data3Data2Data1 Front Back

CS 307 Fundamentals of Computer Science 12 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 307 Fundamentals of Computer Science 13 Trees  Similar to a linked list public class TreeNode {private Object data; private TreeNode left; private TreeNode right; } Root

CS 307 Fundamentals of Computer Science 14 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 307 Fundamentals of Computer Science 15 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 307 Fundamentals of Computer Science 16 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 307 Fundamentals of Computer Science 17 The Java Collection Interface boolean isEmpty() int size() boolean add(Object x) boolean contains(Object x) boolean remove(Object x) void clear() Object[] toArray() Iterator iterator()

CS 307 Fundamentals of Computer Science 18 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 307 Fundamentals of Computer Science 19

CS 307 Fundamentals of Computer Science 20 Example - ArrayList