Sociology and CS Philip Chan. How close are people connected? Are people closely connected, not closely connected, isolated into groups, …

Slides:



Advertisements
Similar presentations
CS 206 Introduction to Computer Science II 04 / 01 / 2009 Instructor: Michael Eckmann.
Advertisements

CSE 390B: Graph Algorithms Based on CSE 373 slides by Jessica Miller, Ruth Anderson 1.
Data Structures Lecture 13: QUEUES Azhar Maqsood NUST Institute of Information Technology (NIIT)
Queues A waiting line that grows by adding elements to its end and shrinks by taking elements from its front Line at the grocery store Cars in traffic.
§2 Topological Sort 〖 Example 〗 Courses needed for a computer science degree at a hypothetical university How shall we convert this list into a graph?
Graph Theory, DFS & BFS Kelly Choi What is a graph? A set of vertices and edges –Directed/Undirected –Weighted/Unweighted –Cyclic/Acyclic.
CS 206 Introduction to Computer Science II 03 / 27 / 2009 Instructor: Michael Eckmann.
Graph A graph, G = (V, E), is a data structure where: V is a set of vertices (aka nodes) E is a set of edges We use graphs to represent relationships among.
Graphs Chapter 12. Chapter Objectives  To become familiar with graph terminology and the different types of graphs  To study a Graph ADT and different.
Chapter 8, Part I Graph Algorithms.
1 Graphs: Traversal Searching/Traversing a graph = visiting the vertices of a graph by following the edges in a systematic way Example: Given a highway.
CS 206 Introduction to Computer Science II 11 / 07 / 2008 Instructor: Michael Eckmann.
Graphs Graphs are the most general data structures we will study in this course. A graph is a more general version of connected nodes than the tree. Both.
CS171 Introduction to Computer Science II Graphs Strike Back.
CSC 331: Algorithm Analysis Paths in Graphs. The DFS algorithm we gave is recursive. DFS generates a search tree showing paths from one vertex to all.
CSCI 3160 Design and Analysis of Algorithms Tutorial 2 Chengyu Lin.
CS 206 Introduction to Computer Science II 11 / 11 / Veterans Day Instructor: Michael Eckmann.
ITEC200 – Week 12 Graphs. 2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study.
CSE332: Data Abstractions Lecture 16: Topological Sort / Graph Traversals Tyler Robison Summer
CSE332: Data Abstractions Lecture 16: Topological Sort / Graph Traversals Dan Grossman Spring 2010.
Graph & BFS.
Directed Graph Algorithms CSE 373 Data Structures Lecture 14.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs.
Connected Components, Directed Graphs, Topological Sort COMP171.
Graph COMP171 Fall Graph / Slide 2 Graphs * Extremely useful tool in modeling problems * Consist of: n Vertices n Edges D E A C F B Vertex Edge.
Graphs. Graph definitions There are two kinds of graphs: directed graphs (sometimes called digraphs) and undirected graphs Birmingham Rugby London Cambridge.
Graph & BFS Lecture 22 COMP171 Fall Graph & BFS / Slide 2 Graphs * Extremely useful tool in modeling problems * Consist of: n Vertices n Edges D.
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
Spring 2010CS 2251 Graphs Chapter 10. Spring 2010CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs.
CS 206 Introduction to Computer Science II 11 / 03 / 2008 Instructor: Michael Eckmann.
Graphs. Graphs Many interesting situations can be modeled by a graph. Many interesting situations can be modeled by a graph. Ex. Mass transportation system,
Chapter 9 Graph algorithms Lec 21 Dec 1, Sample Graph Problems Path problems. Connectedness problems. Spanning tree problems.
CSE 780 Algorithms Advanced Algorithms Graph Algorithms Representations BFS.
CS 206 Introduction to Computer Science II 11 / 05 / 2008 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 03 / 25 / 2009 Instructor: Michael Eckmann.
CS 1114: Graphs and Blobs Prof. Graeme Bailey (notes modified from Noah Snavely, Spring 2009)
Fall 2007CS 2251 Graphs Chapter 12. Fall 2007CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs To.
CS 206 Introduction to Computer Science II 03 / 30 / 2009 Instructor: Michael Eckmann.
Computer Science 112 Fundamentals of Programming II Graph Algorithms.
Geography and CS Philip Chan. How do I get there? Navigation Which web sites can give you turn-by-turn directions?
1 Chapter 9 Graph Algorithms Real-life graph problems Algorithms for some graph problems Choice of data structures for graph problems.
Representing and Using Graphs
Shortest Path Problem Weight of the graph –Nonnegative real number assigned to the edges connecting to vertices Weighted graphs –When a graph.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs.
Dijkstra’s Algorithm: single source shortest paths David Kauchak cs62 Spring 2010.
COMP261 Lecture 6 Dijkstra’s Algorithm. Connectedness Is this graph connected or not? A Z FF C M N B Y BB S P DDGG AA R F G J L EE CC Q O V D T H W E.
CS 206 Introduction to Computer Science II 11 / 16 / 2009 Instructor: Michael Eckmann.
Chapter 16 – Data Structures and Recursion. Data Structures u Built-in –Array –struct u User developed –linked list –stack –queue –tree Lesson 16.1.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 20.
Where’s the title? You gotta search for it!. PotW Solution String s = new Scanner(System.in).next(); int[] prev = new int[s.length() * 2 + 2]; Arrays.fill(prev,
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 13: Graphs Data Abstraction & Problem Solving with C++
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.
COSC 2007 Data Structures II
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
© 2006 Pearson Addison-Wesley. All rights reserved 14 A-1 Chapter 14 Graphs.
Graphs Upon completion you will be able to:
Breadth-first and depth-first traversal Prof. Noah Snavely CS1114
Give Eg:? Queues. Introduction DEFINITION: A Queue is an ordered collection of element in which insertions are made at one end and deletions are made.
Graphs and Paths : Chapter 15 Saurav Karmakar
Breadth-first and depth-first traversal CS1114
CSE 421 Algorithms Richard Anderson Autumn 2015 Lecture 5.
Data Structures and Algorithms Lists, Stacks, Queues, and Graphs Sorting and searching algorithms.
Lecture #13. Topics 1.The Graph Abstract Data Type. 2.Graph Representations. 3.Elementary Graph Operations.
Topics In Social Computing (67810) Module 1 Introduction & The Structure of Social Networks.
Brute Force and Exhaustive Search Brute Force and Exhaustive Search Traveling Salesman Problem Knapsack Problem Assignment Problem Selection Sort and Bubble.
Brute Force and Exhaustive Search Brute Force and Exhaustive Search Traveling Salesman Problem Knapsack Problem Assignment Problem Selection Sort and Bubble.
CSE 373 Topological Sort Graph Traversals
Queues Queues Queues.
Depth-First Search.
I206: Lecture 15: Graphs Marti Hearst Spring 2012.
Presentation transcript:

Sociology and CS Philip Chan

How close are people connected? Are people closely connected, not closely connected, isolated into groups, …

Degree of Separation The number of connections to reach another person

Milgram’s Experiment Stanley Milgram, psychologist Experiment in the late 1960’s Chain letter to gather data Stockbroker in Boston 160 people in Omaha, Nebraska Given a packet Add name and forward it to another person who might be closer to the stockbroker Partial “social network”

Small World Six degrees of separation Everyone is connected to everyone by a few people—about 6 on the average. Obama might be 6 connections away from you “Small world” phenomenon

Bacon Number Number of connections to reach actor Kevin Bacon Is a connection in this network different from the one in Milgram’s experiment?

Problem Formulation Given (input) People Connections/links/friendships Find (output) the average number of connections between two people Simplification don’t care about how long/strong/… the friendships are

Problem Formulation Formulate it into a graph problem (abstraction) Given (input) People Connections Find (output) the average number of connections between two people

Problem Formulation Formulate it into a graph problem (abstraction) Given (input) People -> vertices Connections -> edges Find (output) the average number of connections between two people -> ?

Problem Formulation Formulate it into a graph problem (abstraction) Given (input) People -> vertices Connections -> edges Find (output) the average number of connections between two people -> average shortest path length

Algorithm Shortest Path Dijkstra’s algorithm Limitations?

Algorithm Shortest Path Dijkstra’s algorithm This could be an overkill, why?

Algorithm Unweighted edges Each edge has the same weight of 1 Simpler algorithm? Any ideas?

Breadth-First Search Start from the origin Explore people one link away (dist=1) Explore people two links away (dist=2) … Until the destination is reach

Algorithm Breadth-first search (BFS) Single origin, all destinations

Algorithm Breadth-first search (BFS) Single origin, all destinations Repeat BFS for each origin ShortestDistance(x,y) = shortestDistance(y,x)

Algorithm Breadth-first search (BFS) Single origin, all destinations Repeat BFS for each origin ShortestDistance(x,y) = shortestDistance(y,x) Each subsequent BFS can stop earlier

BFS Algorithm—A Closer Look Add origin to the open list While open list is not empty 1. Remove the first person from the open list 2. Mark the person as visited 3. Add non-visited neighbors of the person to the open list

BFS Algorithm—A Closer Look Add (origin, 0) to the open list While open list is not empty 1. Remove the first item (person, dist) from the open list 2. Mark person as visited 3. For each non-visited neighbor of person Add (neighbor, dist + 1) to the open list

Implementation Data Structures What do we need to keep track of? Whether we have visited some person before An ordered list of persons to be visited Implementation Boolean visited[person] Open list of to be visited people  Queue  First in first out (FIFO)

Queue Operations Enqueue Add an item at the end Dequeue Remove an item from the front

Queue Implementation 1 Consider using an array How to implement the two operations? Enqueue Update tail, add item at tail Dequeue

Queue Implementation 1 Consider using an array How to implement the two operations? Enqueue Update tail, add item at tail Dequeue Remove the first item Shift the rest of the items up, update tail

Additional Operations What do we need to check before Enqueue? What do we need to check before Dequeue?

Additional Operations What do we need to check before Enqueue? What do we need to check before Dequeue? Enqueue: Is the queue full? Dequeue Is the queue empty?

Queue Implementation 1(shifting items) Is the queue empty?

Queue Implementation 1(shifting items) Is the queue empty? When tail is -1 Is the queue full?

Queue Implementation 1(shifting items) Is the queue empty? When tail is -1 Is the queue full? When tail is length - 1

Number of assignments (Speed of algorithm) N = number of items on the queue Count number of assignments involving items in the queue

Number of assignments (Implementation 1) Enqueue

Number of assignments (Implementation 1) Enqueue 1 (assign new item at tail) Dequeue

Number of assignments (Implementation 1) Enqueue 1 (assign new item at tail) Dequeue 1 (assign first item to somewhere else) N-1 shifts (assignments) Total N

Shifting items in Dequeue Quite a bit of work if we have many items in the queue Can we avoid shifting? If so, how? Ideas?

Queue Implementation 2 Consider using an array How to implement the two operations? Enqueue Head and tail Update tail, add at tail Dequeue

Queue Implementation 2 Consider using an array How to implement the two operations? Enqueue Head and tail update tail, add at tail Dequeue Get item from head Update head

Queue Implementation 2 (head and tail) Is the queue empty?

Queue Implementation 2 (head and tail) Is the queue empty? When head is larger than tail Is the queue full?

Queue Implementation 2 (head and tail) Is the queue empty? When head is larger than tail Is the queue full? When tail is length - 1

Number of assignments (Implementation 2) Enqueue

Number of assignments (Implementation 2) Enqueue 1 (assign new item at tail) Dequeue

Number of assignments (Implementation 2) Enqueue 1 (assign new item at tail) Dequeue 1 (assign item at tail to somewhere else)

What if tail reaches the end of array But there is room in the front of the array? Any ideas to reuse the space in the front?

Queue Implementation 3 Circular queue Wrap around If we use head and tail (Implementation 2) What needs to be changed?

Circular Queue Operations Length = length of array Enqueue

Circular Queue Operations Length = length of array Enqueue If not full If tail < length  increment tail Else  tail = 0 Add item Dequeue

Circular Queue Operations Length = length of array Enqueue If not full If tail < length  increment tail Else  tail = 0 Add item Dequeue Similarly for head

Queue Implementation 3 (circular queue) Is the queue empty?

Queue Implementation 3 (circular queue) Is the queue empty? When head is larger than tail With wrap-around adjustment Is the queue full?

Queue Implementation 3 (circular queue) Is the queue empty? When head is larger than tail With wrap-around adjustment Is the queue full? When head is larger than tail With wrap-around adjustment Same!! How can we distinguish them?

Queue Implementation 3 (circular queue) Is the queue empty? When head is larger than tail With wrap-around adjustment Is the queue full? When head is larger than tail With wrap-around adjustment Same!! How can we distinguish them? Keep track of size instead

Keeping track of queue size Enqueue: increment size Dequeue: decrement size

Summary Understand how people are connected Degrees of separation shortest distance between two people Average degree of separation (community) Sum of shortest distance of all pairs / # of pairs Algorithm for shortest distance (distance 1 in all edges) Breadth-first search (BFS) Different origins BFS Open list: people to be explored Queue  Circular queue (implementation 3)