*** 1 Progress [(?,O(n^1))] *** Considered Problem: Strict DP Rules: Strict TRS Rules: f(x,0()) -> s(0()) f(s(x),s(y)) -> s(f(x,y)) g(0(),x) -> g(f(x,x),x) Weak DP Rules: Weak TRS Rules: Signature: {f/2,g/2} / {0/0,s/1} Obligation: Innermost basic terms: {f,g}/{0,s} Applied Processor: DependencyPairs {dpKind_ = DT} Proof: We add the following dependency tuples: Strict DPs f#(x,0()) -> c_1() f#(s(x),s(y)) -> c_2(f#(x,y)) g#(0(),x) -> c_3(g#(f(x,x),x),f#(x,x)) Weak DPs and mark the set of starting terms. *** 1.1 Progress [(?,O(n^1))] *** Considered Problem: Strict DP Rules: f#(x,0()) -> c_1() f#(s(x),s(y)) -> c_2(f#(x,y)) g#(0(),x) -> c_3(g#(f(x,x),x),f#(x,x)) Strict TRS Rules: Weak DP Rules: Weak TRS Rules: f(x,0()) -> s(0()) f(s(x),s(y)) -> s(f(x,y)) g(0(),x) -> g(f(x,x),x) Signature: {f/2,g/2,f#/2,g#/2} / {0/0,s/1,c_1/0,c_2/1,c_3/2} Obligation: Innermost basic terms: {f#,g#}/{0,s} Applied Processor: UsableRules Proof: We replace rewrite rules by usable rules: f(x,0()) -> s(0()) f(s(x),s(y)) -> s(f(x,y)) f#(x,0()) -> c_1() f#(s(x),s(y)) -> c_2(f#(x,y)) g#(0(),x) -> c_3(g#(f(x,x),x),f#(x,x)) *** 1.1.1 Progress [(?,O(n^1))] *** Considered Problem: Strict DP Rules: f#(x,0()) -> c_1() f#(s(x),s(y)) -> c_2(f#(x,y)) g#(0(),x) -> c_3(g#(f(x,x),x),f#(x,x)) Strict TRS Rules: Weak DP Rules: Weak TRS Rules: f(x,0()) -> s(0()) f(s(x),s(y)) -> s(f(x,y)) Signature: {f/2,g/2,f#/2,g#/2} / {0/0,s/1,c_1/0,c_2/1,c_3/2} Obligation: Innermost basic terms: {f#,g#}/{0,s} Applied Processor: PredecessorEstimation {onSelection = all simple predecessor estimation selector} Proof: We estimate the number of application of {1} by application of Pre({1}) = {2,3}. Here rules are labelled as follows: 1: f#(x,0()) -> c_1() 2: f#(s(x),s(y)) -> c_2(f#(x,y)) 3: g#(0(),x) -> c_3(g#(f(x,x),x) ,f#(x,x)) *** 1.1.1.1 Progress [(?,O(n^1))] *** Considered Problem: Strict DP Rules: f#(s(x),s(y)) -> c_2(f#(x,y)) g#(0(),x) -> c_3(g#(f(x,x),x),f#(x,x)) Strict TRS Rules: Weak DP Rules: f#(x,0()) -> c_1() Weak TRS Rules: f(x,0()) -> s(0()) f(s(x),s(y)) -> s(f(x,y)) Signature: {f/2,g/2,f#/2,g#/2} / {0/0,s/1,c_1/0,c_2/1,c_3/2} Obligation: Innermost basic terms: {f#,g#}/{0,s} Applied Processor: RemoveWeakSuffixes Proof: Consider the dependency graph 1:S:f#(s(x),s(y)) -> c_2(f#(x,y)) -->_1 f#(x,0()) -> c_1():3 -->_1 f#(s(x),s(y)) -> c_2(f#(x,y)):1 2:S:g#(0(),x) -> c_3(g#(f(x,x),x),f#(x,x)) -->_2 f#(x,0()) -> c_1():3 -->_1 g#(0(),x) -> c_3(g#(f(x,x),x),f#(x,x)):2 -->_2 f#(s(x),s(y)) -> c_2(f#(x,y)):1 3:W:f#(x,0()) -> c_1() The following weak DPs constitute a sub-graph of the DG that is closed under successors. The DPs are removed. 3: f#(x,0()) -> c_1() *** 1.1.1.1.1 Progress [(?,O(n^1))] *** Considered Problem: Strict DP Rules: f#(s(x),s(y)) -> c_2(f#(x,y)) g#(0(),x) -> c_3(g#(f(x,x),x),f#(x,x)) Strict TRS Rules: Weak DP Rules: Weak TRS Rules: f(x,0()) -> s(0()) f(s(x),s(y)) -> s(f(x,y)) Signature: {f/2,g/2,f#/2,g#/2} / {0/0,s/1,c_1/0,c_2/1,c_3/2} Obligation: Innermost basic terms: {f#,g#}/{0,s} Applied Processor: Decompose {onSelection = all cycle independent sub-graph, withBound = RelativeAdd} Proof: We analyse the complexity of following sub-problems (R) and (S). Problem (S) is obtained from the input problem by shifting strict rules from (R) into the weak component. Problem (R) Strict DP Rules: f#(s(x),s(y)) -> c_2(f#(x,y)) Strict TRS Rules: Weak DP Rules: g#(0(),x) -> c_3(g#(f(x,x),x),f#(x,x)) Weak TRS Rules: f(x,0()) -> s(0()) f(s(x),s(y)) -> s(f(x,y)) Signature: {f/2,g/2,f#/2,g#/2} / {0/0,s/1,c_1/0,c_2/1,c_3/2} Obligation: Innermost basic terms: {f#,g#}/{0,s} Problem (S) Strict DP Rules: g#(0(),x) -> c_3(g#(f(x,x),x),f#(x,x)) Strict TRS Rules: Weak DP Rules: f#(s(x),s(y)) -> c_2(f#(x,y)) Weak TRS Rules: f(x,0()) -> s(0()) f(s(x),s(y)) -> s(f(x,y)) Signature: {f/2,g/2,f#/2,g#/2} / {0/0,s/1,c_1/0,c_2/1,c_3/2} Obligation: Innermost basic terms: {f#,g#}/{0,s} *** 1.1.1.1.1.1 Progress [(?,O(n^1))] *** Considered Problem: Strict DP Rules: f#(s(x),s(y)) -> c_2(f#(x,y)) Strict TRS Rules: Weak DP Rules: g#(0(),x) -> c_3(g#(f(x,x),x),f#(x,x)) Weak TRS Rules: f(x,0()) -> s(0()) f(s(x),s(y)) -> s(f(x,y)) Signature: {f/2,g/2,f#/2,g#/2} / {0/0,s/1,c_1/0,c_2/1,c_3/2} Obligation: Innermost basic terms: {f#,g#}/{0,s} Applied Processor: DecomposeDG {onSelection = all below first cut in WDG, onUpper = Just someStrategy, onLower = Nothing} Proof: We decompose the input problem according to the dependency graph into the upper component g#(0(),x) -> c_3(g#(f(x,x),x),f#(x,x)) and a lower component f#(s(x),s(y)) -> c_2(f#(x,y)) Further, following extension rules are added to the lower component. g#(0(),x) -> f#(x,x) g#(0(),x) -> g#(f(x,x),x) *** 1.1.1.1.1.1.1 Progress [(?,O(1))] *** Considered Problem: Strict DP Rules: g#(0(),x) -> c_3(g#(f(x,x),x),f#(x,x)) Strict TRS Rules: Weak DP Rules: Weak TRS Rules: f(x,0()) -> s(0()) f(s(x),s(y)) -> s(f(x,y)) Signature: {f/2,g/2,f#/2,g#/2} / {0/0,s/1,c_1/0,c_2/1,c_3/2} Obligation: Innermost basic terms: {f#,g#}/{0,s} Applied Processor: PredecessorEstimationCP {onSelectionCP = any intersect of rules of CDG leaf and strict-rules, withComplexityPair = NaturalMI {miDimension = 1, miDegree = 0, miKind = Algebraic, uargs = UArgs, urules = URules, selector = Nothing, greedy = NoGreedy}} Proof: We first use the processor NaturalMI {miDimension = 1, miDegree = 0, miKind = Algebraic, uargs = UArgs, urules = URules, selector = Nothing, greedy = NoGreedy} to orient following rules strictly: 1: g#(0(),x) -> c_3(g#(f(x,x),x) ,f#(x,x)) The strictly oriented rules are moved into the weak component. *** 1.1.1.1.1.1.1.1 Progress [(?,O(1))] *** Considered Problem: Strict DP Rules: g#(0(),x) -> c_3(g#(f(x,x),x),f#(x,x)) Strict TRS Rules: Weak DP Rules: Weak TRS Rules: f(x,0()) -> s(0()) f(s(x),s(y)) -> s(f(x,y)) Signature: {f/2,g/2,f#/2,g#/2} / {0/0,s/1,c_1/0,c_2/1,c_3/2} Obligation: Innermost basic terms: {f#,g#}/{0,s} Applied Processor: NaturalMI {miDimension = 1, miDegree = 0, miKind = Algebraic, uargs = UArgs, urules = URules, selector = Just first alternative for predecessorEstimation any intersect of rules of CDG leaf and strict-rules, greedy = NoGreedy} Proof: We apply a matrix interpretation of kind constructor based matrix interpretation (containing no more than 0 non-zero interpretation-entries in the diagonal of the component-wise maxima): The following argument positions are considered usable: uargs(c_3) = {1} Following symbols are considered usable: {f,f#,g#} TcT has computed the following interpretation: p(0) = [3] p(f) = [0] p(g) = [1] x1 + [1] p(s) = [0] p(f#) = [2] p(g#) = [8] x1 + [4] p(c_1) = [2] p(c_2) = [1] p(c_3) = [4] x1 + [4] x2 + [0] Following rules are strictly oriented: g#(0(),x) = [28] > [24] = c_3(g#(f(x,x),x),f#(x,x)) Following rules are (at-least) weakly oriented: f(x,0()) = [0] >= [0] = s(0()) f(s(x),s(y)) = [0] >= [0] = s(f(x,y)) *** 1.1.1.1.1.1.1.1.1 Progress [(?,O(1))] *** Considered Problem: Strict DP Rules: Strict TRS Rules: Weak DP Rules: g#(0(),x) -> c_3(g#(f(x,x),x),f#(x,x)) Weak TRS Rules: f(x,0()) -> s(0()) f(s(x),s(y)) -> s(f(x,y)) Signature: {f/2,g/2,f#/2,g#/2} / {0/0,s/1,c_1/0,c_2/1,c_3/2} Obligation: Innermost basic terms: {f#,g#}/{0,s} Applied Processor: Assumption Proof: () *** 1.1.1.1.1.1.1.2 Progress [(O(1),O(1))] *** Considered Problem: Strict DP Rules: Strict TRS Rules: Weak DP Rules: g#(0(),x) -> c_3(g#(f(x,x),x),f#(x,x)) Weak TRS Rules: f(x,0()) -> s(0()) f(s(x),s(y)) -> s(f(x,y)) Signature: {f/2,g/2,f#/2,g#/2} / {0/0,s/1,c_1/0,c_2/1,c_3/2} Obligation: Innermost basic terms: {f#,g#}/{0,s} Applied Processor: RemoveWeakSuffixes Proof: Consider the dependency graph 1:W:g#(0(),x) -> c_3(g#(f(x,x),x),f#(x,x)) -->_1 g#(0(),x) -> c_3(g#(f(x,x),x),f#(x,x)):1 The following weak DPs constitute a sub-graph of the DG that is closed under successors. The DPs are removed. 1: g#(0(),x) -> c_3(g#(f(x,x),x) ,f#(x,x)) *** 1.1.1.1.1.1.1.2.1 Progress [(O(1),O(1))] *** Considered Problem: Strict DP Rules: Strict TRS Rules: Weak DP Rules: Weak TRS Rules: f(x,0()) -> s(0()) f(s(x),s(y)) -> s(f(x,y)) Signature: {f/2,g/2,f#/2,g#/2} / {0/0,s/1,c_1/0,c_2/1,c_3/2} Obligation: Innermost basic terms: {f#,g#}/{0,s} Applied Processor: EmptyProcessor Proof: The problem is already closed. The intended complexity is O(1). *** 1.1.1.1.1.1.2 Progress [(?,O(n^1))] *** Considered Problem: Strict DP Rules: f#(s(x),s(y)) -> c_2(f#(x,y)) Strict TRS Rules: Weak DP Rules: g#(0(),x) -> f#(x,x) g#(0(),x) -> g#(f(x,x),x) Weak TRS Rules: f(x,0()) -> s(0()) f(s(x),s(y)) -> s(f(x,y)) Signature: {f/2,g/2,f#/2,g#/2} / {0/0,s/1,c_1/0,c_2/1,c_3/2} Obligation: Innermost basic terms: {f#,g#}/{0,s} Applied Processor: PredecessorEstimationCP {onSelectionCP = any intersect of rules of CDG leaf and strict-rules, withComplexityPair = NaturalMI {miDimension = 1, miDegree = 1, miKind = Algebraic, uargs = UArgs, urules = URules, selector = Nothing, greedy = NoGreedy}} Proof: We first use the processor NaturalMI {miDimension = 1, miDegree = 1, miKind = Algebraic, uargs = UArgs, urules = URules, selector = Nothing, greedy = NoGreedy} to orient following rules strictly: 1: f#(s(x),s(y)) -> c_2(f#(x,y)) The strictly oriented rules are moved into the weak component. *** 1.1.1.1.1.1.2.1 Progress [(?,O(n^1))] *** Considered Problem: Strict DP Rules: f#(s(x),s(y)) -> c_2(f#(x,y)) Strict TRS Rules: Weak DP Rules: g#(0(),x) -> f#(x,x) g#(0(),x) -> g#(f(x,x),x) Weak TRS Rules: f(x,0()) -> s(0()) f(s(x),s(y)) -> s(f(x,y)) Signature: {f/2,g/2,f#/2,g#/2} / {0/0,s/1,c_1/0,c_2/1,c_3/2} Obligation: Innermost basic terms: {f#,g#}/{0,s} Applied Processor: NaturalMI {miDimension = 1, miDegree = 1, miKind = Algebraic, uargs = UArgs, urules = URules, selector = Just first alternative for predecessorEstimation any intersect of rules of CDG leaf and strict-rules, greedy = NoGreedy} Proof: We apply a matrix interpretation of kind constructor based matrix interpretation: The following argument positions are considered usable: uargs(c_2) = {1} Following symbols are considered usable: {f#,g#} TcT has computed the following interpretation: p(0) = [0] p(f) = [4] p(g) = [1] x1 + [2] x2 + [0] p(s) = [1] x1 + [1] p(f#) = [2] x2 + [0] p(g#) = [5] x2 + [0] p(c_1) = [0] p(c_2) = [1] x1 + [0] p(c_3) = [4] x1 + [1] x2 + [0] Following rules are strictly oriented: f#(s(x),s(y)) = [2] y + [2] > [2] y + [0] = c_2(f#(x,y)) Following rules are (at-least) weakly oriented: g#(0(),x) = [5] x + [0] >= [2] x + [0] = f#(x,x) g#(0(),x) = [5] x + [0] >= [5] x + [0] = g#(f(x,x),x) *** 1.1.1.1.1.1.2.1.1 Progress [(?,O(1))] *** Considered Problem: Strict DP Rules: Strict TRS Rules: Weak DP Rules: f#(s(x),s(y)) -> c_2(f#(x,y)) g#(0(),x) -> f#(x,x) g#(0(),x) -> g#(f(x,x),x) Weak TRS Rules: f(x,0()) -> s(0()) f(s(x),s(y)) -> s(f(x,y)) Signature: {f/2,g/2,f#/2,g#/2} / {0/0,s/1,c_1/0,c_2/1,c_3/2} Obligation: Innermost basic terms: {f#,g#}/{0,s} Applied Processor: Assumption Proof: () *** 1.1.1.1.1.1.2.2 Progress [(O(1),O(1))] *** Considered Problem: Strict DP Rules: Strict TRS Rules: Weak DP Rules: f#(s(x),s(y)) -> c_2(f#(x,y)) g#(0(),x) -> f#(x,x) g#(0(),x) -> g#(f(x,x),x) Weak TRS Rules: f(x,0()) -> s(0()) f(s(x),s(y)) -> s(f(x,y)) Signature: {f/2,g/2,f#/2,g#/2} / {0/0,s/1,c_1/0,c_2/1,c_3/2} Obligation: Innermost basic terms: {f#,g#}/{0,s} Applied Processor: RemoveWeakSuffixes Proof: Consider the dependency graph 1:W:f#(s(x),s(y)) -> c_2(f#(x,y)) -->_1 f#(s(x),s(y)) -> c_2(f#(x,y)):1 2:W:g#(0(),x) -> f#(x,x) -->_1 f#(s(x),s(y)) -> c_2(f#(x,y)):1 3:W:g#(0(),x) -> g#(f(x,x),x) -->_1 g#(0(),x) -> g#(f(x,x),x):3 -->_1 g#(0(),x) -> f#(x,x):2 The following weak DPs constitute a sub-graph of the DG that is closed under successors. The DPs are removed. 3: g#(0(),x) -> g#(f(x,x),x) 2: g#(0(),x) -> f#(x,x) 1: f#(s(x),s(y)) -> c_2(f#(x,y)) *** 1.1.1.1.1.1.2.2.1 Progress [(O(1),O(1))] *** Considered Problem: Strict DP Rules: Strict TRS Rules: Weak DP Rules: Weak TRS Rules: f(x,0()) -> s(0()) f(s(x),s(y)) -> s(f(x,y)) Signature: {f/2,g/2,f#/2,g#/2} / {0/0,s/1,c_1/0,c_2/1,c_3/2} Obligation: Innermost basic terms: {f#,g#}/{0,s} Applied Processor: EmptyProcessor Proof: The problem is already closed. The intended complexity is O(1). *** 1.1.1.1.1.2 Progress [(?,O(1))] *** Considered Problem: Strict DP Rules: g#(0(),x) -> c_3(g#(f(x,x),x),f#(x,x)) Strict TRS Rules: Weak DP Rules: f#(s(x),s(y)) -> c_2(f#(x,y)) Weak TRS Rules: f(x,0()) -> s(0()) f(s(x),s(y)) -> s(f(x,y)) Signature: {f/2,g/2,f#/2,g#/2} / {0/0,s/1,c_1/0,c_2/1,c_3/2} Obligation: Innermost basic terms: {f#,g#}/{0,s} Applied Processor: RemoveWeakSuffixes Proof: Consider the dependency graph 1:S:g#(0(),x) -> c_3(g#(f(x,x),x),f#(x,x)) -->_2 f#(s(x),s(y)) -> c_2(f#(x,y)):2 -->_1 g#(0(),x) -> c_3(g#(f(x,x),x),f#(x,x)):1 2:W:f#(s(x),s(y)) -> c_2(f#(x,y)) -->_1 f#(s(x),s(y)) -> c_2(f#(x,y)):2 The following weak DPs constitute a sub-graph of the DG that is closed under successors. The DPs are removed. 2: f#(s(x),s(y)) -> c_2(f#(x,y)) *** 1.1.1.1.1.2.1 Progress [(?,O(1))] *** Considered Problem: Strict DP Rules: g#(0(),x) -> c_3(g#(f(x,x),x),f#(x,x)) Strict TRS Rules: Weak DP Rules: Weak TRS Rules: f(x,0()) -> s(0()) f(s(x),s(y)) -> s(f(x,y)) Signature: {f/2,g/2,f#/2,g#/2} / {0/0,s/1,c_1/0,c_2/1,c_3/2} Obligation: Innermost basic terms: {f#,g#}/{0,s} Applied Processor: SimplifyRHS Proof: Consider the dependency graph 1:S:g#(0(),x) -> c_3(g#(f(x,x),x),f#(x,x)) -->_1 g#(0(),x) -> c_3(g#(f(x,x),x),f#(x,x)):1 Due to missing edges in the depndency graph, the right-hand sides of following rules could be simplified: g#(0(),x) -> c_3(g#(f(x,x),x)) *** 1.1.1.1.1.2.1.1 Progress [(?,O(1))] *** Considered Problem: Strict DP Rules: g#(0(),x) -> c_3(g#(f(x,x),x)) Strict TRS Rules: Weak DP Rules: Weak TRS Rules: f(x,0()) -> s(0()) f(s(x),s(y)) -> s(f(x,y)) Signature: {f/2,g/2,f#/2,g#/2} / {0/0,s/1,c_1/0,c_2/1,c_3/1} Obligation: Innermost basic terms: {f#,g#}/{0,s} Applied Processor: PredecessorEstimationCP {onSelectionCP = any intersect of rules of CDG leaf and strict-rules, withComplexityPair = NaturalMI {miDimension = 1, miDegree = 0, miKind = Algebraic, uargs = UArgs, urules = URules, selector = Nothing, greedy = NoGreedy}} Proof: We first use the processor NaturalMI {miDimension = 1, miDegree = 0, miKind = Algebraic, uargs = UArgs, urules = URules, selector = Nothing, greedy = NoGreedy} to orient following rules strictly: 1: g#(0(),x) -> c_3(g#(f(x,x),x)) The strictly oriented rules are moved into the weak component. *** 1.1.1.1.1.2.1.1.1 Progress [(?,O(1))] *** Considered Problem: Strict DP Rules: g#(0(),x) -> c_3(g#(f(x,x),x)) Strict TRS Rules: Weak DP Rules: Weak TRS Rules: f(x,0()) -> s(0()) f(s(x),s(y)) -> s(f(x,y)) Signature: {f/2,g/2,f#/2,g#/2} / {0/0,s/1,c_1/0,c_2/1,c_3/1} Obligation: Innermost basic terms: {f#,g#}/{0,s} Applied Processor: NaturalMI {miDimension = 1, miDegree = 0, miKind = Algebraic, uargs = UArgs, urules = URules, selector = Just first alternative for predecessorEstimation any intersect of rules of CDG leaf and strict-rules, greedy = NoGreedy} Proof: We apply a matrix interpretation of kind constructor based matrix interpretation (containing no more than 0 non-zero interpretation-entries in the diagonal of the component-wise maxima): The following argument positions are considered usable: uargs(c_3) = {1} Following symbols are considered usable: {f,f#,g#} TcT has computed the following interpretation: p(0) = [14] p(f) = [0] p(g) = [0] p(s) = [0] p(f#) = [1] x2 + [0] p(g#) = [1] x1 + [0] p(c_1) = [1] p(c_2) = [2] p(c_3) = [8] x1 + [6] Following rules are strictly oriented: g#(0(),x) = [14] > [6] = c_3(g#(f(x,x),x)) Following rules are (at-least) weakly oriented: f(x,0()) = [0] >= [0] = s(0()) f(s(x),s(y)) = [0] >= [0] = s(f(x,y)) *** 1.1.1.1.1.2.1.1.1.1 Progress [(?,O(1))] *** Considered Problem: Strict DP Rules: Strict TRS Rules: Weak DP Rules: g#(0(),x) -> c_3(g#(f(x,x),x)) Weak TRS Rules: f(x,0()) -> s(0()) f(s(x),s(y)) -> s(f(x,y)) Signature: {f/2,g/2,f#/2,g#/2} / {0/0,s/1,c_1/0,c_2/1,c_3/1} Obligation: Innermost basic terms: {f#,g#}/{0,s} Applied Processor: Assumption Proof: () *** 1.1.1.1.1.2.1.1.2 Progress [(O(1),O(1))] *** Considered Problem: Strict DP Rules: Strict TRS Rules: Weak DP Rules: g#(0(),x) -> c_3(g#(f(x,x),x)) Weak TRS Rules: f(x,0()) -> s(0()) f(s(x),s(y)) -> s(f(x,y)) Signature: {f/2,g/2,f#/2,g#/2} / {0/0,s/1,c_1/0,c_2/1,c_3/1} Obligation: Innermost basic terms: {f#,g#}/{0,s} Applied Processor: RemoveWeakSuffixes Proof: Consider the dependency graph 1:W:g#(0(),x) -> c_3(g#(f(x,x),x)) -->_1 g#(0(),x) -> c_3(g#(f(x,x),x)):1 The following weak DPs constitute a sub-graph of the DG that is closed under successors. The DPs are removed. 1: g#(0(),x) -> c_3(g#(f(x,x),x)) *** 1.1.1.1.1.2.1.1.2.1 Progress [(O(1),O(1))] *** Considered Problem: Strict DP Rules: Strict TRS Rules: Weak DP Rules: Weak TRS Rules: f(x,0()) -> s(0()) f(s(x),s(y)) -> s(f(x,y)) Signature: {f/2,g/2,f#/2,g#/2} / {0/0,s/1,c_1/0,c_2/1,c_3/1} Obligation: Innermost basic terms: {f#,g#}/{0,s} Applied Processor: EmptyProcessor Proof: The problem is already closed. The intended complexity is O(1).