# Category: DP

## Calculate sum of all elements in a sub-matrix in constant time

Given a M x N matrix and two coordinates (p, q) and (r, s) which represents top-left and bottom-right coordinates of a sub-matrix of the given matrix, calculate the sum of all elements present in the sub-matrix in O(1) time. Here, 0 < = p < r < M and 0

Read More Calculate sum of all elements in a sub-matrix in constant time

## Find probability that a person is alive after taking N steps on the island

Given an island in the form of square matrix and a point inside the matrix where a person is standing. The person is allowed to move one step in any direction (right, left, top, down) on the matrix. If he steps outside the matrix, he dies. Calculate the probability that he is alive after he …

Read More Find probability that a person is alive after taking N steps on the island

## Best online courses for Data Structures And Algorithms

Friends, this article lists some the of best courses available online on Data Structures and Algorithms. We recommend to go through them to have strong basics.   Data Structures and Algorithms by Dr. Naveen Garg Lecture Series on Data Structures and Algorithms by Dr. Naveen Garg, Department of Computer Science and Engineering, IIT Delhi. Playlist details …

Read More Best online courses for Data Structures And Algorithms

## All-Pairs Shortest Paths – Floyd Warshall Algorithm

Given a set of vertices V in a weighted graph where its edge weights w(u, v) can be negative, find the shortest-path weights d(s, v) from every source s for all vertices v present in the graph. If the graph contains negative-weight cycle, report it.

Read More All-Pairs Shortest Paths – Floyd Warshall Algorithm

## Single-Source Shortest Paths – Bellman Ford Algorithm

Given a source vertex s from set of vertices V in a weighted graph where its edge weights w(u, v) can be negative, find the shortest-path weights d(s, v) from given source s for all vertices v present in the graph. If the graph contains negative-weight cycle, report it.

Read More Single-Source Shortest Paths – Bellman Ford Algorithm