breadth-first-search

Retrieving all paths in an OWL class hierarchy with SPARQL and Jena

余生长醉 提交于 2019-12-04 17:58:48
I have an RDF graph of with a hierarchy three levels deep. I want to retrieve all the paths starting from the root of the class hierarchy (i.e., owl:Thing ) down to classes in the third level without using a reasoner. For instance, I would like the path C 1 → C 2 → C 3 is a path, where each C i is a class at the i th level of the hierarchy. I need to retrieve all the paths in the RDF graph using the breadth first search algorithm with no considerations to the object properties in the graph. Given some data like this (where length of the class name is an indication of the

Breadth-First search in Java

落花浮王杯 提交于 2019-12-04 16:49:59
I am having to run a breadth-first search in Java for an assignment. I have a 5x5 grid of tiles (24 in total - 1 tile is left 'blank'). The point of the search is to rearrange the tiles by moving the 'blank' up, down, left or right to eventually rearrange the tiles into the correct order. To do this search, I have created an Arraylist 'queue'. I have a method that takes the state at index 0 of this arraylist, finds each of the legal moves that can follow and then adds them each to the end of the arraylist. In theory, this continues until the 'goalstate' is eventually found. The problem is that

Can this breadth-first search be made faster?

不打扰是莪最后的温柔 提交于 2019-12-04 12:35:15
问题 I have a data set which is a large unweighted cyclic graph The cycles occur in loops of about 5-6 paths. It consists of about 8000 nodes and each node has from 1-6 (usually about 4-5) connections. I'm doing single pair shortest path calculations and have implemented the following code to do a breadth-first search. from Queue import Queue q = Queue() parent = {} fromNode = 'E1123' toNode = 'A3455' # path finding q.put(fromNode) parent[fromNode] = 'Root' while not q.empty(): # get the next node

Breadth-First Search using State monad in Haskell

心已入冬 提交于 2019-12-04 10:51:31
问题 Recently, I've asked a question for building DFS tree from Graph in Stackoverflow and had learned that it can be simply implemented by using State Monad. DFS in haskell While DFS requires to track only visited nodes, so that we can use 'Set' or 'List' or some sort of linear data structure to track visited nodes, BFS requires 'visited node' and 'queue' data structure to be accomplished. My pseudocode for BFS is Q = empty queue T = empty Tree mark all nodes except u as unvisited while Q is

Is the runtime of BFS and DFS on a binary tree O(N)?

♀尐吖头ヾ 提交于 2019-12-04 10:27:16
问题 I realize that runtime of BFS and DFS on a generic graph is O(n+m), where n is number of nodes and m is number of edges, and this is because for each node its adjacency list must be considered. However, what is the runtime of BFS and DFS when it is executed on a binary tree? I believe it should be O(n) because the possible number of edges that can go out of a node is constant (i.e., 2). Please confirm if this is the correct understanding. If not, then please explain what is the correct time

Which Procedure we can use for Maze exploration BFS or DFS

自古美人都是妖i 提交于 2019-12-04 10:00:56
I know we can use DFS for maze exploration. But I think we can also use BFS for maze exploration. I'm little bit confused here because most of the books and articles that I've read had used DFS for this problem. What I think is that the Best Case time complexity of DFS will be better as compared to BFS. But Average and Worst Case time complexity will be same for both BFS & DFS and thats why we prefer DFS over BFS. Am I right or I'm having some misconception They have similar running time , but either may greatly outperform the other on any given problem simply due to the order in which the

Breadth first traversal of object

ε祈祈猫儿з 提交于 2019-12-04 08:01:46
问题 I am making a program that solves a puzzle game, and it finds all the possible moves on a board and puts all the possible resulting boards in an object. Then it finds all the possible moves for the resulting boards, and so on. The object will look something like this: { "board": { "starts": [[0,0],[0,3]], "blocks": [[3,0],[3,3]], "ends": [[2,4]] }, "possibleMoves": [ { "board": { "starts": [[0,0],[2,3]], "blocks": [[3,0],[3,3]], "ends": [[2,4]] }, "possibleMoves":[ { "board": {},

Finding simple path between two vertices in a tree (undirected simple graph)

烈酒焚心 提交于 2019-12-04 06:43:44
问题 Given two vertices (A and B) and a tree (G) (undirected simple graph) - Find the vertices in the simple path between A and B in G. The algorithm should run in O(V) complexity. for instance - find the vertices in the simple path between a and b: d<->k k<->a k<->b the answer should be : k I have tried to modify BFS to accomplish the goal but it doesn't seem to work so far. Any suggestions? 回答1: If the problem is reconstructing the path after you found the distance, adjust the BFS in the

How to get the path between 2 nodes using Breadth-First Search?

ぐ巨炮叔叔 提交于 2019-12-03 23:53:40
I am trying to find a path between two nodes in a graph , where the edges are unweighted . I am using a Breadth First Search , which stops when it finds the target, in order to find the existence of a path, but I am not sure how to get the path itself. I tried looking at the list of visited nodes, but this did not seem to help. I saw someone answer this question using prolog, but I am a C++ programmer. I also looked at Dijkstras algorithm , but this seems like over kill, since a simple Breadth-first Search has got me almost the whole way. How to get the path between 2 nodes using Breadth-First

Shortest path in JavaScript

与世无争的帅哥 提交于 2019-12-03 12:36:05
I have been searching for weeks for a way to compute shortest paths in JavaScript. I have been playing with the book Data Structures and Algorithms by Groner (aptly named) at https://github.com/loiane/javascript-datastructures-algorithms/tree/master/chapter09 . The trouble I keep on finding is that the code is so customized that it is almost impossible to rewrite to produce the desired results. I would like to be able to get the shortest path from any given vertex to any other, rather than, as Groner codes it, just the list of everything from A. I would like to be able to get, for example, the