Movatterモバイル変換


[0]ホーム

URL:


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

Commit8bf7b20

Browse files
committed
Solution submitted.
Further enhancement of solution is left to do.
1 parentf17da57 commit8bf7b20

File tree

34 files changed

+89
-7
lines changed

34 files changed

+89
-7
lines changed
3.71 MB
Binary file not shown.
3.12 MB
Binary file not shown.
1.64 MB
Binary file not shown.
3.98 MB
Binary file not shown.

‎src/google/Level4/Challenge2/README.md‎

Lines changed: 85 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,20 +117,26 @@ The problem is related to finding the network flow.
117117

118118
###Theory
119119
-https://algs4.cs.princeton.edu/40graphs
120+
- Maximum Flow Problem at Communications of the ACM :https://dl.acm.org/doi/10.1145/2628036
121+
-https://en.wikipedia.org/wiki/Maximum_flow_problem
120122
-[Network Flow Algorithms Starting Here](https://www.youtube.com/watch?v=LdOnanfc5TM&list=PLDV1Zeh2NRsDGO4--qE8yH72HFL1Km93P&index=33)
123+
124+
MIT Open Course Ware :
125+
https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-046j-design-and-analysis-of-algorithms-spring-2015/lecture-videos
126+
https://www.youtube.com/watch?v=8C_T4iTzPCU&list=PLUl4u3cNGP6317WaSNfmCvGym2ucw3oGp&index=19
121127
-13. Incremental Improvement: Max Flow, Min Cut](https://www.youtube.com/watch?v=VYZGlgzr_As)
122128
-14.https://www.youtube.com/watch?v=8C_T4iTzPCU
129+
123130
-https://www.youtube.com/watch?v=0CdxkgAjsDA
124131
-https://en.wikipedia.org/wiki/Flow_network
125132
-https://en.wikipedia.org/wiki/Max-flow_min-cut_theorem
126-
-https://en.wikipedia.org/wiki/Maximum_flow_problem
127133
-https://www.geeksforgeeks.org/cuts-and-network-flow
128134
-https://www.sciencedirect.com/science/article/pii/002200008590039X
129135
-https://stackoverflow.com/questions/36054690/how-to-use-dinics-algorithm-to-find-min-cut-edges-in-undireted-graph
130136
- Actual Complexity of Max Flow Algorithmshttps://codeforces.com/blog/entry/52714
131137

132138

133-
###First Example
139+
###First Example, Edmonds-Karp Algorithm
134140

135141
```java
136142

@@ -222,13 +228,25 @@ public class EscapePods {
222228
return solveWithFordFulkerson(transform(entrances, exits, path));
223229
}
224230
}
225-
```
231+
```
232+
233+
Ford-Fulkerson - Time Complexity: O(fV^2), where f is the max flow
234+
235+
The idea of Edmonds-Karp is to use BFS in Ford-Fulkerson
236+
implementation as BFS always picks a path with minimum
237+
number of edges. When BFS is used, the worst case time
238+
complexity can be reduced to O(VE^2).
239+
240+
226241
###Dinic's Algorithm
242+
243+
Time Complexity: O(EV²)
244+
227245
From further research, a more efficient algorithm - Dinic's algorithm selected.
228246

229247
#####Theory
230248
-https://en.wikipedia.org/wiki/Dinic%27s_algorithm
231-
-https://www.youtube.com/watch?v=M6cm8UeeziI&list=PLDV1Zeh2NRsDGO4--qE8yH72HFL1Km93P&index=42
249+
-WilliamFiset - Graphh Theory -[Playlist](https://www.youtube.com/watch?v=M6cm8UeeziI&list=PLDV1Zeh2NRsDGO4--qE8yH72HFL1Km93P&index=42)
232250
-https://github.com/ADJA/algos/blob/master/Graphs/Dinic.cpp
233251
-https://www.geeksforgeeks.org/dinics-algorithm-maximum-flow
234252
-https://www.hackerearth.com/practice/algorithms/graphs/maximum-flow/tutorial
@@ -508,4 +526,66 @@ than 0 was transformed as edges of the graph.
508526

509527
The implementation was slightly modified as my implementation.
510528

511-
###Search For Better Algorithm
529+
Further optimization of implemented Dinic's algorithm and also finding better
530+
version is in progress.
531+
532+
533+
>Ford–Fulkerson algorithm, Edmond Karp algorithm and Dinic’s algorithm
534+
535+
536+
###Finding More Efficient
537+
538+
Push-Relabel Maximum Flow Algorithm
539+
Push-Relabel approach is the more efficient than Ford-Fulkerson algorithm. In this post, Goldberg’s “generic” maximum-flow algorithm is discussed that runs in O(V^2E) time. This time complexity is better than O(E^2V) which is time complexity of Edmond-Karp algorithm (a BFS based implementation of Ford-Fulkerson). There exist a push-relabel approach based algorithm that works in O(V3) which is even better than the one discussed here.
540+
541+
Similarities with Ford Fulkerson
542+
Like Ford-Fulkerson, Push-Relabel also works on Residual Graph (Residual Graph of a flow network is a graph which indicates additional possible flow. If there is a path from source to sink in residual graph, then it is possible to add flow).
543+
Differences with Ford Fulkerson
544+
Push-relabel algorithm works in a more localized. Rather than examining the entire residual network to find an augmenting path, push-relabel algorithms work on one vertex at a time (Source : CLRS Book).
545+
In Ford-Fulkerson, net difference between total outflow and total inflow for every vertex (Except source and sink) is maintained 0. Push-Relabel algorithm allows inflow to exceed the outflow before reaching the final flow. In final flow, the net difference is 0 for all except source and sink.
546+
Time complexity wise more efficient.
547+
548+
Dinic's algorithm can be improved to O(VElogV) with dynamic trees.
549+
550+
There exists another more efficient algorithm James B Orlin's + KRT (King, Rao, Tarjan)'s algorithm to O(VE).
551+
https://dspace.mit.edu/handle/1721.1/88020
552+
553+
-https://failedturing.blogspot.com/2018/12/harvard-compsci-224-advanced-algorithms.html
554+
555+
556+
####Improving Dinic's To O(VElogV) With Dynamic Trees
557+
558+
-https://courses.csail.mit.edu/6.851/spring12/lectures/L19.html
559+
-https://www.youtube.com/playlist?list=PLUl4u3cNGP61hsJNdULdudlRL493b-XZf
560+
-https://courses.csail.mit.edu/6.851/spring12/
561+
562+
-https://sites.google.com/site/indy256/algo/link-cut-tree-connectivity
563+
-https://github.com/jeffrey-xiao/competitive-programming/blob/master/src/codebook/datastructures/LinkCutTree.java
564+
-https://codeforces.com/blog/entry/75885
565+
-https://github.com/detel/Data-Structures/blob/master/LinkCutTree.java
566+
-https://github.com/jeffrey-xiao/competitive-programming/blob/master/src/codebook/datastructures/LinkCutTree.java
567+
-https://posobin.com/advancedDS/
568+
569+
570+
Amortized Analysis
571+
In computer science, amortized analysis is a method for analyzing a given algorithm's complexity, or how much of a resource, especially time or memory, it takes to execute. The motivation for amortized analysis is that looking at the worst-case run time per operation, rather than per algorithm, can be too pessimistic. - Wikipedia
572+
573+
Amortization
574+
In computer science, amortised analysis is a method of analyzing the execution cost of algorithms over a sequence of operations. In the context of zoning regulations, amortisation refers to the time period a non-conforming property has to conform to a new zoning classification before the non-conforming use becomes prohibited. - Wikipedia
575+
576+
Amortization
577+
A technique from financial analysis, but we've appropriated it in computer science as an analysis technique to say, well, let's not worry about every single operation worst case cost, let's just worry about the total operation, the sum of all the operations cost. -https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-046j-design-and-analysis-of-algorithms-spring-2015/lecture-videos/lecture-5-amortization-amortized-analysis
578+
579+
This lecture is about a cool data structure for maintaining rooted trees (potentially very unbalanced) in O(log n) time per operation. The operations include linking two trees together by adding an edge, and cutting an edge to split a tree into two trees, so the data structure is called link-cut trees. This result is our first solving a dynamic graph problem (where in general we can insert and delete edges); next lecture will see other solutions for trees and generalization from trees to undirected graphs. Link-cut trees have specific advantages in that they can represent information over root-to-node paths; for example, they can easily compute the min/max/sum of values stored in nodes or edges along any root-to-node paths. Most importantly, link-cut trees introduce two powerful tree decompositions: preferred-path decomposition (which we already used in Tango trees) and heavy-light decomposition. As we will cover them, link-cut trees also demonstrate how a surprisingly “care-free” use of splay trees is actually still efficient.
580+
581+
582+
Goldberg and Tarjan O(nm log(n*/m)))
583+
https://www.semanticscholar.org/paper/A-new-approach-to-the-maximum-flow-problem-Goldberg-Tarjan/c8fb31bef2bf64bfbde869601cb624812a1d066e
584+
https://dl.acm.org/doi/10.1145/12130.12144
585+
https://deepai.org/publication/a-strongly-polynomial-algorithm-for-linear-exchange-markets
586+
https://web.stanford.edu/class/archive/cs/cs161/cs161.1176
587+
588+
CSE 542. Advanced Data Structures and Algorithms Spring 2013https://www.arl.wustl.edu/~jst/cse/542/
589+
590+
#Submission
591+
Other solutions was not implmented due to time limitation.

‎src/google/Level4/Challenge2/Solution.java‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ abstract class NetworkFlowBase {
114114
* @param path - The number of nodes in the graph including s and t.
115115
*/
116116
publicNetworkFlowBase(int[]entrances,int[]exits,int[][]path ) {
117+
118+
// As per requirement: A most 2000000 bunnies that will fit at a time.
117119
MAX_VAL =20000;
118120

119121
this.path =path;
@@ -323,8 +325,8 @@ private int dfs(int at, int[] next, int flow) {
323325
intcap =edge.remainingCapacity();
324326

325327
if (cap >0 && (level[edge.to] ==level[at] +1 )) {
326-
327-
intbottleNeck =dfs(edge.to,next,flow>cap ?cap :flow);
328+
flow =flow >cap ?cap :flow;
329+
intbottleNeck =dfs(edge.to,next,flow );
328330

329331
if (bottleNeck >0 ) {
330332
edge.augment(bottleNeck);
1.24 MB
Binary file not shown.
6.69 MB
Binary file not shown.
6.69 MB
Binary file not shown.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp