backtracking, graph DSA Flashcards
Backtracking
general algorithmic technique that considers searching every possible combination in order to solve a computational problem.
Properties of backtracking
Incremental construction: Backtracking builds a solution incrementally by constructing a partial solution and expanding it until a complete solution is found or it becomes clear that no solution exists.
Reversibility: Backtracking is reversible, as it can backtrack to a previous state and try a different path when it reaches a dead end.
Optimal solution: Backtracking can guarantee an optimal solution if the problem has a well-defined goal and optimal solution, as it explores the entire search space.
Simplicity: Backtracking is a simple approach for solving problems, as it avoids the need for complex data structures or algorithms and can be easily implemented using a simple recursive approach.
Advantages of backtracking
Flexibility: Backtracking can be used to solve a wide range of problems, from simple puzzles like the N-Queens problem to complex combinatorial optimization problems. It can be adapted to various constraints and problem-specific requirements.
Pruning: Backtracking can be optimized through pruning, which involves avoiding certain branches of the search tree that are not likely to lead to a solution. This can greatly reduce the search space and speed up the solution time.
Concurrent execution: Backtracking algorithms can be parallelized and executed in multiple threads, as each recursive call can be executed independently. This can greatly speed up the solution time
Disadvantages of backtracking
Time complexity: Backtracking can be very slow for large problems, as it explores a large search space that may contain many dead ends. This can result in a high time complexity, especially if the problem has a large number of constraints and a complex search space.
Space complexity: Backtracking can also be memory-intensive, as it requires storing the state of the partial solution at each step of the search. This can result in a high space complexity, especially for problems with a large number of variables and constraints.
Inefficiency: Backtracking can be inefficient, as it may explore the same parts of the search space multiple times. This can result in a large number of redundant calculations, which can significantly slow down the solution time.
Limited applicability: Backtracking is not suitable for problems with real-time constraints, as it may take a long time to find a solution. Additionally, it may not be appropriate for problems with continuous variables, as it can only handle discrete variables and constraints.
Application of Backtracking:
Five different field where backtracking can be used
Computer Science: Backtracking is commonly used in computer science to solve a wide range of problems, including search algorithms, constraint satisfaction problems, and combinatorial optimization problems.
Mathematics: Backtracking can be used in mathematics to solve a variety of problems, including those related to graph theory, number theory, and combinatorics.
Artificial Intelligence: Backtracking is a key technique used in artificial intelligence to solve problems related to planning, decision-making, and optimization. Examples include pathfinding, route planning, and constraint satisfaction problems in robotics and other AI applications.
Natural Language Processing: Backtracking can be used in natural language processing to solve problems related to parsing and semantic analysis.
Component of a graph:
Vertices
Vertices are the fundamental units of the graph. Sometimes, vertices are also known as vertices or nodes. Every node/vertex can be labeled or unlabelled.
Component of a graph:
Edges
Edges are drawn or used to connect two nodes of the graph. It can be ordered pair of nodes in a directed graph. Edges can connect any two nodes in any possible way. There are no rules. Sometimes, edges are also known as arcs. Every edge can be labeled/unlabelled.
Graph
a non-linear data structure consisting of vertices and edges. The vertices are sometimes also referred to as nodes and the edges are lines or arcs that connect any two nodes in the graph. More formally a Graph is composed of a set of vertices( V ) and a set of edges( E ). The graph is denoted by G(E, V).
Component of a graph:
Edges
Edges are drawn or used to connect two nodes of the graph. It can be ordered pair of nodes in a directed graph. Edges can connect any two nodes in any possible way. There are no rules. Sometimes, edges are also known as arcs. Every edge can be labeled/unlabelled.
Null graph
A graph is known as a null graph if there are no edges in the graph.
Trivial graph
Graph having only a single vertex, it is also the smallest graph possible.
Undirected graph
A graph in which edges do not have any direction. That is the nodes are unordered pairs in the definition of every edge.
Directed graph
A graph in which edge has direction. That is the nodes are ordered pairs in the definition of every edge.
disconnected graph
The graph in which at least one node is not reachable from a node is known as a disconnected graph.
Connected graph
The graph in which from one node we can visit any other node in the graph is known as a connected graph.
complete graph
The graph in which from each node there is an edge to each other node.
Cycle graph
The graph in which the graph is a cycle in itself, the degree of each vertex is 2.
Directed Acyclic graph
A Directed Graph that does not contain any cycle.
Cycle graph
The graph in which the graph is a cycle in itself, the degree of each vertex is 2.
Cyclic graph
A graph containing at least one cycle is known as a Cyclic graph.
Trivial graph
Graph having only a single vertex, it is also the smallest graph possible.
Bipartite graph
A graph in which vertex can be divided into two sets such that vertex in each set does not contain any edge between them.
Weighted graph
A graph in which the edges are already specified with suitable weight is known as a weighted graph. Weighted graphs can be further classified as:
directed weighted graphs and
undirected weighted graphs.
Graph is a data structure that consists of the following two components:
A finite set of vertices also called nodes.
A finite set of ordered pair of the form (u, v) called edge. The pair is ordered because (u, v) is not the same as (v, u) in the case of a directed graph(di-graph). The pair of the form (u, v) indicates that there is an edge from vertex u to vertex v. The edges may contain weight/value/cost.