Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Performance Enhancement: Replace list with collections.deque in graph algorithms #12857

Closed
Labels
enhancementThis PR modified some existing files
@riokuma

Description

Feature description

Summary

The current implementation of the breadth_first_search_shortest_path_2.py uses a Python list to simulate a queue. However, using a list for this purpose might be inefficient because removing the first element (pop(0)) has a time complexity of O(n) and affects the overall performance. Python's collections.deque is optimized for such use cases and offers O(1) time complexity for appending and popping from both ends.

Suggested update

Replace the list used as a queue with a collections.deque to improve performance and align with best practices for implementing BFS in Python.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementThis PR modified some existing files

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /