6.170 Recitation Godfrey Tan.

Slides:



Advertisements
Similar presentations
Data Abstraction II SWE 619 Software Construction Last Modified, Spring 2009 Paul Ammann.
Advertisements

Graphs Chapter 12. Chapter Objectives  To become familiar with graph terminology and the different types of graphs  To study a Graph ADT and different.
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
Fall 2007CS 2251 Graphs Chapter 12. Fall 2007CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs To.
Graphs Chapter 28 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Cs2220: Engineering Software Class 8: Implementing Data Abstractions Fall 2010 University of Virginia David Evans.
1 Linked-list, stack and queue. 2 Outline Abstract Data Type (ADT)‏ Linked list Stack Queue.
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.
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
90-723: Data Structures and Algorithms for Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 7: Graphs Data Structures.
David Evans CS201J: Engineering Software University of Virginia Computer Science Lecture 7: A Tale of Two Graphs (and.
3-1 Java's Collection Framework Another use of polymorphism and interfaces Rick Mercer.
UNIT-V ABSTRACT DATA TYPE 1.LIST 2.STACK 3.QUEUE EC6301-II-ECE-C.
Collections ABCD ABCD Head Node Tail Node array doubly linked list Traditional Arrays and linked list: Below is memory representation of traditional.
Graphs A New Data Structure
Using the Java Collection Libraries COMP 103 # T2
Data Structures and Design in Java © Rick Mercer
CSE 214 – Computer Science II Maps
Linked List :: Basic Concepts
Fundamentals of Programming II Overview of Collections
CS2006- Data Structures I Chapter 5 Linked Lists I.
Priority Queues and Heaps
The LAST Recitation Godfrey Tan.
CSE373: Data Structures & Algorithms Lecture 13: Topological Sort / Graph Traversals Kevin Quinn Fall 2015.
Data Structures Data Structure is a way of collecting and organising data in such a way that we can perform operations on these data in an effective.
Csc 2720 Instructor: Zhuojun Duan
Array Array is a variable which holds multiple values (elements) of similar data types. All the values are having their own index with an array. Index.
Efficiency add remove find unsorted array O(1) O(n) sorted array
Chapter 22 : Binary Trees, AVL Trees, and Priority Queues
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.
Common final examinations
structures and their relationships." - Linus Torvalds
Hash table another data structure for implementing a map or a set
Data Structures and Algorithms for Information Processing
abstract containers sequence/linear (1 to 1) hierarchical (1 to many)
abstract containers sequence/linear (1 to 1) hierarchical (1 to many)
Lesson 6. Types Equality and Identity. Collections.
Copyright ©2012 by Pearson Education, Inc. All rights reserved
Lectures on Graph Algorithms: searching, testing and sorting
Graphs.
Iteration Abstraction
SWE 619 Software Construction Last Modified, Fall 2015 Paul Ammann
Graphs Part 2 Adjacency Matrix
A Robust Data Structure
Lecture 7: A Tale of Two Graphs CS201j: Engineering Software
Graphs.
(2,4) Trees 2/15/2019 (2,4) Trees (2,4) Trees.
Chapter 14 Graphs © 2006 Pearson Addison-Wesley. All rights reserved.
Introduction to Data Structure
1.4 ทบทวน JAVA OO Programming Concepts Declaring and Creating Objects
Graphs.
GRAPHS G=<V,E> Adjacent vertices Undirected graph
abstract containers sequence/linear (1 to 1) hierarchical (1 to many)
Graphs.
Graphs.
The Greedy Approach Young CS 530 Adv. Algo. Greedy.
Graphs.
Chapter 14 Graphs © 2011 Pearson Addison-Wesley. All rights reserved.
Copyright ©2012 by Pearson Education, Inc. All rights reserved
GRAPHS Lecture 17 CS 2110 — Spring 2019.
Software Design Lecture : 39.
Graphs.
Lists CMSC 202, Version 4/02.
Lists CMSC 202, Version 4/02.
Lecture 10 Graph Algorithms
17CS1102 DATA STRUCTURES © 2018 KLEF – The contents of this presentation are an intellectual and copyrighted property of KL University. ALL RIGHTS RESERVED.
structures and their relationships." - Linus Torvalds
Lecture 3 – Data collection List ADT
Abstract Data Types and Stacks
Presentation transcript:

6.170 Recitation Godfrey Tan

Announcements Quiz 1 Review Problem Set 3 Quiz 1 (L1-L10): Sunday, March 3, 7:30pm, 34-101 Problem Set 3 Tuesday, March 5 Quiz 1 (L1-L10): Wednesday, March 6 during class Locations 54-100 for usernames a*-j* 34-101 for usernames k*-z* Open book, but it is a short quiz!

Graph Basics Node Edge Nodes are connected via Edges Station: id, name Edge Line: type, (in station, out station) Nodes are connected via Edges Graph is a collection of nodes and edges

Graph Requirements Directed Multi-graph Dynamic: add and remove nodes Flexible: works for other applications

Graph Operations addNode, containsNode addEdge, containsEdge Traversal Predecessors, successors

Graph Implementation Centralized Distributed Graph stores everything May or may not require Node class Distributed Graph stores Nodes Node stores Edges

Storing Nodes and Edges Adjacency lists Nodes IN Edges, Out Edges for each Node Adjacency matrices Two dimensional arrays HashMap Stores (key, value)

Traversal Depth first search Breadth first search Operations Mark: found, visited Visit

Inputs and outputs Input: Harvard Alewife Output: [Harvard(14), Porter(10), Davis(7), Alewife(8)]

Abstract Data Type: What? Abstraction by specification Operations (T = abstract type, t = some other type) Constructors: t  T Producers: T, t  T Mutators: T, t  void Observers: T, t  t Designing an Abstract Type Few, simple operations that can be combined in powerful ways Operations should have well-defined purpose, coherent behavior Set of operations should be adequate

Abstract Data Type: Why? Allows us to: abstract from the details of how data objects are implemented how they behave defer decisions about the data structures Interface to users is via operations; changes made to representation does not affect the operations You can change the structures late in the game

Implementing an ADT Select the rep (representation of instances) Implement operations in terms of that rep

Rep Data structure plus Set of conventions defined by rep invariant abstraction function

A Rep example We want a representation of a list of 3 integers sorted in ascending order [ x1, x2, x3 ] where x1 <= x2 <= x3

Sorted List class SortedList { Vector v; Integer foo; // requires: a <= b <= c public SortedListA(Integer a, Integer b, Integer c) { v = new Vector(); foo = new Integer(666); v.add(a); v.add(foo); v.add(b); v.add(foo); v.add(c); v.add(foo); }… }

Rep Data structure plus Set of conventions defined by rep invariant abstraction function What is the data structure for SortedList?

Rep Data structure plus Set of conventions defined by rep invariant abstraction function What is the data structure for SortedList? Vector

Abstraction Function What is the abstraction function?

Abstraction Function What is the abstraction function? Mapping from vector elements to abstract values [ v[0], v[2], v[4] ] maps to [ x1, x2, x3 ]

Is this implementation necessarily wrong? class SortedList { Vector v; Integer foo; // requires: a <= b <= c public SortedListA(Integer a, Integer b, Integer c) { v = new Vector(); foo = new Integer(666); v.add(b); v.add(foo); v.add(a); v.add(foo); v.add(c); v.add(foo); }… }

Abstraction Function Just redefine the abstraction function! [ v[2], v[0], v[4] ] maps to [ x1, x2, x3 ] Abstraction function defines the convention or the way we interpret the underlying data structure for the abstraction it represents.

Representation Invariant If I decide that my representation invariant is the following: v != null && v.size() == 6 && all elements in v are Integers && foo == Integer(666) Then all operations: constructors, producers, mutators, observers MUST maintain this property!!!

Representation Invariant If I decide that my representation invariant is the following: v != null && v.size() == 6 && all elements in v are Integers && foo == Integer(666) Suppose I take out the last clause, then what does this imply? Then the operators: the constructors, producers, mutators, observers cannot always expect foo == Integer(666) in their implementation!

Representation Invariant The idea behind Representation Invariant is to allow the implementation of each operation to agree on a set of assumptions about the data structure!

Quiz 1 Questions? Good luck on the quiz!