
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 26504 Articles for Server Side Programming

344 Views
We have to make the knight cover all the cells of the board and it can move to a cell only once.There can be two ways of finishing the knight move - the first in which the knight is one knight's move away from the cell from where it began, so it can go to the position from where it started and form a loop, this is called closed tour, the second in which the knight finishes anywhere else, this is called open tour. A move is valid if it is inside the chessboard and if the cell is not ... Read More

393 Views
Create a backtrack function that updates the current string if open brackets are less than n or close bracket are less than open bracket. When the length of current string becomes equal to 2*n, add it to the combination result array. It could be simply tracked by keeping the number of { } placed . We can start an opening bracket if we still have one left to place. And we can start a closing bracket if it would not exceed the number of opening brackets.Example Live Demousing System; using System.Collections.Generic; using System.Text; using System.Linq; namespace ConsoleApplication{ public class BackTracking{ ... Read More

387 Views
Create an output list to store the valid sequences, create a current list that will store the current sequence found in the path of the recursion tree. A backtrack function that will go into the recursion until the target is achieved, otherwise, it should backtrack to the previous phase as target becomes less than 0. At any point in time, if target becomes 0 then add the candidate array to the result as the values in the candidate array must be sum up to the given target.If those are not the cases then, one by one add the elements in ... Read More

289 Views
Create an output list to store the valid sequences, create a current list that will store the current sequence found in the path of the recursion tree. A backtrack function that will go into the recursion until the target is achieved, otherwise, it should backtrack to the previous phase as target becomes less than 0. At any point in time, if target becomes 0 then add the candidate array to the result as the values in the candidate array must be sum up to the given target.If those are not the cases then, one by one add the elements in ... Read More

361 Views
Distinct subsets problem gives us the different combination from the given array.When the target is 2 then from the array, we take all the combination that corresponds to number 2, When the target is three then from the array, we take all the combination that corresponds to count 3. In the below example the array is [1, 2, 3] and the target is 2. So, we take all the combinations the corresponds to number 2 “1, 2 “, “2, 3”, ”1, 3””.Example Live Demousing System; using System.Collections.Generic; using System.Text; using System.Linq; namespace ConsoleApplication{ public class BackTracking{ public ... Read More

553 Views
Target sum problem is the problem of finding a subset such that the sum of elements equal a given number. The backtracking approach generates all permutations in the worst case but in general, performs better than the recursive approach towards subset sum problem.A subset A of n positive integers and a value sum is given, find whether or not there exists any subset of the given set, the sum of whose elements is equal to the given value of sumSuppose we have an array [1, 2, 3] the output will be “1, 1, 1, 1 “, “1, 1, 2”, ”2, ... Read More

319 Views
The problem can be broken down into smaller and simple "subproblems", which can be further divided into yet simpler and smaller subproblems. We take each and every digit one by one and count all ndigits reachable from any digit, use a map to store the mapping of digits reachable from every digit. When the digit becomes n-digit, update the count.Example Live Demousing System; using System.Collections.Generic; namespace ConsoleApplication{ public class BackTracking{ private string GetKeyPadValueBasedOnInput(string digit){ Dictionary keypad = new Dictionary(); keypad.Add("2", "abc"); keypad.Add("3", "def"); ... Read More

896 Views
Find the character in the first position and swap the rest of the character with the first character. Like in ABC, in the first iteration three strings are formed: ABC, BAC, and CBA by swapping A with A, B and C respectively. Repeat step for the rest of the characters like fixing second character B and so on. Now swap again to go back to the previous position. from ABC, we formed ABC by fixing B again, and we backtrack to the previous position and swap B with C. So, now we got ABC and ACB.Example Live Demousing System; namespace ConsoleApplication{ ... Read More

323 Views
Create a function to Find Power which takes the number x and n, where x is the 2 and n is how many times, we have to do the power. If the number is even then we have to do x*x and if the number is odd multiply the result with x*x. Continue the recursive call until the n becomes 0.Suppose if we have a number 2 and 8, then 2*2*2*2*2*2*2*2 =256.Example Live Demousing System; namespace ConsoleApplication{ public class BackTracking{ public int FindPower(int x, int n){ int result; if ... Read More

699 Views
Linear scan the 2d grid map, if a node contains a '1', then it is a root node that triggers a Depth First Search. During DFS, every visited node should be set as '0' to mark as visited node. Count the number of root nodes that trigger DFS, this number would be the number of islands since each DFS starting at some root identifies an island.Example Live Demousing System; namespace ConsoleApplication{ public class Matrix{ public int PrintNumberOfIslands(char[, ] grid){ bool[, ] visited = new bool[grid.GetLength(0), grid.GetLength(1)]; int res = ... Read More