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 — algorithms/tree/binary_tree/is_subtree at master · marcosfede/algorithms

Expand file tree

/

is_subtree

/
Copy path

Directory actions

More options

More options

Directory actions

More options

More options

Latest commit

 

History

History
History
/

is_subtree

/
Copy path

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
README.md
README.md
 
 
is_subtree.py
is_subtree.py
 
 

README.md

Given two binary trees s and t, check if t is a subtree of s. A subtree of a tree t is a tree consisting of a node in t and all of its descendants in t.

Example 1:

Given s:

    3
  /   \
 4     5
/  \
1   2

Given t:

4 /
1 2 Return true, because t is a subtree of s.

Example 2:

Given s:

      3
    /   \
    4   5
  /  \
  1   2
  /
 0

Given t:

    3
   /
  4
 / \
1   2

Return false, because even though t is part of s, it does not contain all descendants of t.

Follow up: What if one tree is significantly lager than the other?

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.