wingkwong / leetcode-the-hard-way

LeetCode The Hard Way - From Absolute Beginner to Quitter. Join Discord: https://discord.com/invite/Nqm4jJcyBf
https://linktr.ee/leetcodethehardway
883 stars 221 forks source link

Tutorial Writeup - Floyd–Warshall Algorithm #63

Open wingkwong opened 2 years ago

wingkwong commented 2 years ago

Markdown Path: tutorials/graph-theory/floyd-warshall-algorithm.md

You can include other info related to this topic as you wish.

i-dipanshu commented 2 years ago

Hey @wingkwong
I would love to work this issue. Could you please assign me this task

wingkwong commented 2 years ago

Sure

wingkwong commented 2 years ago

Free this issue at this moment as dipanshu got 2 writeups already. Free feel to leave a comment here if you wanna pick up.

wizeewig commented 2 years ago

@wingkwong I would love to work on this. Would you please assign this to me.

wingkwong commented 2 years ago

as wizeewig got one writeup on hand, i'll assign this one to Sowham-3098

wingkwong commented 2 years ago

@Sowham-3098 Any updates?

Bobliuuu commented 2 years ago

Hey @wingkwong, I can take this one as well, since it isn't active.

wingkwong commented 2 years ago

@Sowham-3098 Are you still working on it?

wingkwong commented 2 years ago

@Sowham-3098 Thanks for your confirmation. @Bobliuuu Assigned to you now.

wingkwong commented 2 years ago

Unassigned due to inactivity.

Sanchita1304 commented 1 year ago

Hi, I would like to do this work. Can you assign me this work.

wingkwong commented 1 year ago

@Sanchita1304 you already got one assignment. please finish that one first.

Sanchita1304 commented 1 year ago

okk

AnUsHkAIT commented 1 year ago

Hey! I would love to make my contribution here. Please assign me this task.

wingkwong commented 1 year ago

@AnUsHkAIT assigned. please check out contribution guide first.

AnUsHkAIT commented 1 year ago

git add . git commit -m "Title: FLOYD WARSHALL Description: DEEP LEARNING OF FLOYD WARSHALL ALGORITH WITH EXAMPLES AND PROBLEM STATEMENTS

Overview

Floyd Warshall is also known as Multisource Shortest Path . It not helps you to find /work on positive cycle but also on Negative cycle as well.

Real life Applications

  1. Robotics:- Robots are used to navigate through an environment, Floyd Warshall can be used to plan the shortest paths between different points/different areas.

  2. Transportation Networks: This can help in urban planning, traffic optimization, and efficient routing for emergency services like ambulance, fire brigade etc.

  3. Infrastructure Maintenance Planning: This helps in planning cost-effective maintenance schedules, reducing downtime.

Time Complexity O(V^3), where V is the number of vertices in the graph. --Floyd Warshall algorithm performs well on small to moderately-sized graphs with a relatively low number of vertices. --The cubic time complexity makes the algorithm less efficient for large graphs, particularly those with a high number of vertices. Space Complexity O(V^2), where V is the number of vertices in the graph. --Floyd Warshall performs well on graphs with a moderate number of vertices, where the cubic time complexity and square space complexity are manageable. --It may not be suitable in scenarios where the available memory resources are limited or strictly constrained." LEETCODE PROBLEMS

[605. Can Place Flowers] (https://leetcode.com/problems/can-place-flowers/) You have a long flowerbed in which some of the plots are planted, and some are not. However, flowers cannot be planted in adjacent plots.

Given an integer array flowerbed containing 0's and 1's, where 0 means empty and 1 means not empty, and an integer n, return true if n new flowers can be planted in the flowerbed without violating the no-adjacent-flowers rule and false otherwise.

Example 1:

Input: flowerbed = [1,0,0,0,1], n = 1 Output: true Example 2:

Input: flowerbed = [1,0,0,0,1], n = 2 Output: false

Constraints:

--Explanation This problem is about planting flowers in a flowerbed without violating the rule that no two flowers can be planted adjacent to each other. You're given a flowerbed represented as an array where 0 represents an empty plot and 1 represents a plot with a flower already planted. You need to determine if it's possible to plant 'n' new flowers in the flowerbed without violating the rule. Here's a step-by-step explanation:

Now, you need to check if it's possible to plant 'n' new flowers in the flowerbed without breaking this rule. Here's how you can approach this problem:

Code public boolean canPlaceFlowers(int[] flowerbed, int n) { int count = 0; int i = 0;

while (i < flowerbed.length) {
    if (flowerbed[i] == 0 && (i == 0 || flowerbed[i - 1] == 0) && (i == flowerbed.length - 1 || flowerbed[i + 1] == 0)) {
        flowerbed[i] = 1;  
        count++;
    }
    i++;
}

return count >= n;

} Time Complexity O(n) Space Complexity O(1)

wingkwong commented 6 months ago

Unassigned due to inactivity

Jennifer-tech commented 1 month ago

Hi @wingkwong , Please is this up to be assigned?, I will like to work on it

Jennifer-tech commented 1 month ago

@wingkwong can it have the hacktoberfest label?