Even Odd Tree | DFS | BFS | Leetcode 1609

Subscribers:
92,300
Published on ● Video Link: https://www.youtube.com/watch?v=ai7zemxYjz4



Duration: 40:37
3,086 views
174


Whatsapp Community Link : https://www.whatsapp.com/channel/0029Va6kVSjICVfiVdsHgi1A
This is the 42nd Video of our Playlist "Binary Tree : Popular Interview Problems".
In this video we will try to solve a very good Binary Tree problem : Even Odd Tree | Leetcode 1609

I will explain the intuition so easily that you will never forget and start seeing this as cakewalk EASYYY.
We will do live coding after explanation and see if we are able to pass all the test cases.
Also, please note that my Github solution link below contains both C++ as well as JAVA code.

Problem Name : Even Odd Tree | DFS | BFS | Leetcode 1609
Company Tags : AMAZON
My solutions on Github(C++ & JAVA) : https://github.com/MAZHARMIK/Interview_DS_Algo/blob/master/Tree/Even%20Odd%20Tree.cpp
Leetcode Link : https://leetcode.com/problems/even-odd-tree/


My DP Concepts Playlist : https://youtu.be/7eLMOE1jnls
My Graph Concepts Playlist : https://youtu.be/5JGiZnr6B5w
My GitHub Repo for interview preparation : https://github.com/MAZHARMIK/Interview_DS_Algo
Subscribe to my channel : https://www.youtube.com/@codestorywithMIK
Instagram : https://www.instagram.com/codestorywithmik/
Facebook : https://www.facebook.com/people/codestorywithmik/100090524295846/
Twitter : https://twitter.com/CSwithMIK


Approach Summary :
Approach-1 (BFS)
Algorithm:
Uses Breadth-First Search (BFS) to traverse the tree level by level.
Maintains a queue to keep track of nodes at each level.
Uses a boolean flag (even_level) to alternate between even and odd levels.
Checks if values in even levels are strictly increasing and odd levels are strictly decreasing.
Complexity:
Time Complexity: O(n) - where n is the number of nodes in the tree.
Space Complexity: O(n) - in the worst case, when the queue stores all nodes at the maximum level.
Approach-2 (DFS)
Algorithm:
Uses Depth-First Search (DFS) with a recursive approach.
Maintains a vector (levelPrev) to store the previous value at each level.
Checks if values at even levels are strictly increasing and odd levels are strictly decreasing.
Complexity:
Time Complexity: O(n) - where n is the number of nodes in the tree.
Space Complexity: O(n) - uses additional space for the vector levelPrev and recursion stack. The recursion depth is determined by the height of the tree.
These approaches aim to determine if a given binary tree is an Even-Odd Tree based on specific rules about the values in even and odd levels. The BFS approach uses a queue for level-order traversal, while the DFS approach utilizes recursive calls and a vector to track previous values at each level. Both approaches have a time complexity of O(n) but differ in their space complexity.

╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝

✨ Timelines✨
00:00 - Introduction
02:28 - Approach 1 BFS
11:40 - Coding Approach 1
16:01 - Time & Space
16:18 - Approach 2 DFS
33:43 - Coding Approach 2
38:39- Time & Space

#coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge#leetcodequestions #leetcodechallenge #hindi #india #hindiexplanation #hindiexplained #easyexplaination #interview#interviewtips #interviewpreparation #interview_ds_algo #hinglish #github #design #data #google #video #instagram #facebook #leetcode #computerscience #leetcodesolutions #leetcodequestionandanswers #code #learning #dsalgo #dsa #newyear2024




Other Videos By codestorywithMIK


2024-03-04Minimum Length of String After Deleting Similar Ends | Simple Two Pointers | Leetcode 1750
2024-03-04Stay tuned - Life Changing Moment
2024-03-04Largest Number formed from an Array | Largest Number | Comparators Application | Leetcode 179
2024-03-02Remove Nth Node From End of List | 1 Pass | 2 Pass | Leetcode 19
2024-03-01Just don't give up. #codestorywithmik
2024-03-01Squares of a Sorted Array | 2 Approaches | Follow Up | Leetcode 977
2024-02-29Maximum Odd Binary Number | 2 Approaches | Leetcode 2864
2024-02-29Comparators in C++ | sort Example | Function Pointer | Functors | Lambda Expressions
2024-02-29Print Longest Common Subsequence | DP On Strings | DP Concepts & Qns-19
2024-02-28Keep moving guys. We are together 💪
2024-02-28Even Odd Tree | DFS | BFS | Leetcode 1609
2024-02-28Permutations II | Two Approaches | Detailed | Recursion Concepts And Questions
2024-02-27Find Bottom Left Tree Value | 3 Approaches | Simple Story | Microsoft | Leetcode 513
2024-02-27Power Set | Same as Subsets | Magic Of Recursion | Recursion Concepts And Questions
2024-02-26Diameter of Binary Tree | Simple Story | Amazon | Leetcode 543
2024-02-26Earliest Second to Mark Indices I | Detailed Intuition | Leetcode Weekly Contest 386 | Leetcode 3048
2024-02-25Generate Parentheses | 2 Approaches | Magic Of Recursion | Recursion Concepts And Questions
2024-02-25Greatest Common Divisor Traversal | Why Graph | Why DSU | Google | Leetcode 2709
2024-02-24Find All People With Secret | 4 Approaches | Google | Leetcode 2092
2024-02-23Thank you and Love You All ❤️🙏
2024-02-23N-Queens | 2 Approaches | Super Detailed | Magic Of Recursion | Recursion Concepts And Questions