CS 261 - Winter 2011 Abstract Data Types. Container Classes Over the years, programmers have identified a small number of different ways of organizing.

Slides:



Advertisements
Similar presentations
CS Winter 2010 Linked Lists - Part 2 Deque with Double Links and Sentinel, Bag.
Advertisements

Computer Science 112 Fundamentals of Programming II Overview of Collections.
Stacks and Queues. 2 Stack and Queue ADT’s You should understand How are they different philosophically from arrays What are they used for How do you.
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.
Stacks. What is a stack? Last-in first-out data structure (LIFO) New objects are placed on top Removal restricted to top object Examples?
CS 307 Fundamentals of Computer Science 1 Abstract Data Types many slides taken from Mike Scott, UT Austin.
CS Winter 2011 Further Introduction to the C programming language.
Stacks.
1 Data Structures  We can now explore some advanced techniques for organizing and managing information  Chapter 12 of the book focuses on: dynamic structures.
Priority Queues. 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.
Priority Queues. 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.
Chapter 12 C Data Structures Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
COMP 110 Introduction to Programming Mr. Joshua Stough.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 12 – Data Structures Outline 12.1Introduction.
1 ES 314 Advanced Programming Lec 2 Sept 3 Goals: Complete the discussion of problem Review of C++ Object-oriented design Arrays and pointers.
Chapter 24 Dispensers and dictionaries. This chapter discusses n Dictionaries n Dispensers u stacks u queues u priority queues.
© 2004 Pearson Addison-Wesley. All rights reserved12-1 Chapter 12 : Collections Intermediate Java Programming Summer 2007.
Data Structures Data structures permit the storage of related data for use in your program. –Arrays.
Lists, Stacks, Queues Svetlin Nakov Telerik Corporation
1 HEAPS & PRIORITY QUEUES Array and Tree implementations.
Copyright © Wondershare Software Introduction to Data Structures Prepared by: Eng. Ahmed & Mohamed Taha.
Chapter 12 Data Structure Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
1 Hash Tables  a hash table is an array of size Tsize  has index positions 0.. Tsize-1  two types of hash tables  open hash table  array element type.
Data Structures Winter What is a Data Structure? A data structure is a method of organizing data. The study of data structures is particularly important.
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.
Lecture 10: Class Review Dr John Levine Algorithms and Complexity March 13th 2006.
Introduction to Data Structures Fall 2008 Dr. David A. Gaitros
TECH Computer Science Data Abstraction and Basic Data Structures Improving efficiency by building better  Data Structure Object IN  Abstract Data Type.
Jan 12, 2012 Introduction to Collections. 2 Collections A collection is a structured group of objects Java 1.2 introduced the Collections Framework Collections.
Chapter 7 Stacks. © 2004 Pearson Addison-Wesley. All rights reserved 7-2 The Abstract Data Type: Developing an ADT During the Design of a Solution Specifications.
Cosc237/data structures1 Data Types Every data type has two characteristics: 1.Domain - set of all possible values 2.set of allowable operations Built-in.
Data Structures (part 2). Stacks An Everyday Example Your boss keeps bringing you important items to deal with and keeps saying: “Put that last ‘rush’
Data structures Abstract data types Java classes for Data structures and ADTs.
CS261 Data Structures Ordered Bag Dynamic Array Implementation.
CS261 – Data Structures Iterator ADT Dynamic Array and Linked List.
Chapter 12: Collections by Lewis and Loftus (Updated by Dan Fleck) Coming up: Collections.
Stacks The content for these slides was originally created by Gerard Harrison. Ported to C# by Mike Panitz.
EASTERN MEDITERRANEAN UNIVERSITY Stacks EENG212 –Algorithms and Data Structures.
Data Structures Stack Namiq Sultan 1. Data Structure Definition: Data structures is a study of different methods of organizing the data and possible operations.
1 Linked-list, stack and queue. 2 Outline Abstract Data Type (ADT)‏ Linked list Stack Queue.
Introduction to the Standard Template Library (STL) A container class holds a number of similar objects. Examples: –Vector –List –Stack –Queue –Set –Map.
CS261 Data Structures Maps (or Dictionaries). Goals Introduce the Map(or Dictionary) ADT Introduce an implementation of the map with a Dynamic Array.
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.
CS 261 Fall 2009 Dynamic Array Introduction (aka Vector, ArrayList)
Week 2 - Friday.  What did we talk about last time?  Computing Big Oh.
Introduction to Collections. Collections Collections provide a way of organizing related data in a model Different types of collections have different.
Data-structure-palooza Checkout DataStructures from SVN.
Abstract Data Types and Stacks CSE 2320 – Algorithms and Data Structures Vassilis Athitsos University of Texas at Arlington 1.
C++ Review STL CONTAINERS.
CS-2851 Dr. Mark L. Hornick 1 Stacks and Queues Behavior vs. Structure.
CS Fall 2009 Linked List Introduction. Characteristics of Linked Lists Elements are held in objects termed Links Links are 1-1 with elements, allocated.
Abstract Data Types and Stacks CSE 2320 – Algorithms and Data Structures Vassilis Athitsos University of Texas at Arlington Last updated: 2/17/
Linked List Introduction
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.
Stacks The content for these slides was originally created by Gerard Harrison. Ported to C# by Mike Panitz.
Hassan Khosravi / Geoffrey Tien
Cinda Heeren / Geoffrey Tien
structures and their relationships." - Linus Torvalds
Abstract Data Types (ADTs)
Stack ADT & Modularity 2 implementations of the Stack abstract data type: Array Linked List Program design: modularity, abstraction and information hiding.
structures and their relationships." - Linus Torvalds
Abstract Data Type Abstract Data Type as a design tool
Abstract Data Types and Stacks
Introduction to Data Structure
Dynamic Array: Implementation of Stack
structures and their relationships." - Linus Torvalds
Abstract Data Types (ADTs)
Abstract Data Types and Stacks
Presentation transcript:

CS Winter 2011 Abstract Data Types

Container Classes Over the years, programmers have identified a small number of different ways of organizing collections of data. These container abstractions are now the fundamental heart of the study of data structures. Examples, Stack, Queue, Set, Map, etc

Three Levels of Abstraction There are at least three levels of abstraction in the study of data structures ADT - Abstract Data Type, language independent Interface - the interface in a particular library of containers Implementation - the various implementations in a particular library

The ADT view (Abstract Data Type) Every data type can be described in a way that is independent of language/library E.G., A Stack is a collection that has the property that an item removed is the most recently entered item. Properties that are true regardless of the names given to operations in library

Metaphors ADT view are often described by metaphors (e.g., stack of plates). Easy to remember. Easy to understand.

The Interface View Gives specific names to operations struct stack; void initStack (struct stack * stk); void pushStack (struct stack * stk, double val); double topStack (struct stack * stk); void popStack (struct stack * stk); int isEmptyStack (struct stack * stk);

Additional Information The interface view gives only signatures Must also attach meanings (LIFO properties of stack, etc) Can also attach expected execution times (want push and pop to be constant time). Both more and less informative than ADT view

The Implementation View void pushStack (struct stack * stk, double val) { stk->data.add(val); } int stackIsEmpty (struct stack * stk) { return dyArraySize(stk->data) == 0: }

The Study of Data Structures As we study data structures we move constantly between all three views The ADT view is constant from one language to the next The interface view allows you to compare implementations The implementation allows you to see how it is done

The Classic ADTs Bag, Ordered Bag - simple collections Stack, Queue, Deque - ordered by insertion Set - unique elements, fast test Map (Dictionary) - key/value associations Priority Queue - ordered by importance

BAG as Design Pattern Problem: Need to maintain an unordered collection of elements, without needing to know how it is organized Forces: Require insertion, test and removal - time of insertion is unimportant Counter-forces: Time of insertion IS important Solution: Provide abstract interface

BAG interface Provide functions for operations, effectively hiding implementation (names may vary) addBag (container, value) testBag (container, value) removeBag (container, value) sizeBag (container, value)

Stack as Design Pattern Problem: Maintain collection in Last-In, First-Out format Forces: LIFO Counter-forces: non-LIFO Solution: again, abstract Stack interface

The Classic Implementation Techniques Arrays and Dynamic Arrays (Vectors) Linked Lists Binary Trees, Balanced Trees Heaps Hash Tables Skip Lists Etc etc etc

Now, your first worksheet As a way to introduce C and the worksheet idea, we will make implementations of a simple BAG and STACK using an array We will do these together, in class - won’t always be that way Worksheets are handed in, and are lightly graded.

First look at C - interface file # define EleType double # define EQ(a, b) (a == b) struct arrayBag { EleType data[100]; int count; }; void initBag (struct arrayBag * b); … etc

First function - initialize void initBag (struct arrayBag * b) { }

Add to bag void addBag (struct arrayBag * b, EleType v) { }

Test for contains int testBag (struct arrayBag * b, EleType v) { }

Remove from bag void removeBag (struct arrayBag * b, EleType v) { }

Return size of collection int bagSize (struct arrayBag * b) { }

How about stack? void pushStack (struct arrayBag * b, EleType v) { }

Test for stack empty int isStackEmpty (struct arrayBag * b) { }

Top of stack EleType topStack (struct arrayBag * b) { }

Pop top element void popStack (struct arrayBag * b) { }

That’s all for today Hand in your worksheets, put your name on them