I've searched but I can't seem to find the complexity of the Flood Fill Algorithm (Four-way ver.). What exactly is the complexity in big O notation?
标签:
time-complexity
相关问题
- Time complexity for recursion in for loop
- Is there a sorting algorithm with linear time comp
- Time complexity of Array.from
- Time/space complexity of in-built python functions
- Efficiently searching a common node in 2 singly li
相关文章
- Is there any function that is in o(1)?
- TreeMap - Search Time Complexity
- Given a collection of integers and threshold value
- Sorting nearly sorted array with O(n*Log(K)) compl
- Time Complexity of Permutations of a String
- Big O Notation for two non-nested loops
- Is lseek() O(1) complexity?
- Approach and Code for o(log n) solution
In worst-case, all cells of the matrix will be covered.
In terms of complexity time, this algorithm will be equals the recursive one: O(N×M)O(N×M), where N and M are the dimensions of the input matrix. The key idea is that in both algorithms each node is processed at most once.
Please refer below link for better understaning and more cases:
https://www.hackerearth.com/practice/algorithms/graphs/flood-fill-algorithm/tutorial/
The time complexity would be O(4*mn)=(mn) because each cell of matrix is processed at most 4 times. For Example, a particular cell can be called by its top, down, left or right cell.
The complexity of the flood fill algorithm is proportional to the number of pixels in the filled area. So, if you have e.g. a square, and M is the number of pixels in the square and N is the length of the side of a square, then M = N^2 and the complexity is O(M) = O(N^2).
By the way, this question has already been answered in a comment in Stackoverflow. See How can I improve the performance of my flood-fill routine?