abstract data types

34
Abstract Data Types Reggie Santos UP ITDC Content mostly adapted from Mike Scott, UT Austin

Upload: reggie-niccolo-santos

Post on 05-Dec-2014

285 views

Category:

Software


1 download

DESCRIPTION

* Definition of ADT * Set * List * Stack * Queue * Map * Tree * Graph

TRANSCRIPT

Abstract Data TypesReggie Santos

UP ITDC Content mostly adapted from Mike Scott, UT Austin

Outline

Definition of ADT

Set

List

Stack

Outline

Queue

Map

Tree

Graph

Abstract Data Type (ADT)

Stores data

Allows various operations on the data to access or change it

Why Abstract?

Specify the operations of the data structure and leave implementation details for later

High-level languages often provide built-in data structures

The Core Operations

Every Collection ADT should provide a way to:

Add an item

Remove an item

Find, retrieve, or access an item

Additional Operations

More possibilities:

Is the collection empty?

Make the collection empty

Give a subset of the collection

–David Jones

“Get your data structures correct first, and the rest of the program

will write itself.”

Program Logic Formulation

Image credit: Ledork via flickr Creative Commons

Set

Unordered collection of data items

No duplicate items are allowed

Image credit: pasukaru76 via flickr Creative Commons

Image credit: Stacy Spensley via flickr Creative Commons

List

Ordered collection of data items

Order is important

Image credit: Frances Dinkelspiel via flickr Creative Commons

By Zzubnik (Own work) [CC-BY-3.0 (http://creativecommons.org/licenses/by/3.0)], via Wikimedia Commons

Stack

Ordered collection of data items

LIFO (Last In First Out)

Only the element at the top may be accessed at any point in time

Stack

Core operations:

push(x)

pop(x)

Stack

Image credit: Toyhouse.cc Creative Commons

Image credit: gadl via flickr

Queue

Ordered collection of data items

FIFO (First In First Out)

Inserts an element at the rear and ejects an element from the front

Queue

Core operations:

enqueue(x) - at rear

dequeue(x) - from front

Queue

By Choon Boo LIM Creative Commons

By Wilton Scout Group Creative Commons

MapCollection of key-value pairs

Also called a:

Hashtable

Dictionary

Symbol table

Associative array

Map

By John Gasson Creative Commons

By intotheforest via Flickr Creative Commons

By Da Pino Creative Commons

Tree

Collection of nodes (starting at a root node) where each node contains a data value and a list of references to other nodes, with the constraints that no reference is duplicated, and none points to the root

Tree

By Claudio Rocchini (Own work) [GFDL, CC-BY-SA-3.0, CC-BY-SA-2.5], via Wikimedia Commons

By Vector Fresh Creative Commons

Graph

Finite set of ordered pairs, called edges or arcs, of certain entities called nodes or vertices

An edge (x, y) is said to point or go from x to y

Graph

Summary

Definition of ADT

Set

List

Stack

Summary

Queue

Map

Tree

Graph

ReferencesMike Scott’s set of slides, University of Texas Austin

Wikipedia

For images:

Wikimedia Commons

Flickr