0% found this document useful (0 votes)
22 views77 pages

01-Toturial Week2

Uploaded by

peidongliu2000
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views77 pages

01-Toturial Week2

Uploaded by

peidongliu2000
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 77

INFS7450 SOCIAL MEDIA ANALYTICS

Week 2

Liang QU
School of EECS
The University of Queensland
About me: Liang QU

• Office room: 78-622


• Email: liang.qu@uq.edu.au
• Face-to-face: appointment by email
• Research interests: graph embedding, recommender systems, LLM
Today’s Contents

• About INFS7450
• Graph Essentials
• Coding Demo
• Q&A
Section 1: Recall Key Points on INFS7450
Section 1: Course Schedule
Section 1: Course Website - Blackboard

• Lectures, Tutorials and Their Recordings


– Slides posted at the night before the lecture and tutorial sessions
respectively.
– Their recordings will be available on Blackboard system.
• Assignments
– Both online quizzes and projects will be released and submitted via
Blackboard system.
• Communication
– All announcements and reminders about the deadline and due date will be
posted through Blackboard.
– Ed Discussion Board will be used for discussions, queries and questions.
• Emails to the tutors for private questions; all other questions should be posted to ED.
• Students are encouraged to help each other on the discussion board.
• If you cannot access this course on Ed Discussion, please contact
Skye(skye.sun@uq.edu.au )
Section 1: About Generative AI

Examples of misuse:
• Reports: Submitting a report generated by AI without indicating that AI was used.
• Code: Incorporating AI-generated code in your projects without citing the AI as a source.
• Quizzes: Using AI to answer quiz questions

Failure to properly cite AI contributions is a form of academic misconduct


Always attribute AI assistance in your work

Course Profiles: https://course-profiles.uq.edu.au/student_section_loader/section_1/132633


Section 2: Graph Essentials
Section 2: In this section, we’d like to answer:
• Types of graphs
– Directed graph VS undirected graph
– Weighted graph VS unweighted graph
– Regular graph VS complete graph
– Simple graph VS multigraph
• How to traverse a graph?
– DFS
– BFS
• What is a strongly connected component in a
directed graph?
• How to find the shortest path in a weighted graph?
Section 2: Types of Graphs
• Directed graph VS undirected graph
– Handshake Theorem: Let G=(V,E) be an undirected graph with m edges. Then
2𝑚 = $ deg(𝑣)
!∈#
Proof: Each edge contributes twice to the total degree count of all vertices. Thus, both sides
of the equation equal to twice the number of edges.
– Theorem: An undirected graph has an even number of nodes of odd degree.
Proof: Let V1 be the nodes of even degree and V2 be the nodes of odd degree in an
undirected graph G=(V,E) with m edges. Then
2𝑚 = ∑!∈# deg(𝑣) = ∑!∈#! deg 𝑣 + ∑!∈#" deg(𝑣)

Directed Undirected
Section 2: Types of Graphs
• Weighted graph VS unweighted graph
– Degree has generally been extended to the sum of weights when analyzing
weighted graph.
Section 2: Types of Graphs
• Regular graph VS complete graph
– A regular graph is a graph where each node has the same number of
neighbors; i.e., every node has the same degree.
– A complete graph is a graph in which each pair of graph nodes is connected
by an edge.
– A complete graph is always a regular graph.

3-regular graph Complete graph


Section 2: Types of Graphs
• Simple graph VS multigraph
– Simple graphs are graphs where only a single edge is allowed to exist
between any pair of nodes (contain no self loops)
– Multigraphs are graphs where you can have multiple edges between two
nodes (loops are allowed)
Section 2: How to traverse a graph?

• Graph traversal refers to the process of visiting each node in


a graph.
• Typical solution:
– Depth First Search (DFS)
– Breath First Search (BFS)

1 6

0 2
4
7
3
5
Section 2: DFS

• The Depth First Search (DFS) is the most fundamental search


algorithm used to explore nodes and edges of a graph.
• As the name suggests, a DFS plunges depth first into a graph
without regard for which edge it takes next until it cannot go
any further at which point it backtracks and continues.

1 6

0 2
4
7
3
5
Section 2: DFS

• Start DFS at node 0


• The node 0 is in the stack.
1 6

0 2
4
7
3
5

0 The order of visited nodes: {}


Section 2: DFS

• The node 0 is out of stack


• Put the neighbor nodes of node 0 to the stack

1 6

0 2
4
7
3
5

0 The order of visited nodes: {0}


Section 2: DFS

• The node 0 is out of stack


• Put the neighbor nodes of node 0 to the stack

1 6

0 2
4
7
3
5

0 The order of visited nodes: {0}


Section 2: DFS

• Stack follows the LIFO (Last in First out) principle


• Node 1 is going out of the stack

1 6

0 2
4
7
3
5

0 The order of visited nodes: {0}


Section 2: DFS

• Node 1 is out of the stack


• Put the neighbor node of node 1 into the stack

1 6

0 2
4
7
3
5
2

0 The order of visited nodes: {0,1}


Section 2: DFS

• Stack follows the LIFO (Last in First out) principle


• Node 2 is going out of the stack

1 6

0 2
4
7
3
5
2

0 The order of visited nodes: {0,1}


Section 2: DFS

• Node 2 is out of the stack


• Put the neighbor node of node 2 into the stack

1 6

0 2
4
7
4 3
5
2

0 The order of visited nodes: {0,1,2}


Section 2: DFS

• Stack follows the LIFO (Last in First out) principle


• Node 4 is going out of the stack

1 6

0 2
4
7
4 3
5
2

0 The order of visited nodes: {0,1,2}


Section 2: DFS

• Node 4 is out of the stack


• Put the neighbor node of node 4 into the stack

1 6

0 2
6 4
7
4 3
5
2

0 The order of visited nodes: {0,1,2,4}


Section 2: DFS

• Node 4 is out of the stack


• Put the neighbor node of node 4 into the stack

1 6
7
0 2
6 4
7
4 3
5
2

0 The order of visited nodes: {0,1,2,4}


Section 2: DFS

• Node 4 is out of the stack


• Put the neighbor node of node 4 into the stack

5
1 6
7
0 2
6 4
7
4 3
5
2

0 The order of visited nodes: {0,1,2,4}


Section 2: DFS

• Stack follows the LIFO (Last in First out) principle


• Node 5 is going out of the stack

5
1 6
7
0 2
6 4
7
4 3
5
2

0 The order of visited nodes: {0,1,2,4}


Section 2: DFS
• Node 5 is out of the stack
• Put the neighbor node of node 5 into the stack
• Node 7 is already in the stack

5
1 6
7
0 2
6 4
7
4 3
5
2

0 The order of visited nodes: {0,1,2,4,5}


Section 2: DFS

• Stack follows the LIFO (Last in First out) principle


• Node 7 is going out of the stack

5
1 6
7
0 2
6 4
7
4 3
5
2

0 The order of visited nodes: {0,1,2,4,5}


Section 2: DFS
• Node 7 is out of the stack
• Backtrack the stack
• Make sure you don’t re-visit visited nodes!

5
1 6
7
0 2
6 4
7
4 3
5
2

0 The order of visited nodes: {0,1,2,4,5,7}


Section 2: DFS
• Node 6 is going out of the stack
• Backtrack when a dead end is reached.

5
1 6
7
0 2
6 4
7
4 3
5
2

0 The order of visited nodes: {0,1,2,4,5,7}


Section 2: DFS
• Node 6 is out of the stack
• Backtrack

5
1 6
7
0 2
6 4
7
4 3
5
2

0 The order of visited nodes: {0,1,2,4,5,7,6}


Section 2: DFS
• Node 3 is going out of the stack

7
5
1 6
7
0 2
6 4
7
4 3
5
2

0 The order of visited nodes: {0,1,2,4,5,7,6}


Section 2: DFS
• Node 3 is out of the stack
• The DFS will terminate when the stack is empty
7
5
1 6
7
0 2
6 4
7
4 3
5
2

0 The order of visited nodes: {0,1,2,4,5,7,6,3}


Section 2: Strongly Connected Component

• What is a strongly connected component?


– A strongly connected component is the portion of a directed graph in which there is a
path from each node to another node.
– It is applicable only on a directed graph.
– Is {a,b,c} a strongly connected component?
– Is {b,c,d} a strongly connected component?

– How to find strongly connected components? You can refer to:


https://stackoverflow.com/questions/33590974/how-to-find-strongly-connected-
components-in-a-graph
Section 2: Breadth First Search (BFS)

• The Breadth First Search (BFS) is another fundamental


search algorithm used to explore nodes and edges of a
graph.

1 6

0 2
4
7
3
5
Section 2: Breadth First Search (BFS)

• A BFS starts at some arbitrary node of a graph and explore


the neighbor nodes first, before moving to the next level
neighbors
1 6

0 2
4
7
3
5
Section 2: Breadth First Search (BFS)

• A BFS starts at some arbitrary node of a graph and explore


the neighbor nodes first, before moving to the next level
neighbors
1 6

0 2
4
7
3
5
Section 2: Breadth First Search (BFS)

• A BFS starts at some arbitrary node of a graph and explore


the neighbor nodes first, before moving to the next level
neighbors
1 6

0 2
4
7
3
5
Section 2: Breadth First Search (BFS)

• A BFS starts at some arbitrary node of a graph and explore


the neighbor nodes first, before moving to the next level
neighbors
1 6

0 2
4
7
3
5
Section 2: Breadth First Search (BFS)

• A BFS starts at some arbitrary node of a graph and explore


the neighbor nodes first, before moving to the next level
neighbors
1 6

0 2
4
7
3
5
Section 2: Using a Queue

• The BFS algorithm uses a queue data structure to track which


node to visit next. Upon reaching a new node the algorithm adds
it the queue to visit it later. The queue data structure works just
like a real-world queue such as a waiting line at a restaurant.
People can either join the waiting line (enqueue) or get seated
(dequeue)
Queue Back
Dequeue
Enqueue

Queue Front
Section 2: Breadth First Search (BFS)

• A BFS starts at some arbitrary node of a graph and explore


the neighbor nodes first, before moving to the next level
neighbors
1 6

0 2
4
7
3
5

0
Section 2: Breadth First Search (BFS)

• Add the neighbors of node 1 to the queue.

1 6

0 2
4
7
3
5

0
Section 2: Breadth First Search (BFS)

• Add the neighbors of node 1 to the queue.

1 6

0 2
4
7
3
5
3

0
Section 2: Breadth First Search (BFS)

• After we add all the neighbor nodes of node 0 to the queue, we say that we
have visited the node 0.
• The node 0 will dequeue.
• We will visit the next node in the queue, i..e, the node 1

1 6

0 2
4
7
3
5
3

0
Section 2: Breadth First Search (BFS)

• We add the neighbor node (node 2) of node 1 to the queue.


• Node 0 has been visited, so we don’t add it to the queue.

1 6

0 2
4
7
2 3
5
3

0
Section 2: Breadth First Search (BFS)

• After we add all the neighbor nodes of node 1 to the queue, we say that we have
visited the node 1.
• The node 1 will dequeue.
• We will visit the next node in the queue, i..e, the node 3
• Here is the difference between DFS and BFS

1 6

0 2
4
7
2 3
5
3

0
Section 2: Breadth First Search (BFS)

• A BFS starts at some arbitrary node of a graph and explore


the neighbor nodes first, before moving to the next level
neighbors
1 6

0 2
4
7
2 3
5
3

0
Section 2: Breadth First Search (BFS)

• A BFS starts at some arbitrary node of a graph and explore


the neighbor nodes first, before moving to the next level
neighbors
1 6

0 2
4
7
2 3
5
3

0
Section 2: Breadth First Search (BFS)

• A BFS starts at some arbitrary node of a graph and explore


the neighbor nodes first, before moving to the next level
neighbors
1 6

4 0 2
4
7
2 3
5
3

0
Section 2: Breadth First Search (BFS)

• A BFS starts at some arbitrary node of a graph and explore


the neighbor nodes first, before moving to the next level
neighbors
1 6

4 0 2
4
7
2 3
5
3

0
Section 2: Breadth First Search (BFS)

• A BFS starts at some arbitrary node of a graph and explore


the neighbor nodes first, before moving to the next level
neighbors
1 6
6

4 0 2
4
7
2 3
5
3

0
Section 2: Breadth First Search (BFS)

• A BFS starts at some arbitrary node of a graph and explore


the neighbor nodes first, before moving to the next level
neighbors
7
1 6
6

4 0 2
4
7
2 3
5
3

0
Section 2: Breadth First Search (BFS)

• A BFS starts at some arbitrary node of a graph and explore


the neighbor nodes first, before moving to the next level
neighbors
5

7
1 6
6

4 0 2
4
7
2 3
5
3

0
Section 2: Breadth First Search (BFS)

• A BFS starts at some arbitrary node of a graph and explore


the neighbor nodes first, before moving to the next level
neighbors
5

7
1 6
6

4 0 2
4
7
2 3
5
3

0
Section 2: Breadth First Search (BFS)

• A BFS starts at some arbitrary node of a graph and explore


the neighbor nodes first, before moving to the next level
neighbors
5

7
1 6
6

4 0 2
4
7
2 3
5
3

0
Section 2: Breadth First Search (BFS)

• A BFS starts at some arbitrary node of a graph and explore


the neighbor nodes first, before moving to the next level
neighbors
5

7
1 6
6

4 0 2
4
7
2 3
5
3

0
Section 2: Breadth First Search (BFS)

• A BFS starts at some arbitrary node of a graph and explore


the neighbor nodes first, before moving to the next level
neighbors
5

7
1 6
6

4 0 2
4
7
2 3
5
3

0
Section 2: Breadth First Search (BFS)

• A BFS starts at some arbitrary node of a graph and explore


the neighbor nodes first, before moving to the next level
neighbors
5

7
1 6
6

4 0 2
4
7
2 3
5
3

0
Section 2: Breadth First Search (BFS)-Application

• The BFS algorithm is particularly useful for one thing:


finding the shortest path on weight/unweighted graphs.
• What is the shortest path length between node 0 and node
4?
3 1 7
0 2 4
4
2 1
3
Section 2: Breadth First Search (BFS)-Application

• What is the shortest path length between node 0 and node


4?

3 1 7
0 2 4
4
2 1
3

0
Section 2: Breadth First Search (BFS)-Application

• What is the shortest path length between node 0 and node


4?

3 1 7
0 2 4
4
2 1
3

0
Section 2: Breadth First Search (BFS)-Application

• What is the shortest path length between node 0 and node


4?

3 1 7
0 2 4
4
2 1
3 3

0
Section 2: Breadth First Search (BFS)-Application

• What is the shortest path length between node 0 and node


4?

3 1 7
0 2 4
4
2 1
3 3

1 Path: 0 -->1, Length: 3

0
Section 2: Breadth First Search (BFS)-Application

• What is the shortest path length between node 0 and node


4?

3 1 7
0 2 4
2 4
2 1
3 3

1 Path: 0 -->1, Length: 3

0
Section 2: Breadth First Search (BFS)-Application

• What is the shortest path length between node 0 and node


4?

3 1 7
0 2 4
2 4
2 1
3 3
Path: 0 -->3, Length: 2
1 Path: 0 -->1, Length: 3

0
Section 2: Breadth First Search (BFS)-Application

• What is the shortest path length between node 0 and node


4?

3 1 7
0 2 4
2 4
2 1
3 3
Path: 0 -->3, Length: 2
1 Path: 0 -->1, Length: 3

0
Section 2: Breadth First Search (BFS)-Application

• What is the shortest path length between node 0 and node


4?

3 1 7
0 2 4
Path: 0 à1à2, Length: 3+7=10
2 4
Path: 0 à3à2, Length:2+1=3
2 1
3 3
Path: 0 -->3, Length: 2
1 Path: 0 -->1, Length: 3

0
Section 2: Breadth First Search (BFS)-Application

• What is the shortest path length between node 0 and node


4?

3 1 7
4
0 2 4
Path: 0 à1à2, Length: 3+7=10
2 4
Path: 0 à3à2, Length:2+1=3
2 1
3 3
Path: 0 -->3, Length: 2
1 Path: 0 -->1, Length: 3

0
Section 2: Breadth First Search (BFS)-Application

• What is the shortest path length between node 0 and node


4?

Path: 0 à1à2à4, Length: 3+7+4=14


3 1 7
4 Path: 0 à3à2à4, Length:2+1+4=7
0 2 4
Path: 0 à1à2, Length: 3+7=10
2 4
Path: 0 à3à2, Length:2+1=3
2 1
3 3
Path: 0 -->3, Length: 2
1 Path: 0 -->1, Length: 3

0
Section 2: Breadth First Search (BFS)-Application

• What is the shortest path length between node 0 and node


4?

Path: 0 à1à2à4, Length: 3+7+4=14


3 1 7
4 Path: 0 à3à2à4, Length:2+1+4=7
0 2 4
Path: 0 à1à2, Length: 3+7=10
2 4
Path: 0 à3à2, Length:2+1=3
2 1
3 3
Path: 0 -->3, Length: 2
1 Path: 0 -->1, Length: 3

0
A: BFS

B: DFS

C: Neither BFS and DFS will ever


encounter the goal node in this graph

D: BFS and DFS encounter same number


of nodes before encounter the goal node
Section 3: Coding Demo
Section3: Coding demo
• Configure your development environment:

• Install Anaconda on Windows:


• https://docs.anaconda.com/anaconda/install/windows/

• Install Anaconda on MacOS:


• https://docs.anaconda.com/anaconda/install/mac-os/

• Install Jupyter Notebook (Optional):


• https://docs.jupyter.org/en/latest/install/notebook-classic.html
See you next weekJ

Don’t forget the Online quiz 1!

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy