Category: Subjects

Walk in Graph Theory | Path | Trail | Cycle | Circuit

Walk in Graph Theory-

 

In graph theory,

  • A walk is defined as a finite length alternating sequence of vertices and edges.
  • The total number of edges covered in a walk is called as Length of the Walk.

 

Walk in Graph Theory Example-

 

Consider the following graph-

 

 

In this graph, few examples of walk are-

  • a , b , c , e , d                    (Length = 4)
  • d , b , a , c , e , d , e , c     (Length = 7)
  • e , c , b , a , c , e , d          (Length = 6)

 

Open Walk in Graph Theory-

 

In graph theory, a walk is called as an Open walk if-

  • Length of the walk is greater than zero
  • And the vertices at which the walk starts and ends are different.

 

Closed Walk in Graph Theory-

 

In graph theory, a walk is called as a Closed walk if-

  • Length of the walk is greater than zero
  • And the vertices at which the walk starts and ends are same.

 

NOTE

 

It is important to note the following points-

  • If length of the walk = 0, then it is called as a Trivial Walk.
  • Both vertices and edges can repeat in a walk whether it is an open walk or a closed walk.

 

Path in Graph Theory-

 

In graph theory, a path is defined as an open walk in which-

  • Neither vertices (except possibly the starting and ending vertices) are allowed to repeat.
  • Nor edges are allowed to repeat.

 

Cycle in Graph Theory-

 

In graph theory, a cycle is defined as a closed walk in which-

  • Neither vertices (except possibly the starting and ending vertices) are allowed to repeat.
  • Nor edges are allowed to repeat.

 

OR

In graph theory, a closed path is called as a cycle.

 

Trail in Graph Theory-

 

In graph theory, a trail is defined as an open walk in which-

  • Vertices may repeat.
  • But edges are not allowed to repeat.

 

Circuit in Graph Theory-

 

In graph theory, a circuit is defined as a closed walk in which-

  • Vertices may repeat.
  • But edges are not allowed to repeat.

OR

In graph theory, a closed trail is called as a circuit.

 

NOTE

 

It is important to note the following points-

  • Every path is a trail but every trail need not be a path.
  • Every cycle is a circuit but every circuit need not be a cycle.
  • For directed graphs, we put term “directed” in front of all the terms defined above.

 

Important Chart-

 

The following chart summarizes the above definitions and is helpful in remembering them-

 

 

Also Read- Types of Graphs in Graph Theory

 

PRACTICE PROBLEMS BASED ON WALK IN GRAPH THEORY-

 

Problem-01:

 

Consider the following graph-

 

 

Decide which of the following sequences of vertices determine walks.

For those that are walks, decide whether it is a circuit, a path, a cycle or a trail.

  1. a , b , g , f , c , b
  2. b , g , f , c , b , g , a
  3. c , e , f , c
  4. c , e , f , c , e
  5. a , b , f , a
  6. f , d , e , c , b

 

Solution-

 

  1. Trail
  2. Walk
  3. Cycle
  4. Walk
  5. Not a walk
  6. Path

 

Problem-02:

 

Consider the following graph-

 

 

Consider the following sequences of vertices and answer the questions that follow-

  1. x , v , y , w , v
  2. x , u , x , u , x
  3. x , u , v , y , x
  4. x , v , y , w , v , u , x

 

  1. Which of the above given sequences are directed walks?
  2. What are the lengths of directed walks?
  3. Which directed walks are also directed paths?
  4. Which directed walks are also directed cycles?

 

Solution-

 

Part-01:

 

  • Only (A) and (B) are the directed walks.
  • (C) is not a directed walk since there exists no arc from vertex u to vertex v.
  • (D) is not a directed walk since there exists no arc from vertex v to vertex u.

 

Part-02:

 

Both the directed walks (A) and (B) have length = 4.

 

Part-03:

 

  • Neither (A) nor (B) are directed paths.
  • This is because vertices repeat in both of them.
  • Vertex v repeats in Walk (A) and vertex u repeats in walk (B).

 

Part-04:

 

  • Neither of them are directed cycles.
  • Walk (A) does not represent a directed cycle because its starting and ending vertices are not same.
  • Walk (B) does not represent a directed cycle because it repeats vertices/edges.

 

Problem-03:

 

Consider the following graph-

 

 

Observe the given sequences and predict the nature of walk in each case-

  1. v1e1v2e2v3e2v2
  2. v4e7v1e1v2e2v3e3v4e4v5
  3. v1e1v2e2v3e3v4e4v5
  4. v1e1v2e2v3e3v4e7v1
  5. v6e5v5e4v4e3v3e2v2e1v1e7v4e6v6

 

Solution-

 

  1. Open walk
  2. Trail (Not a path because vertex v4 is repeated)
  3. Path
  4. Cycle
  5. Circuit (Not a cycle because vertex v4 is repeated)

 

To gain better understanding about Walk in Graph Theory,

Watch this Video Lecture

 

Next Article- Graph Coloring

 

Get more notes and other study material of Graph Theory.

Watch video lectures by visiting our YouTube channel LearnVidFun.

Complement of Graph in Graph Theory | Example | Problems

Complement Of Graph-

 

Complement of a simple graph G is a simple graph G’ having-

  • All the vertices of G.
  • An edge between two vertices v and w iff there exists no edge between v and w in the original graph G.

 

Complement Of Graph Example-

 

The following example shows a graph G and its complement graph G’-

 

 

Relationship Between G & G’-

 

The following relationship exists between a graph G and its complement graph G’-

 

1. Number of vertices in G = Number of vertices in G’.

 

|V(G)| = |V(G’)|

 

2. The sum of total number of edges in G and G’ is equal to the total number of edges in a complete graph.

 

|E(G)| + |E(G’)|

= C(n,2)

= n(n-1) / 2

where n = total number of vertices in the graph

 

Important Terms-

 

It is important to note the following terms-

  • Order of graph = Total number of vertices in the graph
  • Size of graph = Total number of edges in the graph

 

Also Read- Types of Graphs in Graph Theory

 

PRACTICE PROBLEMS BASED ON COMPLEMENT OF GRAPH IN GRAPH THEORY-

 

Problem-01:

 

A simple graph G has 10 vertices and 21 edges. Find total number of edges in its complement graph G’.

 

Solution-

 

Given-

  • Number of edges in graph G, |E(G)| = 21
  • Number of vertices in graph G, n = 10

 

We know |E(G)| + |E(G’)| = n(n-1) / 2.

 

Substituting the values, we get-

21 + |E(G’)| = 10 x (10-1) / 2

|E(G’)| = 45 – 21

∴ |E(G’)| = 24

 

Thus, Number of edges in complement graph G’ = 24.

 

Problem-02:

 

A simple graph G has 30 edges and its complement graph G’ has 36 edges. Find number of vertices in G.

 

Solution-

 

Given-

  • Number of edges in graph G, |E(G)| = 30
  • Number of edges in graph G’, |E(G’)| = 36

 

We know |E(G)| + |E(G’)| = n(n-1) / 2.

 

Substituting the values, we get-

30 + 36 = n(n-1) / 2

n(n-1) = 132

n2 – n – 132 = 0

Solving this quadratic equation, we get n = 12.

 

Thus, Number of vertices in graph G = 12.

 

Problem-03:

 

Let G be a simple graph of order n. If the size of G is 56 and the size of G’ is 80. What is n?

 

Solution-

 

Size of a graph = Number of edges in the graph.

 

Given-

  • Number of edges in graph G, |E(G)| = 56
  • Number of edges in graph G’, |E(G’)| = 80

 

We know |E(G)| + |E(G’)| = n(n-1) / 2.

 

Substituting the values, we get-

56 + 80 = n(n-1) / 2

n(n-1) = 272

n2 – n – 272 = 0

Solving this quadratic equation, we get n = 17.

 

Thus, Number of vertices in graph G = 17.

In other words, Order of graph G = 17.

 

To gain better understanding about Complement Of Graph,

Watch this Video Lecture

 

Next Article- Walks in Graph Theory

 

Get more notes and other study material of Graph Theory.

Watch video lectures by visiting our YouTube channel LearnVidFun.

Recoverability in DBMS | Recoverable Schedule

Schedules in DBMS-

 

Before you go through this article, make sure that you have gone through the previous article on Schedules in DBMS.

 

We have discussed-

  • A schedule is the order in which the operations of multiple transactions appear for execution.
  • Non-serial schedules may be serializable or non-serializable.

 

 

In this article, we will discuss about Non-Serializable Schedules.

 

Also read- Serializability in DBMS

 

Non-Serializable Schedules-

 

  • A non-serial schedule which is not serializable is called as a non-serializable schedule.
  • A non-serializable schedule is not guaranteed to produce the the same effect as produced by some serial schedule on any consistent database.

 

Characteristics-

 

Non-serializable schedules-

  • may or may not be consistent
  • may or may not be recoverable

 

Irrecoverable Schedules-

 

If in a schedule,

  • A transaction performs a dirty read operation from an uncommitted transaction
  • And commits before the transaction from which it has read the value

then such a schedule is known as an Irrecoverable Schedule.

 

Example-

 

Consider the following schedule-

 

 

Here,

  • T2 performs a dirty read operation.
  • T2 commits before T1.
  • T1 fails later and roll backs.
  • The value that T2 read now stands to be incorrect.
  • T2 can not recover since it has already committed.

 

Recoverable Schedules-

 

If in a schedule,

  • A transaction performs a dirty read operation from an uncommitted transaction
  • And its commit operation is delayed till the uncommitted transaction either commits or roll backs

then such a schedule is known as a Recoverable Schedule.

 

Here,

  • The commit operation of the transaction that performs the dirty read is delayed.
  • This ensures that it still has a chance to recover if the uncommitted transaction fails later.

 

Example-

 

Consider the following schedule-

 

 

Here,

  • T2 performs a dirty read operation.
  • The commit operation of T2 is delayed till T1 commits or roll backs.
  • T1 commits later.
  • T2 is now allowed to commit.
  • In case, T1 would have failed, T2 has a chance to recover by rolling back.

 

Checking Whether a Schedule is Recoverable or Irrecoverable-

 

Method-01:

 

Check whether the given schedule is conflict serializable or not.

  • If the given schedule is conflict serializable, then it is surely recoverable. Stop and report your answer.
  • If the given schedule is not conflict serializable, then it may or may not be recoverable. Go and check using other methods.

 

Thumb Rules

  • All conflict serializable schedules are recoverable.
  • All recoverable schedules may or may not be conflict serializable.

 

Method-02:

 

Check if there exists any dirty read operation.

(Reading from an uncommitted transaction is called as a dirty read)

  • If there does not exist any dirty read operation, then the schedule is surely recoverable. Stop and report your answer.
  • If there exists any dirty read operation, then the schedule may or may not be recoverable.

 

If there exists a dirty read operation, then follow the following cases-

 

Case-01:

 

If the commit operation of the transaction performing the dirty read occurs before the commit or abort operation of the transaction which updated the value, then the schedule is irrecoverable.

 

Case-02:

 

If the commit operation of the transaction performing the dirty read is delayed till the commit or abort operation of the transaction which updated the value, then the schedule is recoverable.

 

Thumb Rule

No dirty read means a recoverable schedule.

 

Next Article- Cascading Schedule | Cascading Rollback | Cascadeless Schedule

 

Get more notes and other study material of Database Management System (DBMS).

Watch video lectures by visiting our YouTube channel LearnVidFun.

View Serializability in DBMS

Schedules in DBMS-

 

Before you go through this article, make sure that you have gone through the previous article on Serializability in DBMS.

 

We have discussed-

  • The concept of serializability helps to identify the correct non-serial schedules that maintains the consistency of the database.
  • There are two types of serializability-

 

 

In this article, we will discuss about View Serializability.

 

View Serializability-

 

If a given schedule is found to be view equivalent to some serial schedule, then it is called as a view serializable schedule.

 

Also read- Schedules in DBMS

 

View Equivalent Schedules-

 

Consider two schedules S1 and S2 each consisting of two transactions T1 and T2.

Schedules S1 and S2 are called view equivalent if the following three conditions hold true for them-

 

Condition-01:

 

For each data item X, if transaction Ti reads X from the database initially in schedule S1, then in schedule S2 also, Tmust perform the initial read of X from the database.

 

Thumb Rule

“Initial readers must be same for all the data items”.

 

Condition-02:

 

If transaction Ti reads a data item that has been updated by the transaction Tj in schedule S1, then in schedule S2 also, transaction Ti must read the same data item that has been updated by the transaction Tj.

 

Thumb Rule

“Write-read sequence must be same.”.

 

Condition-03:

 

For each data item X, if X has been updated at last by transaction Ti in schedule S1, then in schedule S2 also, X must be updated at last by transaction Ti.

 

Thumb Rule

“Final writers must be same for all the data items”.

 

Checking Whether a Schedule is View Serializable Or Not-

 

Method-01:

 

Check whether the given schedule is conflict serializable or not.

  • If the given schedule is conflict serializable, then it is surely view serializable. Stop and report your answer.
  • If the given schedule is not conflict serializable, then it may or may not be view serializable. Go and check using other methods.

 

Thumb Rules

  • All conflict serializable schedules are view serializable.
  • All view serializable schedules may or may not be conflict serializable.

 

Method-02:

 

Check if there exists any blind write operation.

(Writing without reading is called as a blind write).

  • If there does not exist any blind write, then the schedule is surely not view serializable. Stop and report your answer.
  • If there exists any blind write, then the schedule may or may not be view serializable. Go and check using other methods.

 

Thumb Rule

No blind write means not a view serializable schedule.

 

Method-03:

 

In this method, try finding a view equivalent serial schedule.

  • By using the above three conditions, write all the dependencies.
  • Then, draw a graph using those dependencies.
  • If there exists no cycle in the graph, then the schedule is view serializable otherwise not.

 

Next Article- Practice Problems On View Serializability

 

Get more notes and other study material of Database Management System (DBMS).

Watch video lectures by visiting our YouTube channel LearnVidFun.

Conflict Serializability | Practice Problems

Conflict Serializability-

 

Before you go through this article, make sure that you have gone through the previous article on Conflict Serializability.

 

We have discussed-

  • The concept of serializability helps to identify the correct non-serial schedules that will maintain the consistency of the database.
  • There are two types of serializability-

 

 

In this article, we will discuss practice problems based on conflict serializability.

 

PRACTICE PROBLEMS BASED ON CONFLICT SERIALIZABILITY-

 

Problem-01:

 

Check whether the given schedule S is conflict serializable or not-

S : R1(A) , R2(A) , R1(B) , R2(B) , R3(B) , W1(A) , W2(B)

 

Solution-

 

Step-01:

 

List all the conflicting operations and determine the dependency between the transactions-

  • R2(A) , W1(A)              (T2 → T1)
  • R1(B) , W2(B)              (T1 → T2)
  • R3(B) , W2(B)              (T3 → T2)

 

Step-02:

 

Draw the precedence graph-

 

 

  • Clearly, there exists a cycle in the precedence graph.
  • Therefore, the given schedule S is not conflict serializable.

 

Problem-02:

 

Check whether the given schedule S is conflict serializable and recoverable or not-

 

 

Solution-

 

Checking Whether S is Conflict Serializable Or Not-

 

Step-01:

 

List all the conflicting operations and determine the dependency between the transactions-

  • R2(X) , W3(X)              (T2 → T3)
  • R2(X) , W1(X)              (T2 → T1)
  • W3(X) , W1(X)             (T3 → T1)
  • W3(X) , R4(X)              (T3 → T4)
  • W1(X) , R4(X)              (T1 → T4)
  • W2(Y) , R4(Y)              (T2 → T4)

 

Step-02:

 

Draw the precedence graph-

 

 

  • Clearly, there exists no cycle in the precedence graph.
  • Therefore, the given schedule S is conflict serializable.

 

Checking Whether S is Recoverable Or Not-

 

  • Conflict serializable schedules are always recoverable.
  • Therefore, the given schedule S is recoverable.

 

Alternatively,

  • There exists no dirty read operation.
  • This is because all the transactions which update the values commits immediately.
  • Therefore, the given schedule S is recoverable.
  • Also, S is a Cascadeless Schedule.

 

Problem-03:

 

Check whether the given schedule S is conflict serializable or not. If yes, then determine all the possible serialized schedules-

 

 

Solution-

 

Checking Whether S is Conflict Serializable Or Not-

 

Step-01:

 

List all the conflicting operations and determine the dependency between the transactions-

  • R4(A) , W2(A)              (T4 → T2)
  • R3(A) , W2(A)              (T3 → T2)
  • W1(B) , R3(B)              (T1 → T3)
  • W1(B) , W2(B)             (T1 → T2)
  • R3(B) , W2(B)              (T3 → T2)

 

Step-02:

 

Draw the precedence graph-

 

 

  • Clearly, there exists no cycle in the precedence graph.
  • Therefore, the given schedule S is conflict serializable.

 

Finding the Serialized Schedules-

 

  • All the possible topological orderings of the above precedence graph will be the possible serialized schedules.
  • The topological orderings can be found by performing the Topological Sort of the above precedence graph.

 

After performing the topological sort, the possible serialized schedules are-

  1. T1 → T3 → T4 → T2
  2. T1 → T4 → T3 → T2
  3. T4 → T1 → T3 → T2

 

Problem-04:

 

Determine all the possible serialized schedules for the given schedule-

 

 

Solution-

 

The given schedule S can be rewritten as-

 

 

This is because we are only concerned about the read and write operations taking place on the database.

 

Checking Whether S is Conflict Serializable Or Not-

 

Step-01:

 

List all the conflicting operations and determine the dependency between the transactions-

  • R1(A) , W2(A)              (T1 → T2)
  • R2(A) , W1(A)              (T2 → T1)
  • W2(A) , W1(A)             (T2 → T1)
  • R2(B) , W1(B)              (T2 → T1)
  • R1(B) , W2(B)              (T1 → T2)
  • W1(B) , W2(B)             (T1 → T2)

 

Step-02:

 

Draw the precedence graph-

 

 

  • Clearly, there exists a cycle in the precedence graph.
  • Therefore, the given schedule S is not conflict serializable.
  • Thus, Number of possible serialized schedules = 0.

 

Next Article- View Serializability in DBMS

 

Get more notes and other study material of Database Management System (DBMS).

Watch video lectures by visiting our YouTube channel LearnVidFun.