geeksforgeeks
  • Courses
  • Tutorials
  • Practice
  • Jobs
  • DSA
  • Practice Problems
  • C
  • C++
  • Java
  • Python
  • JavaScript
  • Data Science
  • Machine Learning
  • Courses
  • Linux
  • DevOps
Videos
June 02, 2022 |890 Views

Print the nodes at odd levels of a tree

Tree, Tree, tree-level-order
 Save  Share   Like
Description
Discussion

The above code prints nodes in preorder way. If we wish to print nodes level by level, we can use level order traversal. The idea is based on Print level order traversal line by line
We traverse nodes level by level. We switch odd level flag after every level.

Print the nodes at odd levels of a tree : https://www.geeksforgeeks.org/print-nodes-odd-levels-tree/

Recommendations
Video Thumbnail
07:41
Video Thumbnail
10.9K Views | 10/01/2025...
Maximum width of a binary tree
Video Thumbnail
08:25
Video Thumbnail
3.9K Views | 10/01/2025...
Print nodes at k distance from root
Video Thumbnail
01:06
Video Thumbnail
23.9K Views | 10/01/2025...
Inorder Successor in Binary Search Tree
Video Thumbnail
16:28
Video Thumbnail
27.1K Views | 10/01/2025...
Lowest Common Ancestor in a Binary Search Tree
Video Thumbnail
04:46
Video Thumbnail
9.0K Views | 10/01/2025...
Root to leaf path sum equal to a given number
Video Thumbnail
11:50
Video Thumbnail
5.5K Views | 10/01/2025...
Print BST keys in the given range
Video Thumbnail
13:09
Video Thumbnail
465.1K Views | 10/01/2025...
AVL Tree Data Structure
Video Thumbnail
50:01
Video Thumbnail
30.0K Views | 10/01/2025...
AVL Tree - Deletion
Video Thumbnail
21:39
Video Thumbnail
151.0K Views | 09/01/2025...
Introduction of Segment Tree
Video Thumbnail
09:44
Video Thumbnail
12.4K Views | 09/01/2025...
Reverse Level Order Traversal
GeeksforGeeks
location
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
location
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play StoreGFG App on App Store
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • Careers
  • Contact Us
  • Corporate Solution
  • Campus Training Program
  • Explore
  • POTD
  • Practice Problems
  • Connect
  • Blogs
  • Upskill Courses
  • Tutorials
  • Programming Languages
  • DSA
  • Web Technology
  • AI, ML & Data Science
  • DevOps
  • CS Core Subjects
  • GATE
  • School Subjects
  • Software and Tools
  • Courses
  • ML and Data Science
  • DSA and Placements
  • Web Development
  • Data Science
  • Programming Languages
  • DevOps & Cloud
  • GATE
  • MongoDB Certifications
  • Preparation Corner
  • Interview Corner
  • Aptitude
  • Puzzles
  • GfG 160
  • System Design
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved