Data Structures in Java. Session 16 Instructor: Bert Huang

Similar documents
Data Structures in Java. Session 15 Instructor: Bert Huang

Cpt S 223. School of EECS, WSU

Social Media Mining. Graph Essentials

Analysis of Algorithms, I

Data Structures and Algorithms Written Examination

DATA ANALYSIS II. Matrix Algorithms

V. Adamchik 1. Graph Theory. Victor Adamchik. Fall of 2005

Course on Social Network Analysis Graphs and Networks

IE 680 Special Topics in Production Systems: Networks, Routing and Logistics*

Part 2: Community Detection

Discrete Mathematics & Mathematical Reasoning Chapter 10: Graphs

Seminar. Path planning using Voronoi diagrams and B-Splines. Stefano Martina

Network (Tree) Topology Inference Based on Prüfer Sequence

CSE 326, Data Structures. Sample Final Exam. Problem Max Points Score 1 14 (2x7) 2 18 (3x6) Total 92.

Outline. NP-completeness. When is a problem easy? When is a problem hard? Today. Euler Circuits

Data Structure [Question Bank]

The Goldberg Rao Algorithm for the Maximum Flow Problem

Graph Theory and Complex Networks: An Introduction. Chapter 06: Network analysis

Home Page. Data Structures. Title Page. Page 1 of 24. Go Back. Full Screen. Close. Quit

Distributed Computing over Communication Networks: Maximal Independent Set

Handout #Ch7 San Skulrattanakulchai Gustavus Adolphus College Dec 6, Chapter 7: Digraphs

Exam study sheet for CS2711. List of topics

Discrete Mathematics. Hans Cuypers. October 11, 2007

Approximation Algorithms

Solutions to Homework 6

OPTIMAL DESIGN OF DISTRIBUTED SENSOR NETWORKS FOR FIELD RECONSTRUCTION

Graph/Network Visualization

Simplified External memory Algorithms for Planar DAGs. July 2004

A SOCIAL NETWORK ANALYSIS APPROACH TO ANALYZE ROAD NETWORKS INTRODUCTION

Midterm Practice Problems

Practical Graph Mining with R. 5. Link Analysis

Lecture 15 An Arithmetic Circuit Lowerbound and Flows in Graphs

136 CHAPTER 4. INDUCTION, GRAPHS AND TREES

SCAN: A Structural Clustering Algorithm for Networks

Why? A central concept in Computer Science. Algorithms are ubiquitous.

Graph Theory and Complex Networks: An Introduction. Chapter 06: Network analysis. Contents. Introduction. Maarten van Steen. Version: April 28, 2014

CompSci-61B, Data Structures Final Exam

Mathematics for Algorithm and System Analysis

2. (a) Explain the strassen s matrix multiplication. (b) Write deletion algorithm, of Binary search tree. [8+8]

Social Media Mining. Network Measures

Chapter 6: Graph Theory

Finding and counting given length cycles

Zachary Monaco Georgia College Olympic Coloring: Go For The Gold

Labeling outerplanar graphs with maximum degree three

Discrete Mathematics Problems

Big O and Limits Abstract Data Types Data Structure Grand Tour.

Java Software Structures

The Union-Find Problem Kruskal s algorithm for finding an MST presented us with a problem in data-structure design. As we looked at each edge,

SPANNING CACTI FOR STRUCTURALLY CONTROLLABLE NETWORKS NGO THI TU ANH NATIONAL UNIVERSITY OF SINGAPORE

A Review And Evaluations Of Shortest Path Algorithms

3. The Junction Tree Algorithms

6 March Array Implementation of Binary Trees

Simple Graphs Degrees, Isomorphism, Paths

Graphs without proper subgraphs of minimum degree 3 and short cycles

Krishna Institute of Engineering & Technology, Ghaziabad Department of Computer Application MCA-213 : DATA STRUCTURES USING C

Problem Set 7 Solutions

Page 1. CSCE 310J Data Structures & Algorithms. CSCE 310J Data Structures & Algorithms. P, NP, and NP-Complete. Polynomial-Time Algorithms

Graph theory and network analysis. Devika Subramanian Comp 140 Fall 2008

BOUNDARY EDGE DOMINATION IN GRAPHS

Minimum cost maximum flow, Minimum cost circulation, Cost/Capacity scaling

Graph Theory Problems and Solutions

Distance Degree Sequences for Network Analysis

6.852: Distributed Algorithms Fall, Class 2

Probabilistic Risk Analysis in Business Continuity Management

General Network Analysis: Graph-theoretic. COMP572 Fall 2009

SGL: Stata graph library for network analysis

Ching-Yung Lin, Ph.D. Adjunct Professor, Dept. of Electrical Engineering and Computer Science IBM Chief Scientist, Graph Computing. October 29th, 2015

WOLLONGONG COLLEGE AUSTRALIA. Diploma in Information Technology

Some questions... Graphs

An Introduction to APGL

Mining Social Network Graphs

! E6893 Big Data Analytics Lecture 10:! Linked Big Data Graph Computing (II)

One last point: we started off this book by introducing another famously hard search problem:

(67902) Topics in Theory and Complexity Nov 2, Lecture 7

WAN Wide Area Networks. Packet Switch Operation. Packet Switches. COMP476 Networked Computer Systems. WANs are made of store and forward switches.

THE last two decades have witnessed an exponential

CMSC 858T: Randomized Algorithms Spring 2003 Handout 8: The Local Lemma

GRAPH THEORY LECTURE 4: TREES

A Fast Algorithm For Finding Hamilton Cycles

! E6893 Big Data Analytics Lecture 9:! Linked Big Data Graph Computing (I)

A Sublinear Bipartiteness Tester for Bounded Degree Graphs

Cloud Computing. Lectures 10 and 11 Map Reduce: System Perspective

Data Structures. Chapter 8

Large induced subgraphs with all degrees odd

Topology-based network security

NP-Completeness. CptS 223 Advanced Data Structures. Larry Holder School of Electrical Engineering and Computer Science Washington State University

DYNAMIC GRAPH ANALYSIS FOR LOAD BALANCING APPLICATIONS

SHARP BOUNDS FOR THE SUM OF THE SQUARES OF THE DEGREES OF A GRAPH

most 4 Mirka Miller 1,2, Guillermo Pineda-Villavicencio 3, The University of Newcastle Callaghan, NSW 2308, Australia University of West Bohemia

Approximated Distributed Minimum Vertex Cover Algorithms for Bounded Degree Graphs

The Basics of Graphical Models

Graphical degree sequences and realizations

B AB 5 C AC 3 D ABGED 9 E ABGE 7 F ABGEF 8 G ABG 6 A BEDA 3 C BC 1 D BCD 2 E BE 1 F BEF 2 G BG 1

Systems and Algorithms for Big Data Analytics

Minimizing Probing Cost and Achieving Identifiability in Probe Based Network Link Monitoring

Chapter 1. Introduction

Network Analysis: Lecture 1. Sacha Epskamp

1 Introduction. Dr. T. Srinivas Department of Mathematics Kakatiya University Warangal , AP, INDIA

Load balancing Static Load Balancing

! Solve problem to optimality. ! Solve problem in poly-time. ! Solve arbitrary instances of the problem. !-approximation algorithm.

Transcription:

Data Structures in Java Session 16 Instructor: Bert Huang http://www.cs.columbia.edu/~bert/courses/3134

Announcements Homework 4 due next class Remaining grades: hw4, hw5, hw6 25% Final exam 30% Midterm grades posted. Avg: 79/90

Todayʼs Plan Graphs Topological Sort Shortest Path Algorithms: Dijkstraʼs

Graphs Trees Linked Lists Graphs

Graphs Linked List Tree Graph

Graph Terminology A graph is a set of nodes and edges nodes aka vertices edges aka arcs, links Edges exist between pairs of nodes if nodes x and y share an edge, they are adjacent

Graph Terminology Edges may have weights associated with them Edges may be directed or undirected A path is a series of adjacent vertices the length of a path is the sum of the edge weights along the path (1 if unweighted) A cycle is a path that starts and ends on a node

Graph Properties An undirected graph with no cycles is a tree A directed graph with no cycles is a special class called a directed acyclic graph (DAG) In a connected graph, a path exists between every pair of vertices A complete graph has an edge between every pair of vertices

Graph Applications: A few examples Computer networks The World Wide Web Social networks Public transportation Probabilistic Inference Flow Charts

Implementation Option 1: Store all nodes in an indexed list Represent edges with adjacency matrix Option 2: Explicitly store adjacency lists

Adjacency Matrices 2d-array A of boolean variables A[i][j] is true when node i is adjacent to node j If graph is undirected, A is symmetric 1 1 2 3 4 5 1 2 3 4 5 0 1 1 0 0 1 0 0 1 0 1 0 0 1 0 0 1 1 0 1 0 0 0 1 0 2 3 4 5

Adjacency Lists Each node stores references to its neighbors 1 2 3 2 1 4 3 1 4 4 2 3 5 5 4 1 2 3 4 5

Math Notation for Graphs Set Notation: v V (v is in V) U V (union) U V (intersection) U V (U is a subset of V) G = {V, E} G is the graph V is set of vertices E is set of edges (v i,v j ) E V = N = size of V

Topological Sort Problem definition: Given a directed acyclic graph G, order the nodes such that for each edge (v i,v j ) E, v i is before v j in the ordering. e.g., scheduling errands when some tasks depend on other tasks being completed.

Topological Sort Ex. Go to ATM Fix Computer Buy Groceries Look up recipe online Buy Stamps Taxes Cook Dinner Mail recipe to Grandma Mail Postcard Mail Tax Form

Topological Sort Naïve Algorithm Degree means # of edges, indegree means # of incoming edges 1. Compute the indegree of all nodes 2. Print any node with indegree 0 3. Remove the node we just printed. Go to 1. Which nodesʼ indegrees change?

Topological Sort Better Algorithm 1. Compute all indegrees 2. Put all indegree 0 nodes into a Collection 3. Print and remove a node from Collection 4. Decrement indegrees of the nodeʼs neighbors. 5. If any neighbor has indegree 0, place in Collection. Go to 3.

Go to ATM Fix Computer Buy Groceries Look up recipe online Buy Stamps Taxes Cook Dinner Mail recipe to Grandma Mail Postcard Mail Tax Form ATM comp recipe stamps taxes cook groceries grandma postcard mail taxes 0 0 2 1 1 1 2 2 1 2

Topological Sort Running time Initial indegree computation: O( E ) Unless we update indegree as we build graph V nodes must be enqueued/dequeued Dequeue requires operation for outgoing edges Each edge is used, but never repeated Total running time O( V + E )

Shortest Path Given G = (V,E), and a node s V, find the shortest (weighted) path from s to every other vertex in G. Motivating example: subway travel Nodes are junctions, transfer locations Edge weights are estimated time of travel

Approximate MTA Express Stop Subgraph A few inaccuracies (donʼt use this to plan any trips) 168th 145th and 8th 125th and 8th 59th Port Auth. 116th 96th 72nd Times Square Penn Station 86th Lex. 59th Lex. Grand Central

Breadth First Search Like a level-order traversal Find all adjacent nodes (level 1) Find new nodes adjacent to level 1 nodes (level 2)... and so on We can implement this with a queue

Unweighted Shortest Path Algorithm Set node sʼ distance to 0 and enqueue s. Then repeat the following: mark that we reached v from u Dequeue node v. For unset neighbor u: set neighbor uʼs distance to vʼs distance +1 enqueue u

168th 145th and 8th 125th and 8th 59th Port Auth. 116th 96th 72nd Times Square Penn Station 86th Lex. 59th Lex. Grand Central 168 th 145 th 125 th 8th 59 th Port Auth. 116 th 96 th 72 nd Times Sq. Penn St. 86 th Lex. 59 th Lex. Grand Centr. dist prev 0 source

Weighted Shortest Path The problem becomes more difficult when edges have different weights Weights represent different costs on using that edge Standard algorithm is Dijkstraʼs Algorithm

Dijkstraʼs Algorithm Keep distance overestimates D(v) for each node v (all non-source nodes are initially infinite) 1. Choose node v with smallest unknown distance 2. Declare that vʼs shortest distance is known 3. Update distance estimates for neighbors

Updating Distances For each of vʼs neighbors, w, if min(d(v)+ weight(v,w), D(w)) i.e., update D(w) if the path going through v is cheaper than the best path so far to w

59th 5 Port Auth. 7 12 10 6 72nd 4 Times Square 2 Penn Station 59 th Port Auth. 72 nd Broad Times Sq. Penn St. inf inf inf inf 0???? home

Dijkstraʼs Algorithm Analysis First, convince ourselves that the algorithm works. At each stage, we have a set of nodes whose shortest paths we know In the base case, the set is the source node. Inductive step: if we have a correct set, is greedily adding the shortest neighbor correct?

Proof by Contradiction (Sketch) Contradiction: Dijkstraʼs finds a shortest path to node w through v, but there exists an even shorter path This shorter path must pass from inside our known set to outside. Call the 1st node in cheaper path outside our set u The path to u must be shorter than the path to w But then we would have chosen u instead s...... v? w u

Computational Cost Keep a priority queue of all unknown nodes Each stage requires a deletemin, and then some decreasekeys (the # of neighbors of node) We call decreasekey once per edge, we call deletemin once per vertex Both operations are O(log V ) Total cost: O( E log V + V log V ) = O( E log V )

Reading Weiss Section 9.1-9.3 (todayʼs material)