Professional Documents
Culture Documents
Alternatively, you may feel neither of these solutions is efficient enough, and you would prefer
an algorithm that only ever made one pass of ''s'' or ''t''. The above two implementations each
require two-passes: the first version computes the lengths and then compares each character,
while the second version computes the lowercase versions of the string and then compares the
results to each other. (Note that for a pair of strings, it is also possible to have the length
precomputed to avoid the second pass, but that can have its own drawbacks at times.) You could
imagine how similar routines can be written to test string equality that not only ignore case, but
also ignore accents.
Dynamic Programming
Dynamic programming is an optimization technique for backtracking algorithms. When
subproblems need to be solved repeatedly (i.e., when there are many duplicate branches in the
backtracking algorithm) time can be saved by solving all of the subproblems first (bottom-up,
from smallest to largest) and storing the solution to each subproblem in a table. Thus, each
subproblem is only visited and solved once instead of repeatedly.
Trees
Tree represents the nodes connected by edges. We will discuss binary tree or binary search
tree specifically. Binary Tree is a special data structure used for data storage purposes. A binary
tree has a special condition that each node can have a maximum of two children. Trees are types
of such data structures where the hierarchical type of data can be stored. The data is stored
in the nodes which sometimes stores the reference for other nodes called the children nodes.
CUT PROPERTY
For any cut C of the graph, if the weight of an edge E in the cut-set of C is strictly smaller than
the weights of all other edges of the cut-set of C, then this edge belongs to all the MSTs of the
graph.
Example:
KRUSKAL’S ALGORITHM
Kruskal's algorithm is the concept that is introduced in the graph theory of discrete mathematics.
It is used to discover the shortest path between two points in a connected weighted graph.
This algorithm converts a given graph into the forest, considering each node as a separate tree.
First, sort all the edges from low weight to high. Now, take the edge with the lowest weight and
add it to the spanning tree. If the edge to be added creates a cycle, then reject the edge. Continue
to add the edges until we reach all vertices, and a minimum spanning tree is created.