Cyclic Sort
Cyclic SortTime Complexcity: O(n)Space Complexity: O(1)for i in 0 to n-1: while nums[i] is not the value expected at the spot: let d = destination index to which nums[i] should…
Cyclic SortTime Complexcity: O(n)Space Complexity: O(1)for i in 0 to n-1: while nums[i] is not the value expected at the spot: let d = destination index to which nums[i] should…
# O(n^3)import itertoolsdef substring(s): substrings = [] for i in range(len(s)): for j in range(i + 1, len(s)+1): substrings.append(s[i:j]) return substrings# O(2^N)def subset(s): store = [] running = [] def…
Topological sorting for a graph is not possible if the graph is not a DAG.from collections import defaultdict class Graph: def __init__(self, vertices): self.graph = defaultdict(list) self.vertices = vertices def…