Relation Discrete Mathematics and Its Applications Baojian Hua

Slides:



Advertisements
Similar presentations
Linked Lists.
Advertisements

CSCE 3110 Data Structures & Algorithm Analysis
C and Data Structures Baojian Hua
Singly Linked List BTECH, EE KAZIRANGA UNIVERSITY.
Data Structure & Abstract Data Type
C Module System C and Data Structures Baojian Hua
Data Structure & Abstract Data Type C and Data Structures Baojian Hua
Elementary Data Structures: Part 2: Strings, 2D Arrays, Graphs
Abstract Syntax Tree Discrete Mathematics and Its Applications Baojian Hua
Foundation of Computing Systems Lecture 2 Linked Lists.
Extensible Array C and Data Structures Baojian Hua
ITEC200 – Week 12 Graphs. 2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study.
Map, Set & Bit-Vector Discrete Mathematics and Its Applications Baojian Hua
Queue C and Data Structures Baojian Hua
Stack C and Data Structures Baojian Hua
Dynamically Extensible Data Structures Discrete Mathematics and Its Applications Baojian Hua
Binary Search Tree C and Data Structures Baojian Hua
Breath First Searching & Depth First Searching C and Data Structures Baojian Hua
1 Graph Representations. 2 Graph Representation zHow can I represent the above graph? A B C D E F
String C and Data Structures Baojian Hua
Graph C and Data Structures Baojian Hua
Stack C and Data Structures Baojian Hua
C and Data Structures Baojian Hua
Graph C and Data Structures Baojian Hua
Hash Discrete Mathematics and Its Applications Baojian Hua
Queue C and Data Structures Baojian Hua
Extensible Array C and Data Structures Baojian Hua
Extensible Array C and Data Structures Baojian Hua
Linked List C and Data Structures Baojian Hua
Tree C and Data Structures Baojian Hua
Set, Map & Bit-Vector Discrete Mathematics and Its Applications Baojian Hua
Functional List C and Data Structures Baojian Hua
String C and Data Structures Baojian Hua
String C and Data Structures Baojian Hua
Graph Traversal Discrete Mathematics and Its Applications Baojian Hua
Set & Bit-Vector Discrete Mathematics and Its Applications Baojian Hua
Graph Discrete Mathematics and Its Applications Baojian Hua
Introduction to C Programming CE Lecture 19 Linear Linked Lists.
Hash C and Data Structure Baojian Hua
Automata and Regular Expression Discrete Mathematics and Its Applications Baojian Hua
Graph Implementations Chapter 31 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Polymorphism Discrete Mathematics and Its Applications Baojian Hua
Binary Search Tree C and Data Structures Baojian Hua
Graph Traversal C and Data Structures Baojian Hua
Multi-Dimensional Arrays in Java "If debugging is the process of removing software bugs, then programming must be the process of putting them in." -- Edsger.
1 Chapter 16-1 Linked Structures Dale/Weems. 2 Chapter 16 Topics l Meaning of a Linked List l Meaning of a Dynamic Linked List l Traversal, Insertion.
Trees By Charl du Plessis. Contents Basic Terminology Basic Terminology Binary Search Trees Binary Search Trees Interval Trees Interval Trees Binary Indexed.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs.
Data Structure Sang Yong Han Chung-Ang University Spring
Data Structures & Algorithm Analysis Arrays. Array: a set of pairs (index and value) data structure For each index, there is a value associated with that.
Data Structures Lecture 1: Introduction. Course Contents Data Types   Overview, Introductory concepts   Data Types, meaning and implementation  
1 Chapter 16 Linked Structures Dale/Weems/Headington.
APS105 Lists. Structures Arrays allow a collection of elements –All of the same type How to collect elements of different types? –Structures; in C: struct.
Hash C and Data Structure Baojian Hua
ENEE150 – 0102 ANDREW GOFFIN Project 4 & Function Pointers.
Graphs A graphs is an abstract representation of a set of objects, called vertices or nodes, where some pairs of the objects are connected by links, called.
Polymorphism Discrete Mathematics and Its Applications Baojian Hua
1 Directed Graphs Chapter 8. 2 Objectives You will be able to: Say what a directed graph is. Describe two ways to represent a directed graph: Adjacency.
Abstract Data Types and Stacks CSE 2320 – Algorithms and Data Structures Vassilis Athitsos University of Texas at Arlington 1.
Extensible Tree Discrete Mathematics and Its Applications Baojian Hua
Lecture 16 Linked Lists. In this lecture Fundamentals Applications Memory Allocation Creating a List Inserting Nodes.
114 3/30/98 CSE 143 Collection ADTs [Chapter 4] /30/98 Collection ADTs  Many standard ADTs are for collections  Data structures that manage groups.
Implementing Queues Eric Roberts CS 106B February 13, 2013.
1 ARRAYS AND STRUCTURES. 2 Arrays Array: a set of index and value data structure For each index, there is a value associated with that index. representation.
Abstract Data Types and Stacks CSE 2320 – Algorithms and Data Structures Vassilis Athitsos University of Texas at Arlington Last updated: 2/17/
Linked List :: Basic Concepts
What remains Topics Assignments Final exam
Discrete Mathematics and
Discrete Mathematics and
Discrete Math 2 Shortest Path Using Matrix
Presentation transcript:

Relation Discrete Mathematics and Its Applications Baojian Hua

Relation ADT A relation is a triple (A, B, R) A and B are two sets R \supset A*B Typical operations: relation creation search a vertex (or an edge) traverse all vertexes …

Example G = (A, B, R) A=B= {1, 2, 3, 4, 5, 6} R = {(1, 2), (2, 5), (3, 5), (3, 6), (4, 1), (4, 2), (5, 4), (6, 6)}

Representation Two popular strategies: array-based (adjacency matrix) Keep an extensible two-dimensional array M internally M[i][j] holds the relation info ’ of, if there exists one a generalization of the 0-1 matrix linear list-based (adjacency list) for every vertex vi, maintain a linear list list list stores vi ’ s outing edges Not the focus of this slide, we ’ d discuss this in later slides

Adjacency Matrix # # ## ## # # Note the hash function: hash (n) = n-1

Adjacency List >2 3->53->6 5 4->1 6 2->5 4->2 5->4 6->6 Notice the pointers!

Graph in C

“ relation ” ADT in C: Interface // in file “relation.h” #ifndef RELATION_H #define RELATION_H typedef struct relationStruct *relation; relation newRelation (); void insertElem (relation r, poly data); void insertPair (relation r, poly from, poly to); // more to come later … #endif

Relation Implementation #1: Adjacency Matrix // adjacency matrix-based implementation #include “matrix.h” #include “hash.h” #include “relation.h” struct relationStruct { matrix matrix; int rows; int columns; // remember the index hash hashTable; }; ###

Matrix Interface // file “matrix.h” #ifndef MATRIX_H #define MATRIX_H typedef struct matrixStruct *matrix; matrix newMatrix (); void matrixInsert (matrix m, int i, int j); int matrixExtend (matrix m); #endif // Implementation could make use of a two- // dimensional extensible array, leave to you.

Adjacency Matrix-based: Relation Creation relation newRelation () { relation r = malloc (sizeof (*r)); r->matrix = newMatrix (); // an empty matrix r->rows = 0; r->columns = 0; g->hash = newHash (); return g; }

Adjacency Matrix-based: Inserting Element void insertElem (relation r, poly data) { int i = matrixExtend (r->matrix); hashInsert (r->hash, data, i); return; } ### ### 4 4

Relation Implementation #1: Inserting Pairs void insertPair (relation r, poly from, poly to) { int f = hashLookup (g->hash, from); int t = hashLookup (g->hash, to); matrixInsert (g->matrix, f, t); return; } ### #### 4 4

Client Code relation r = newRelation (); insertElem (r, 1); insertElem (r, 2); … insertElem (r, 6); insertPair (r, 1, 2); insertPair (r, 2, 5); … insertPair (r, 6, 6);