GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Graph/JavaScript at master · HowProgrammingWorks/Graph

Expand file tree

/

JavaScript

/
Copy path

Directory actions

More options

More options

Directory actions

More options

More options

Latest commit

 

History

History
History
/

JavaScript

/
Copy path

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
1-graph.js
1-graph.js
 
 
2-insert-link-to.js
2-insert-link-to.js
 
 
3-index.js
3-index.js
 
 
README.md
README.md
 
 

README.md

Outline

Матрица смежности - хранит связи вершин графа

    1            +---+              const graph = [
  +--------------+ B +--+             [0, 1, 1, 0, 1],
  |              +---+  |             [1, 0, 0, 1, 0],
  |                     |             [1, 0, 0, 1, 0],
+-+-+    2              |             [0, 1, 1, 0, 0],
| A +----------+        |3            [1, 0, 0, 0, 0],
+-+-+          |        |           ];
  |            |        |
  |          +-+-+      |           const graph = {
  |5         | C |      |             A: [0, 1, 1, 0, 1],
  |          +-+-+      |             B: [1, 0, 0, 1, 0],
  +--+         |        |             C: [1, 0, 0, 1, 0],
     |         |        |             D: [0, 1, 1, 0, 0],
   +-+-+     4 |      +-+-+           E: [1, 0, 0, 0, 0],
   | E |       +------+ D |         };
   +---+              +---+

Матрица смежности в виде плоского массива

    1            +---+              const graph = [
  +--------------+ B +--+             0, 1, 1, 0, 1,
  |              +---+  |             1, 0, 0, 1, 0,
  |                     |             1, 0, 0, 1, 0,
+-+-+    2              |             0, 1, 1, 0, 0,
| A +----------+        |3            1, 0, 0, 0, 0,
+-+-+          |        |           ];
  |            |        |
  |          +-+-+      |
  |5         | C |      |
  |          +-+-+      |
  +--+         |        |
     |         |        |
   +-+-+     4 |      +-+-+
   | E |       +------+ D |
   +---+              +---+

Матрица инцидентности - связь вершин (строки) с дугами (колонки)

    1            +---+               const graph = [
  +--------------+ B +--+              [1, 1, 0, 0, 1],
  |              +---+  |              [1, 0, 1, 0, 0],
  |                     |              [0, 1, 0, 1, 0],
+-+-+    2              |              [0, 0, 1, 1, 0],
| A +----------+        |3             [0, 0, 0, 0, 1],
+-+-+          |        |            ];
  |            |        |
  |          +-+-+      |            const graph = {
  |5         | C |      |              A: [1, 1, 0, 0, 1],
  |          +-+-+      |              B: [1, 0, 1, 0, 0],
  +--+         |        |              C: [0, 1, 0, 1, 0],
     |         |        |              D: [0, 0, 1, 1, 0],
   +-+-+     4 |      +-+-+            E: [0, 0, 0, 0, 1],
   | E |       +------+ D |          ];
   +---+              +---+

Список смежности - список вершин, для каждой списк смежных вершин

    1            +---+               const graph = {
  +--------------+ B +--+              A: [],
  |              +---+  |              B: [],
  |                     |              C: [],
+-+-+    2              |              D: [],
| A +----------+        |3             E: [],
+-+-+          |        |            };
  |            |        |
  |          +-+-+      |            const { A, B, C, D, E } = graph;
  |5         | C |      |            A.push(B, C, E);
  |          +-+-+      |            B.push(A, D);
  +--+         |        |            C.push(A, D);
     |         |        |            D.push(B, C);
   +-+-+     4 |      +-+-+          E.push(A);
   | E |       +------+ D |
   +---+              +---+          console.dir({ graph });

Список ребер - список с указанием ребра как пары вершин

    1            +---+               const graph = [
  +--------------+ B +--+               [A, B],
  |              +---+  |               [A, C],
  |                     |               [B, D],
+-+-+    2              |               [C, D],
| A +----------+        |3              [A, E],
+-+-+          |        |            ];
  |            |        |
  |          +-+-+      |            const graph = [
  |5         | C |      |               { from: A, to: B },
  |          +-+-+      |               { from: A, to: C },
  +--+         |        |               { from: B, to: D },
     |         |        |               { from: C, to: D },
   +-+-+     4 |      +-+-+             { from: A, to: E },
   | E |       +------+ D |          ];
   +---+              +---+
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.