r/AlgoViz • • Aug 24 '26

Visualization Narayana's Next & Previous Lexicographical Permutations Algorithms Visualization _ Step by Step Python Code Animation

4 Upvotes

Algorithm Description

Math Algorithms Narayana's Next and Previous Lexicographical Permutations generates the next greater permutation or the previous smaller permutation of an array in place using a three-step process: first, find the longest non-increasing (for next) or non-decreasing (for previous) suffix and identify the pivot; second, find the rightmost element larger than the pivot (for next) or smaller than the pivot (for previous); third, swap the pivot with that element and reverse the suffix. The algorithm returns the same array rearranged into the desired permutation.


Complexity Analysis

Time Complexity: O(n) — single linear scan to find the pivot, another to find the swap element, plus a reverse of the suffix

Space Complexity: O(1) — all operations are performed in place without additional memory


YouTube

https://www.youtube.com/watch?v=dEaxumQWz_A


r/AlgoViz • • Oct 07 '26

Visualizer for the Python Programming Language

4 Upvotes

Understand your Python code by visualizing its execution using memory_graph:


r/AlgoViz • • Sep 01 '26

udiprod: Visualization of tensors - part 1

Thumbnail
youtube.com
2 Upvotes

This video series visualizes tensors using a unique and original visualization of a sphere with arrows.