Skip to content

Tag: algorithm

Creating a graph from a string

Let’s consider a “maze” defined by a string, for example The sign “#” denotes a wall and the sign “*” denotes the possible path. Moreover “S” is the starting point and “F” is the destination. I would like to apply a path searching algorithm to …

N-Queens II using backtracking is slow

The n-queens puzzle is the problem of placing n queens on an n x n chessboard such that no two queens attack each other. Given an integer n, return the number of distinct solutions to the n-queens puzzle. https://leetcode.com/problems/n-queens-ii/ My solution: It fails at n=8. I can’t figure out why, an…

Algorithm for Connected Components of Graph

I am looking for the most efficient algorithm in order to find both the number of connected components in a network, and the number of nodes for each connected component. Example: Given the following inputs: I would receive the following output: This is what I have so far: I have found a way to iterate throug…