Given a tree check if it is linear or not.
1 / \ 2 3 Linear as we can form a lime 2 1 3
1 / \ 2 3 / \ 4 5 Not linear
Input : 3 1 2 1 3 Output : YES Explanation: The Tree formed is 2-1-3 which is a linear one. Input : 4 1 2 2 3 4 2 Output : NO
Approach:The given tree would be linear only if n-2 of its nodes have indegree == 2 or number of nodes, n==1.
- Check if a given graph is tree or not
- Check whether given degrees of vertices represent a Graph or Tree
- Difference between graph and tree
- Convert Directed Graph into a Tree
- Check if a given graph is Bipartite using DFS
- Check whether a given graph is Bipartite or not
- Check for star graph
- Given level order traversal of a Binary Tree, check if the Tree is a Min-Heap
- Tree, Back, Edge and Cross Edges in DFS of Graph
- DFS for a n-ary tree (acyclic graph) represented as adjacency list
- Check if a given Binary Tree is height balanced like a Red-Black Tree
- Check whether a binary tree is a complete tree or not | Set 2 (Recursive Solution)
- Check if the given permutation is a valid DFS of graph
- Check if a directed graph is connected or not
- Check if the given graph represents a Bus Topology
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : 29AjayKumar