Outdoor foreach runs n = | c1 | times (where | x | is the size of c1 ), and the internal foreach is m = | c2 | time. This is O (n * m) times overall.
How can I imagine simple algorithms with the following complexities?
This is the same as O (n ^ 2). What takes O (n ^ 2) time will drink a toast with every other person at the party, assuming there are exactly two people in the toast, and only one person makes the toast at a time.
Same as above; O (n ^ 2) prevails. Another example of O (n ^ 2) effort is to plant trees in a square garden of length n , assuming that each tree needs constant time to plant, and when you plant a tree, other trees are excluded from its surroundings.
An example of this would be to search for a word in a dictionary by repeatedly selecting the middle of the page area to search in the following. (In other words, binary search.)
Use the algorithm above, but now you need to find every word in the dictionary.
John feminella
source share