Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bridge Trees #1781

Closed
wants to merge 2 commits into from
Closed

Bridge Trees #1781

wants to merge 2 commits into from

Conversation

UtsavKash19
Copy link

adding Bridge trees algo

Copy link

github-actions bot commented Nov 3, 2024

Thank you for submitting your pull request! 🙌 We'll review it as soon as possible.). If there are any specific instructions or feedback regarding your PR, we'll provide them here. Thanks again for your contribution! 😊

Copy link

github-actions bot commented Nov 3, 2024

⚡️ Lighthouse Report for the Deploy Preview of this PR 🚀

🔗 Site: Algo | Live Site

URL 🌐 Performance Accessibility Best Practices SEO 📊
/algo/ 🔴 47 🟢 96 🟡 75 🟡 86 📄
/algo/docs 🔴 45 🟢 96 🟡 75 🟢 100 📄
/algo/blog 🟡 67 🟢 92 🟢 96 🟡 86 📄

@ajay-dhangar ajay-dhangar added gssoc-ext Contributions made as part of GirlScript Summer of Code Extended Edition. level1 GirlScript Summer of Code | Contributor's Levels labels Nov 3, 2024
Copy link
Owner

@ajay-dhangar ajay-dhangar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please carefully read our contribution guidelines. They provide information on our documentation format and syntax.

@UtsavKash19
Copy link
Author

I noticed that the PR validation check is failing, while other checks have passed successfully. I will review the logs for the failing check to address any issues. If there are specific concerns or feedback on the implementation, I’d appreciate your insights!

Copy link
Owner

@ajay-dhangar ajay-dhangar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My comment concerns the format of your code in the .md file for our docs. Please follow our format for best practices.

@UtsavKash19
Copy link
Author

UtsavKash19 commented Nov 4, 2024

what changes you requested @ajay-dhangar

@ajay-dhangar
Copy link
Owner

what changes you requested @ajay-dhangar

We need only markdown files, so please write your code in markdown language and save your file with a .md extension. Also, please follow our format and syntax.

@UtsavKash19
Copy link
Author

Bridge Tree Construction

Introduction

A bridge in a graph is an edge that, if removed, would disconnect the graph. A bridge tree is a graph where each node represents a component of the original graph that does not contain any bridges, and the edges of the bridge tree represent the bridges of the original graph.

Properties of the Bridge Tree

  1. Bridges as Edges: All the bridges of the original graph are represented as edges in the bridge tree.
  2. Connected: The bridge tree is connected if the original graph is connected.
  3. Acyclic: The bridge tree does not contain any cycles.
  4. Nodes Count: The bridge tree will contain ≤ N nodes, where N is the number of nodes in the original graph.
  5. Edges Count: The bridge tree will contain ≤ N−1 edges, where N is the number of nodes in the original graph.

Time Complexity

  • Bridges Finding: The bridges in the graph can be found in O(N + M), where N is the number of nodes and M is the number of edges.
  • DFS Complexity: The time complexity for the DFS function is O(N + M).

Thus, the total time complexity for constructing the bridge tree is O(N + M).

Pseudocode for Constructing the Bridge Tree

DFS Function

void dfs(int node, int component_number) {
    component[node] = component_number; // Mark the component number for the node
    vis[node] = true; // Mark the node as visited
    for each adjacent edge where the edge is not a bridge {
        int next = other endpoint of the edge;
        if (vis[next] == true) {
            continue; // Skip if already visited
        }
        dfs(next, component_number); // Recursively explore
    }
}
void main() {
    // Step 1: Find all the bridges in the graph
    find_bridges(); // This function is assumed to find all the bridges (refer to prerequisites for this)
    
    // Step 2: For each node, call DFS to identify components
    for (int i = 1; i <= n; ++i) {
        if (vis[i] == false) {
            dfs(i, unique_component_number); // Call DFS for unvisited nodes, with a unique component number
            unique_component_number++; // Increment the component number for each DFS call
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gssoc-ext Contributions made as part of GirlScript Summer of Code Extended Edition. level1 GirlScript Summer of Code | Contributor's Levels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants