Number of Increasing Subsequences of length k
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.
Introduction
In combinatorics, the problem of determining the number of increasing subsequences of a given length from a sequence is a fundamental question with significant implications in algorithm design, bioinformatics, and coding theory. This article examines both foundational concepts and practical techniques for solving this problem efficiently.
Understanding Increasing Subsequences
An increasing subsequence of a sequence is a subsequence where each element is strictly larger than the preceding one. For example, given the sequence , possible increasing subsequences include , , , , , , , and the single elements , , , .
Problem Statement
Given a sequence of distinct integers, find the number of increasing subsequences of length exactly . This problem can be generalized to include sequences with repeated numbers by using non-strict inequality, but we focus on the strictly increasing case here.
Dynamic Programming Approach
A common way to solve this problem is through dynamic programming. The approach involves building a table where each entry represents the number of increasing subsequences of length that end at element (using 1-based indexing for the sequence).
Initialization
For length 1, every single element forms an increasing subsequence by itself:
Transition
For every element at position and subsequence length , count those that can be formed by preceding elements smaller than :
In words, to count increasing subsequences of length ending at position , look at all earlier positions where and sum up the count of increasing subsequences of length ending at those positions.
Final Result
The total number of increasing subsequences of length is the sum over all ending positions:
Example
Consider the sequence and .
Step 1: Initialize for all .
| i | ||
| 1 | 2 | 1 |
| 2 | 5 | 1 |
| 3 | 3 | 1 |
| 4 | 7 | 1 |
| 5 | 4 | 1 |
Step 2: Fill the table for :
- (subsequence )
- (subsequence )
- (subsequences )
- (subsequences )
Step 3: Fill for :
- (subsequences )
- (subsequence )
Answer:
Complexity Analysis
The time complexity of this basic algorithm is due to the nested loops iterating over possible subsequences for each element and subsequence length. The space complexity is for the DP table.
Optimization with BIT/Fenwick Tree
The inner summation over all preceding elements can be accelerated using a Binary Indexed Tree (BIT). By processing elements in a sorted order and querying prefix sums, each transition step can be done in instead of , bringing the total time complexity down to . This optimization is important for large sequences.
Summary Table
| Concept | Description |
| Increasing Subsequence | Subsequence where each element is larger than the previous one |
| DP Table | Count of increasing subsequences ending at index of length |
| Initialization | for each |
| Transition | |
| Basic Time Complexity | |
| Optimized (with BIT) |
Conclusion
Computing the number of increasing subsequences of length is both a classical and practically relevant problem. The dynamic programming approach provides a clear and correct solution, while data structure optimizations like BIT reduce the time complexity for larger inputs. Understanding this problem also builds intuition for related challenges like the Longest Increasing Subsequence (LIS) and patience sorting.
Related reading
- Number of largest element exchanges for quicksort
- Number of sub-sequences in a given sequence
- Number of subarrays divisible by k
- Number of substrings in range l, r that can be permuted to palindrome
- Number of n-element permutations with exactly k inversions
- Number of ways of correctly arranging parenthesis
- Number of ways to make change for amount N
- Numpy argsort - what is it doing?

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.