BELLMAN FORD ALGORITHM IMPLEMENTATION IN C++
Search This Blog
“Simplicity
is the ultimate sophistication.”
— Leonardo da Vinci
Contact me: sreramk360@gmail.com
Contact me: sreramk360@gmail.com
Saturday, 3 October 2015
Shortest path algorithm: Elaborated
Shortest path algorithm
Email:
sreramk@outlook.com
Shortest path algorithms are used in may real
life applications, especially applications involving maps and artificial intelligence
algorithms which are NP in nature. A graph is a collection of nodes
connected
by edges
and can be expressed as
.
Stands
for vertices. These vertices and the connecting edges together can be imagined to
form a three dimensional geometrical structure. In some cases, for each
(here
are
vertices which are connected) there is a weight value assigned to it. This can
also be called as “distance” or “cost” of connecting the two nodes. The shortest
path algorithm traces the minimum distance (or cost) between two nodes
which
are either directly or indirectly connected. The weight values along each
possible paths to the destination node from the source node are summed up, and
the path with the minimum summation value is chosen as the shortest path.







We may represent a weighted graph as
where the extra parameter represents
the set of weight values across each edge.
Weight of the edge
.
Usually, shortest path algorithms are of time complexity
because every node needs to be
visited at least once. In case of AI algorithms, the vertices are generated
based on specific rules, and usually it’s a function of depth; because most
nodes have more than one connections, we may also have non-polynomial relation
between the depth and the number of nodes.




Algorithms like Dijkstra’s algorithm’s time
complexity is
(note,
represents number of nodes and
represents number of edges). Dijkstra’s
algorithm holds only for the situations where
.
But from the definition of a weighted graph given above, weight values can also
be negative. So a modified version of the algorithm which also solves problems
with negative weight edge is required. But this modified algorithm would
require a greater runtime-time complexity; Dijkstra’s algorithm is a greedy
algorithm, which selects the best possible path to every node in the graph,
originating from source. But Dijkstra’s algorithm fails to solve problems that
have negative weight values. In scenarios where negative weight values are
present, another algorithm called Bellman Ford algorithm is used. But its
runtime complexity is
. Which is far greater than
Dijkstra’s algorithm. Generally,
unless there are disjoint
nodes or graphs. Unless stated, the graphs discussed here are always assumed to
not contain any disjoint sets or nodes.






Sunday, 2 August 2015
Fundamentals of calculus chapter 4: More on differential equations
Fundamentals of calculus chapter 4: More on differential
equations
Differential
equations do not have immediate means to solve them. The reason is, because
differential equations are defined from differentiation and so is its integral,
it’s easier to find the differential equation rather than it’s solution. If our
motive is purely to find the solution of differential equations, then our best
approach will be to try and find how the expressions “behave” while trying to
differentiate them. Then we may back trace this sequence of steps to find the
original expression.
Monday, 27 July 2015
An optimal algorithm for the shortest path in the graph
An optimal algorithm
to find the shortest path in the graph
Introduction:
Many
real-life solutions rely on shortest path algorithms, especially games rely on
them! If a graphic game character traces your moves along a complicated path
and finds you, then it is obvious that the game implemented a graph algorithm
to find the shortest path to approach you. Is it really that easy to find an
optimal path to reach a point in a graph? No not exactly, as the upper bound of
the Dijkstra’s algorithm is $O(|V|^2)$. If we assume your game
map to be a big grid, then the number of cells in the grid is equal to the
number $|V|$. But this is still the worst case, and for most times we don’t need
to consider the worst case. Let me describe the Dijkstra’s algorithm.
Sunday, 19 July 2015
Fundamentals of calculus Chapter 3: differential equations of functions involving one independent variable.
Fundamentals of calculus
Chapter 3: differential equations of
functions involving one independent variable.
“Everything big is built out
of smaller units; and if the smaller units fail to cooperate the bigger ones
ultimately fall”
“A good learner never
accepts the educative information he comes across unless he knows for sure,
that there is no practical and logical way to contradict it”
Calculus as a whole evolved
to support something new, a differential equation. One marvellous fact about
differential equations are they don’t have any constants to describe the
graphical structure they represent. In the previous article ‘chapter 2’, we saw how
differentiation eliminates a constant. This fact can be taken advantage of to
frame differential equations that elaborate the actual rate of change of
different quantities. For example if, $z = ax^2 + bx +c$ then $\frac{dz}{dx} =
2ax + b$ and $\frac{d^2z}{dx^2} = 2a$ and $\frac{d^3z}{dx^3} = 0$.
Friday, 17 July 2015
Fundamentals of calculus Chapter 2: Integration
Fundamentals of calculus
Chapter 2: Integration
Integration is the
converse of differentiation. To understand this better, it must be known that
during differentiation an important information is lost. Let $\frac{dz(x)}{dx}
= z’(x)$. Then, we cannot get back $z(x)$ from $z’(x)$ because, while taking
the difference $z(x+\Delta x) – z(x)$ only the information regarding the
difference between a point in Z axis and a neighbourhood of that point is
retained. But the actual orientation is lost. Throughout this article, unless
stated $\Delta x$ is limited to zero. To see how this could cause the loss of a
piece of information, let me elaborate this with a simple algebraic example. Consider
$a-b = c$ to be true. Then we may write $a – (a-c) = c$, here $b=a-c$.
Wednesday, 15 July 2015
Fundamentals of calculus Chapter 1: Differentiation.
Fundamentals of calculus
Chapter 1: Differentiation.
Chapter 1: Differentiation.
Can we
really call calculus an art? Moreover, can we call mathematics an art? Most
mathematicians will agree to the answer: yes. We express ourselves, our creativity
through mathematics. It’s not always about calculation. Read my article ‘why do we need mathematics?’ to better understand
what I believe mathematics is really. I will not agree that the explanation I
had given there was enough. But anyway, I believe mathematics is an art because
it is not based on mere calculations but based on creating new rules, using
them to express what is around us in a more precise and defined manner. Most of
the time, mathematicians would define these rules not for the sake of answering
questions that follow up with our reality. But they just do it, in hope that
their discovery might come in handy to some scientist in the near future. Some
don’t even care about its necessity and for the sake of not expressing
themselves to be someone ignorant of the reality most people scramble through
physics equations or some other kind of scientific material to find the right
place for their equations or mathematical rules to fit in and prove to be
beneficial.
Subscribe to:
Posts (Atom)
Featured post
Why increasing complexity is not good?
“ Simplicity is the ultimate sophistication.” — Leonardo da Vinci Why is complicating things wrong ? - K Sr...
-
Read Sreram KS 's answer to Is over-confidence a bad thing? on Quora
-
Read Sreram KS 's answer to Which is hardest, Java, C or C++? on Quora
-
The unknown reality behind IQ tests For most people their carrier depends on clearing public exams. There is a lot of competition ou...