Hello Everyone,

I am not that expert in coding, just coding on a level that helps me to implement some wireless modules /packets/ links/ etc....

I was wondering if we could implement AI search algorithms using C code, as an example, in this image:

[IMG][/IMG]


It is the Bidirectional search algorithm, I have searched to find if anyone has done it before but unfortunately I didn't find any.

My question is, if I decided to use C to implement the above template, how long (approximately) would it take to write it in C Or C++. Again I am not expert, but what I am thinking is that here are many experts who could figure out things like this.

Thanks.

Dani AI

Generated

Short answer: yes — bidirectional search is straightforward to implement in C or C++. For the wireless/module use case described by , represent devices as graph nodes and links as edges (weight = hops, latency, or link quality). C++ plus the STL (or Boost.Graph) will cut development time; plain C is doable but needs explicit data structures and memory management.

A concise implementation plan:

  • Choose a graph representation (adjacency list is usually best for sparse networks).
  • Maintain two frontiers (forward and backward), two visited sets, and two parent maps (one per direction).
  • Alternate expansion (or expand the smaller frontier) and after each neighbor visit check if that neighbor is in the opposite visited set. If so, record the meeting node and reconstruct the path by following parent pointers from both sides.
  • For weighted graphs use two Dijkstra searches (priority queues) or a bidirectional A* variant with careful, consistent heuristics.

A minimal pseudocode sketch:

frontier_f = {start}; frontier_b = {goal}
visited_f[start]=true; visited_b[goal]=true
parent_f[start]=NONE; parent_b[goal]=NONE

while frontier_f and frontier_b not empty:
    expand smaller frontier
    for neighbor in neighbors(current):
        if neighbor in opposite visited:
            meeting = neighbor
            reconstruct path(parent_f, parent_b, meeting)
        if neighbor not visited in this search:
            mark visited, set parent, add to next frontier

Common pitfalls and tips: when edges are directed, use the reversed edge set for the backward search; ensure path reconstruction stitches the two parent chains correctly; beware memory leaks in C and prefer hash maps for arbitrary node ids in C++; ensure heuristics in bidirectional A* are admissible and consistent. As noted, studying existing AI/search repositories speeds up design.

Time estimate: a competent C++ developer can produce a working BFS-based bidirectional search in a few hours to a day. Making it robust (weights, heuristics, tests, edge cases, embedded constraints) may take several days to a week. Test on small graphs, trivial edge cases, and instrument frontier sizes to validate correctness and performance. See Bidirectional search for algorithm notes.

Recommended Answers

All 2 Replies

If you understand the logic behind the Search-Algorithm, C++ (or even C) could certainly be used to implement it.
Without knowing exactly how much you know about programming it is impossible to know how much time it would take you.

I used the 'google-search' and found this zip file you might find interresting: click

Thank You for the link, it contains good functions and classes to be used.

For the experience part, I can write any program, but I can't assume how long and what classes, functions, data structures it needs to complete before even starting. I believe some could easily figure out such things by looking at some algorithm for example, or by looking at some flow-chart.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.