Flood Fill Four-Way Algorithm Complexity

后端 未结 4 1323
忘掉有多难
忘掉有多难 2021-01-27 14:14

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?

4条回答
  •  执笔经年
    2021-01-27 14:32

    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/

提交回复
热议问题