Coder Social home page Coder Social logo

breadth_first_search's Introduction

breadth_first_search_pythonn

Breadth First Search (BFS) Algorithm

This project contains an example of the Breadth First Search (BFS) algorithm in the Python language. The algorithm performs a breadth-first search on a graph.

Algorithm Description

  • The project uses three different colors, "black," "white," and "gray," to indicate the states of nodes.
  • The working of the BFS algorithm can be summarized in the following steps:
    1. The starting node is marked as gray and added to the queue.
    2. As long as the queue is not empty, the following steps are repeated:
      • A node is removed from the queue, and operations are performed on it.
      • The neighbors of the removed node are checked.
      • If neighbors have not been visited before, they are marked as gray and added to the queue.
      • The processed node is marked as black.
    3. When all nodes are visited, the BFS process is completed.

Usage

To run this Python code, you can follow these steps:

  1. Include the math module in your project, which is used for mathematical operations.
  2. Copy the code and run it in a Python environment.
  3. You can update the G variable to change the example graph structure. This graph is represented using key-value pairs. Keys represent nodes, and values represent adjacent nodes.
  4. The Point class is used to define node objects. You can customize this class according to your needs.
  5. The colors dictionary contains RGB values of colors to determine the states of nodes. You can modify these colors to suit your requirements.
  6. Run the code and observe the output of the BFS algorithm.

Example Output

Breadfirst: 5 3 7 2 4 8

This output demonstrates that the BFS algorithm started from the "5" node and visited other nodes in a breadth-first manner.

breadth_first_search's People

Contributors

melisaates avatar

Stargazers

Arman Gencer avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.