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 — LeetCode/Recursion/133.Clone-Graph at master · wisdompeak/LeetCode

Expand file tree

/

133.Clone-Graph

/
Copy path

Directory actions

More options

More options

Directory actions

More options

More options

Latest commit

 

History

History
History
/

133.Clone-Graph

/
Copy path

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
133.Clone Graph_BFS.cpp
133.Clone Graph_BFS.cpp
 
 
133.Clone Graph_DFS.cpp
133.Clone Graph_DFS.cpp
 
 
Readme.md
Readme.md
 
 

Readme.md

Outline

133.Clone-Graph

对于图的copy,必用Map建立原图和新图之间节点的对应。

DFS

DFS时,递归函数作用于原图root所有的邻接节点adjacent。如果邻接节点adjacent已经存在于Map的映射里(说明已经访问过),则只需建立root和adjacent各自对应的两个节点在新图里的邻里关系。否则,邻接节点adjacent不存在于Map的映射里,说明它未曾被考虑过,则需要先在新图里建立一个adjacent的对应节点,再建立邻里关系。

BFS

BFS一般都是用队列。对于队首的原图节点root,查看其所有邻接节点adjacent。如果adjacent在Map中没有建立其映射关系,则将adjacent入列,并且新建adjacent在新图中的对应节点,并建立在新图中的邻里关系。反之,邻接节点adjacent存在于Map的映射里,说明它已经被考虑过,则只需要建立root和adjacent对应节点的邻里关系,不需要入列任何节点。

Leetcode Link

You are visitor 01402792 — 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.