Re-root an undirected tree from any node using DFS/BFS. Use when changing the point of view in a tree, finding paths between nodes, or reparenting tree structures.
Scanned 9/7/2026
Install to Claude Code
npx -y skills add knoopx/pi --skill tree-rerooting --agent claude-codeInstalls into .claude/skills of the current project.
Are you the author of Tree Rerooting?
Add the live security badge to your README — it updates automatically with every re-scan.
[](https://www.skillsdirectory.com/skills/knoopx-tree-rerooting)More formats (shields.io, HTML) on the badges page.
---
name: tree-rerooting
description: "Re-root an undirected tree from any node using DFS/BFS. Use when changing the point of view in a tree, finding paths between nodes, or reparenting tree structures."
topic: Tree Re-Rooting (POV)
token_cost: 120
related: [tree-zipper, dfs-vs-bfs]
keywords:
[
re-root,
reroot,
pov,
point of view,
tree rotation,
change root,
from_pov,
reparent,
path between nodes,
undirected tree,
]
---
## When to use
Re-rooting an undirected tree from a new node.
## Rules
- Build an undirected adjacency map (parent↔children become symmetric neighbor sets)
- Do DFS/BFS from the target node
- Every node you visit gets its parent set to the node you came from
- Its children become all neighbors minus that parent
- Path-between(a, b): re-root at a, then walk from b up parent pointers until you hit a
- If the target node is not in the tree, return None (not an error)
- NEVER mutate the original tree when re-rooting — build a fresh node structure
- ALWAYS keep the original tree intact so repeated from_pov calls work correctly
## Complexity
O(N) per re-root.
## Example
Path between a and b: build adjacency map, DFS from `a` as root, then walk from `b` up parent pointers to `a`. Always build a fresh structure — never mutate the original tree.
Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.
No comments yet. Be the first to comment!
Use this skill when developing or maintaining browser extension code in the `browser/` directory, including Chrome/Firefox/Edge compatibility, content scripts, background scripts, or i18n updates.
SEO optimization with keyword analysis, readability assessment, technical validation, content quality. Use for search rankings, blog posts, content audits, or encountering keyword density, readability scores, meta tags, schema markup errors.
Official Google SEO guide covering search optimization, best practices, Search Console, crawling, indexing, and improving website search visibility based on official Google documentation
Python backend development expertise for FastAPI, security patterns, database operations, Upstash integrations, and code quality. Use when: (1) Building REST APIs with FastAPI, (2) Implementing JWT/OAuth2 authentication, (3) Setting up SQLAlchemy/async databases, (4) Integrating Redis/Upstash caching, (5) Refactoring AI-generated Python code (deslopification), (6) Designing API patterns, or (7) Optimizing backend performance.
Build a full-stack TanStack Start app on Cloudflare Workers from scratch — SSR, file-based routing, server functions, D1+Drizzle, better-auth, Tailwind v4+shadcn/ui. Use whenever the user mentions TanStack Start, asks to scaffold a full-stack Cloudflare app with SSR, wants an SSR dashboard, or asks for a React 19 + Cloudflare Workers app with file-based routing and server functions — even if they don't name TanStack Start specifically. No template repo — Claude generates every file fresh per ...