N-Queens | 2 Approaches | Super Detailed | Magic Of Recursion | Recursion Concepts And Questions
iPad PDF Notes - https://github.com/MAZHARMIK/Interview_DS_Algo/blob/master/iPad%20PDF%20Notes/Recursion%20Concepts%20%26%20Qns%20-%2014.pdf
Whatsapp Community Link : https://www.whatsapp.com/channel/0029Va6kVSjICVfiVdsHgi1A
This is the 14th video of our playlist "Recursion Concepts And Questions". Find the Details below :
Video Name : N-Queens | 2 Approaches | Magic Of Recursion | Recursion Concepts And Questions
Video # : 14
C++/Java Code Link : https://github.com/MAZHARMIK/Interview_DS_Algo/blob/master/Backtracking/N-Queens.cpp
Leetcode Link : https://leetcode.com/problems/n-queens/description/
GFG Link : https://www.geeksforgeeks.org/problems/n-queen-problem0315/1
π Unraveling Recursion: A Journey into the Depths of Code
π₯ Welcome to the 14th Video of my Recursion Playlist! π In this enlightening video, we will solve a very famous recursion/backtracking problem "N-Queens". We will start with a Simple story understanding the problem and then we will be Converting Story to code and writing the recursive code for the problem and also I will also be explaining the Time and Space Complexity of the code π. We will be solving it using 2 Approaches.
π What's Inside?
π Simple story understanding with 2 Approaches
π Converting Story to code and writing the recursive code for N-Queens problem
π Explanation of Time and Space Complexity of the code
π©βπ» Who Should Watch?
This playlist is for everyone but best suited for Freshers who are new to Recursion.
π Embark on the Recursive Adventure Now!
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 (Simple DFS): This approach uses a simple depth-first search (DFS) algorithm to solve the N-Queens problem. The time complexity is O(N!), where N is the size of the chessboard. The algorithm checks the validity of placing a queen in each cell by examining the rows, left diagonals, and right diagonals above the current position. The DFS explores all possible configurations by placing queens row by row and backtracking when necessary. The space complexity is O(N) to store the result.
Approach-2: This approach also employs DFS to solve the N-Queens problem, but with an optimized representation using sets to keep track of occupied columns, diagonals, and anti-diagonals. This reduces the redundant validity checks in the original approach. The time complexity remains O(N!), and the space complexity is O(N) for the result and the sets used to track column, diagonal, and anti-diagonal occupancy. The algorithm places queens row by row, updating the sets accordingly, and backtracks when needed to explore all possible configurations.
βββ¦βββ¦ββββ¦ββ¦β¦β¦β¦ββββ
βββ£βββββ£ββ£ββ£ββ£βββ£ββ£
β βββββββ ββββ£βββββββ£
βββ©βββ©ββ©ββ©ββ©βββ©ββ©ββ
β¨ Timelinesβ¨
00:00 - Introduction
00:55 - Problem Explanation
09:01 - Approach 1 Thought Process
17:43 - Story To Code Points for Approach 1
35:12 - Coding Approach 1
44:41 - Space and Time Approach 1
49:04 - Approach 2 Thought Process
01:01:59 - Coding Approach 2
#codestorywithMIK
#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 #2024 #newyear #RecursionExplained #CodingJourney #Programming101 #TechTalks #AlgorithmMastery #Recursion #Programming #Algorithm #Code #ComputerScience #SoftwareDevelopment #CodingTips #RecursiveFunctions #TechExplained #ProgrammingConcepts #CodeTutorial #LearnToCode #TechEducation #DeveloperCommunity #RecursiveThinking #ProgrammingLogic #ProblemSolving #AlgorithmDesign #CSEducation