Skip to content

Design a linear-time algorithm to check tree perfect matching

Notifications You must be signed in to change notification settings

MU-PING/Tree-perfect-matching

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 

Repository files navigation

Tree-perfect-matching

程式簡介

簡述

使用 Depth-First Search ( DFS ) 實作

Give a linear-time algorithm that takes as input a tree ( undirected tree ) and determines whether it has a perfect matching: a set of edges that touches each node exactly once.

  • Input:the first two are maximal node label【contiguous】and the number of edge. The rest are all edges
  • Output:Is there a perfect matching, Exist or Doesn't exist

Example 1

Input:  6 5 1 2 1 3 2 4 2 5 3 6
Output: Doesn't exist perfect matching

Example 2

Input: 4 3 1 2 1 3 2 4
Output: Exist perfect matching

Example 3

Input: 6 5 1 2 1 3 1 4 2 5 3 6
Output: Exist perfect matching

範例圖

  • 0 means it was not matched

image

時間複雜度

O(V+E):using adjacency list and DFS

About

Design a linear-time algorithm to check tree perfect matching

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages