Skip to main content
deleted 945 characters in body
Source Link
zoomlogo
  • 1.7k
  • 6
  • 7

Convert between graph representations.Convert between graph representations.

What?

Let's say I have this graph:

 1 \ \ 2 3 \ / \ / 4 

I can represent it in 2 ways:

    1. A list of connected vertices. [[1,3],[2,4],[3,4]]
    1. A boolean matrix which shows where edges are:
c |1 2 3 4 --|------- 1 |0 0 1 0 2 |0 0 0 1 3 |1 0 0 1 4 |0 1 1 0 ----- or ----- [[0,0,1,0],[0,0,0,1],[1,0,0,1],[0,1,1,0]] 

You code should take input in the form of 1 and output it as 2. The graph is not directed (aka undirected graph). You can also accept input which is 0-indexed.

Test cases

[[1,2],[3,4]] -> [[0,1,0,0],[1,0,0,0],[0,0,0,1],[0,0,1,0]] [[1,3],[2,4],[3,4]] -> [[0,0,1,0],[0,0,0,1],[1,0,0,1],[0,1,1,0]] [[1,2],[2,3],[5,6]] -> [[0,1,0,0,0,0],[1,0,1,0,0,0],[0,1,0,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0,1],[0,0,0,0,1,0]] [[1,2]] -> [[0,1],[1,0]] [[1,2],[4,5]] -> [[0,1,0,0,0],[1,0,0,0,0],[0,0,0,0,0],[0,0,0,0,1],[0,0,0,1,0]] [[4,5]] -> [[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,1],[0,0,0,1,0]] 

Convert between graph representations.

What?

Let's say I have this graph:

 1 \ \ 2 3 \ / \ / 4 

I can represent it in 2 ways:

    1. A list of connected vertices. [[1,3],[2,4],[3,4]]
    1. A boolean matrix which shows where edges are:
c |1 2 3 4 --|------- 1 |0 0 1 0 2 |0 0 0 1 3 |1 0 0 1 4 |0 1 1 0 ----- or ----- [[0,0,1,0],[0,0,0,1],[1,0,0,1],[0,1,1,0]] 

You code should take input in the form of 1 and output it as 2. The graph is not directed (aka undirected graph). You can also accept input which is 0-indexed.

Test cases

[[1,2],[3,4]] -> [[0,1,0,0],[1,0,0,0],[0,0,0,1],[0,0,1,0]] [[1,3],[2,4],[3,4]] -> [[0,0,1,0],[0,0,0,1],[1,0,0,1],[0,1,1,0]] [[1,2],[2,3],[5,6]] -> [[0,1,0,0,0,0],[1,0,1,0,0,0],[0,1,0,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0,1],[0,0,0,0,1,0]] [[1,2]] -> [[0,1],[1,0]] [[1,2],[4,5]] -> [[0,1,0,0,0],[1,0,0,0,0],[0,0,0,0,0],[0,0,0,0,1],[0,0,0,1,0]] [[4,5]] -> [[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,1],[0,0,0,1,0]] 
added 290 characters in body
Source Link
zoomlogo
  • 1.7k
  • 6
  • 7

Convert between graph representations.

What?

Let's say I have this graph:

 1 \ \ 2 3 \ / \ / 4 

I can represent it in 2 ways:

    1. A list of connected vertices. [[1,3],[2,4],[3,4]]
    1. A boolean matrix which shows where edges are:
c |1 2 3 4 --|------- 1 |0 0 1 0 2 |0 0 0 1 3 |1 0 0 1 4 |0 1 1 0 ----- or ----- [[0,0,1,0],[0,0,0,1],[1,0,0,1],[0,1,1,0]] 

You code should take input in the form of 1 and output it as 2. The graph is not directed (aka undirected graph). You can also accept input which is 0-indexed.

Test cases

[[1,2],[3,4]] -> [[0,1,0,0],[1,0,0,0],[0,0,0,1],[0,0,1,0]] [[1,3],[2,4],[3,4]] -> [[0,0,1,0],[0,0,0,1],[1,0,0,1],[0,1,1,0]] [[1,2],[2,3],[5,6]] -> [[0,1,0,0,0,0],[1,0,1,0,0,0],[0,1,0,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0,1],[0,0,0,0,1,0]] [[1,2]] -> [[0,1],[1,0]] [[1,2],[4,5]] -> [[0,1,0,0,0],[1,0,0,0,0],[0,0,0,0,0],[0,0,0,0,1],[0,0,0,1,0]] [[4,5]] -> [[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,1],[0,0,0,1,0]] 

Convert between graph representations.

What?

Let's say I have this graph:

 1 \ \ 2 3 \ / \ / 4 

I can represent it in 2 ways:

    1. A list of connected vertices. [[1,3],[2,4],[3,4]]
    1. A boolean matrix which shows where edges are:
c |1 2 3 4 --|------- 1 |0 0 1 0 2 |0 0 0 1 3 |1 0 0 1 4 |0 1 1 0 ----- or ----- [[0,0,1,0],[0,0,0,1],[1,0,0,1],[0,1,1,0]] 

You code should take input in the form of 1 and output it as 2. The graph is not directed (aka undirected graph). You can also accept input which is 0-indexed.

Test cases

[[1,2],[3,4]] -> [[0,1,0,0],[1,0,0,0],[0,0,0,1],[0,0,1,0]] [[1,3],[2,4],[3,4]] -> [[0,0,1,0],[0,0,0,1],[1,0,0,1],[0,1,1,0]] 

Convert between graph representations.

What?

Let's say I have this graph:

 1 \ \ 2 3 \ / \ / 4 

I can represent it in 2 ways:

    1. A list of connected vertices. [[1,3],[2,4],[3,4]]
    1. A boolean matrix which shows where edges are:
c |1 2 3 4 --|------- 1 |0 0 1 0 2 |0 0 0 1 3 |1 0 0 1 4 |0 1 1 0 ----- or ----- [[0,0,1,0],[0,0,0,1],[1,0,0,1],[0,1,1,0]] 

You code should take input in the form of 1 and output it as 2. The graph is not directed (aka undirected graph). You can also accept input which is 0-indexed.

Test cases

[[1,2],[3,4]] -> [[0,1,0,0],[1,0,0,0],[0,0,0,1],[0,0,1,0]] [[1,3],[2,4],[3,4]] -> [[0,0,1,0],[0,0,0,1],[1,0,0,1],[0,1,1,0]] [[1,2],[2,3],[5,6]] -> [[0,1,0,0,0,0],[1,0,1,0,0,0],[0,1,0,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0,1],[0,0,0,0,1,0]] [[1,2]] -> [[0,1],[1,0]] [[1,2],[4,5]] -> [[0,1,0,0,0],[1,0,0,0,0],[0,0,0,0,0],[0,0,0,0,1],[0,0,0,1,0]] [[4,5]] -> [[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,1],[0,0,0,1,0]] 
deleted 2 characters in body
Source Link
zoomlogo
  • 1.7k
  • 6
  • 7

Convert between graph representations.

What?

Let's say I have this graph:

 1 \ \ 2 3 \ / \ / 4 

I can represent it in 2 ways:

    1. A list of connected vertices. [[1,3],[2,4],[3,4]]
    1. A boolean matrix which shows which verticeswhere edges are connected:
c |1 2 3 4 --|------- 1 |0 0 1 0 2 |0 0 0 1 3 |1 0 0 1 4 |0 1 1 0 ----- or ----- [[0,0,1,0],[0,0,0,1],[1,0,0,1],[0,1,1,0]] 

You code should take input in the form of 1 and output it as 2. Assume that theThe graph is not directed (aka undirected graph). You can also accept input which is 0-indexed.

Test cases

[[1,2],[3,4]] -> [[0,1,0,0],[1,0,0,0],[0,0,0,1],[0,0,1,0]] [[1,3],[2,4],[3,4]] -> [[0,0,1,0],[0,0,0,1],[1,0,0,1],[0,1,1,0]] 

Convert between graph representations.

What?

Let's say I have this graph:

 1 \ \ 2 3 \ / \ / 4 

I can represent it in 2 ways:

    1. A list of connected vertices. [[1,3],[2,4],[3,4]]
    1. A boolean matrix which shows which vertices are connected:
c |1 2 3 4 --|------- 1 |0 0 1 0 2 |0 0 0 1 3 |1 0 0 1 4 |0 1 1 0 ----- or ----- [[0,0,1,0],[0,0,0,1],[1,0,0,1],[0,1,1,0]] 

You code should take input in the form of 1 and output it as 2. Assume that the graph is not directed. You can also accept input which is 0-indexed.

Test cases

[[1,2],[3,4]] -> [[0,1,0,0],[1,0,0,0],[0,0,0,1],[0,0,1,0]] [[1,3],[2,4],[3,4]] -> [[0,0,1,0],[0,0,0,1],[1,0,0,1],[0,1,1,0]] 

Convert between graph representations.

What?

Let's say I have this graph:

 1 \ \ 2 3 \ / \ / 4 

I can represent it in 2 ways:

    1. A list of connected vertices. [[1,3],[2,4],[3,4]]
    1. A boolean matrix which shows where edges are:
c |1 2 3 4 --|------- 1 |0 0 1 0 2 |0 0 0 1 3 |1 0 0 1 4 |0 1 1 0 ----- or ----- [[0,0,1,0],[0,0,0,1],[1,0,0,1],[0,1,1,0]] 

You code should take input in the form of 1 and output it as 2. The graph is not directed (aka undirected graph). You can also accept input which is 0-indexed.

Test cases

[[1,2],[3,4]] -> [[0,1,0,0],[1,0,0,0],[0,0,0,1],[0,0,1,0]] [[1,3],[2,4],[3,4]] -> [[0,0,1,0],[0,0,0,1],[1,0,0,1],[0,1,1,0]] 
added 46 characters in body
Source Link
zoomlogo
  • 1.7k
  • 6
  • 7
Loading
Source Link
zoomlogo
  • 1.7k
  • 6
  • 7
Loading