Skip to content

Commit db528de

Browse files
authored
Merge pull request #89 from raj-rathod/rajesh
feat:<Backtracking> backtracking algorithm content
2 parents e378aec + 1fe6bf3 commit db528de

File tree

4 files changed

+81
-6
lines changed

4 files changed

+81
-6
lines changed
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
1-
<p class="text-center mt-5">Coming soon</p>
1+
<h1 class="text-center">Backtracking Algorithm</h1>
2+
<div class="mt-md-4 mt-3" [innerHtml]="backtrackingMetaData.defination"></div>
3+
<div class="mt-md-4 mt-3" [innerHtml]="backtrackingMetaData.types"></div>
4+
<div class="mt-md-4 mt-3" [innerHtml]="backtrackingMetaData.properties"></div>
5+
<div class="mt-md-4 mt-3" [innerHtml]="backtrackingMetaData.example"></div>
6+
<div class="mt-md-4 mt-3" [innerHtml]="backtrackingMetaData.applications"></div>
7+
<div class="mt-md-4 mt-3" [innerHtml]="backtrackingMetaData.advantage"></div>
8+
<div class="mt-md-4 mt-3" [innerHtml]="backtrackingMetaData.disadvantage"></div>

src/app/components/Algorithms/backtracking/backtracking-algorithm/backtracking-algorithm.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { Component, OnInit } from '@angular/core';
2+
import { backtrackingMetaData } from 'src/app/core/algorithms/backtracking-meta-data';
23

34
@Component({
45
selector: 'app-backtracking-algorithm',
56
templateUrl: './backtracking-algorithm.component.html',
67
styleUrls: ['./backtracking-algorithm.component.css']
78
})
89
export class BacktrackingAlgorithmComponent implements OnInit {
9-
10+
backtrackingMetaData = backtrackingMetaData;
1011
constructor() { }
1112

1213
ngOnInit(): void {
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { Helper } from "src/app/helper/helper"
2+
3+
const backtracking = {
4+
defination: `Think about a scenario where you are standing outside a maze, and you need to find the exit.
5+
Now, you have a couple of ways you can try to find the exit door, uncertain of the outcome. You may either run into some wrong
6+
path, backtrack(move back to the starting point) and try to find a new path, or one in many chances, you may land into the correct
7+
path and reach your exit door. But out of multiple scenarios, you have only one path(marked in green) which will lead you
8+
to the exit door.
9+
</br>
10+
For any backtracking problem, the backtracking algorithm tries to go through one of the paths to reach to the possible solution,
11+
and if the path doesn't leads them there, then the problem backtracks through the same path and takes another path in search of
12+
the solution.
13+
</br>
14+
To understand this clearly, consider the given example. Suppose you are standing in front of three roads, one of which is having
15+
a bag of gold at it's end, but you don't know which one it is. Firstly you will go in Path 1 , if that is not the one, then come
16+
out of it, and go into Path 2 , and again if that is not the one, come out of it and go into Path 3 . So, let's say we are standing
17+
at 'A' and we divided our problem into three smaller sub-probelms 'B', 'D' and 'F'. And using this sub-problem, we have three
18+
possible path to get to our solution -- 'C', 'E', & 'G'.`,
19+
20+
example:'assets/ds-image/backtracking.jpg',
21+
22+
properties:[
23+
`A backtracking algorithm uses the depth-first search method. When it starts exploring the solutions, a bounding function is
24+
applied so that the algorithm can check if the so-far built solution satisfies the constraints. If it does, it continues
25+
searching. If it doesn’t, the branch would be eliminated, and the algorithm goes back to the level before.`,
26+
`It uses recursive calling to find a solution set by building a solution step by step, increasing levels with time.
27+
In order to find these solutions, a search tree named state-space tree is used. In a state-space tree, each branch
28+
is a variable, and each level represents a solution.`,
29+
`Backtracking is used to solve a problem that have multiple solutions.`
30+
],
31+
types:[
32+
`Decision Problem – In this, we search for a feasible solution.`,
33+
`Optimization Problem – In this, we search for the best solution.`,
34+
`Enumeration Problem – In this, we find all feasible solutions.`
35+
],
36+
advantage:[
37+
`Backtracking can almost solve any problems, due to its brute-force nature,
38+
although we use it to solve problems which have branching involved.`,
39+
`Backtracking is an easy method to implement and contains fewer lines of code.`
40+
],
41+
disadvantage: [
42+
`More optimal algorithms for the given problem may exist.`,
43+
`When the branching factor is high, it is very time-consuming`,
44+
`Large space complexity because we are using recursion so function information is stored on stack.`
45+
],
46+
applications:[
47+
`To find all Hamiltonian Paths present in a graph.`,
48+
`To solve the N Queen problem.`,
49+
`Maze solving problem.`,
50+
`The Knight's tour problem.`,
51+
`Binary Strings: generating all binary strings`,
52+
`Generating k – ary Strings`,
53+
`The Knapsack Problem`,
54+
`Graph Coloring Problem`
55+
]
56+
}
57+
58+
export const backtrackingMetaData = {
59+
defination: Helper.setHeader(backtracking.defination),
60+
types: Helper.setListwithTitleHtml('There are three types of problems in backtracking',backtracking.types),
61+
properties: Helper.setListwithTitleHtml('Backtracking Algorithm Properties',backtracking.properties),
62+
example: Helper.setExampleImage('Backtracking Example',backtracking.example),
63+
applications: Helper.setListwithTitleHtml('Application of Backtracking',backtracking.applications),
64+
advantage: Helper.setListwithTitleHtml('Advantage of Backtracking',backtracking.advantage),
65+
disadvantage: Helper.setListwithTitleHtml('Disadvantage of Backtracking',backtracking.disadvantage)
66+
67+
}

src/app/core/meta-data/router-meta-data.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ export const algorithms: RouterLinkData[] = [
6969
name: "Hashing",
7070
route: "/non-primitive/non-linear/hash-table"
7171
},
72-
{
73-
name: "Randomized",
74-
route: "/algorithm/randomized"
75-
},
72+
// {
73+
// name: "Randomized",
74+
// route: "/algorithm/randomized"
75+
// },
7676
{
7777
name: "Recursive",
7878
route: "/algorithm/recursive"

0 commit comments

Comments
 (0)