- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python Program for array rotation
In this article, we will learn about the solution to the problem statement given below.
Problem statement − Given a text and a pattern, we need to print all occurrences of pattern and its permutations (or anagrams) in text.
Now let’s observe the solution in the implementation below −
# maximum value MAX = 300 # compare def compare(arr1, arr2): for i in range(MAX): if arr1[i] != arr2[i]: return False return True # search def search(pat, txt): M = len(pat) N = len(txt) # countP pattern account # countTW text window count countP = *MAX countTW = *MAX for i in range(M): (countP[ord(pat[i]) ]) += 1 (countTW[ord(txt[i]) ]) += 1 # Traversal for i in range(M, N): # Compare current window and patten counts if compare(countP, countTW): print("Found at Index", (i-M)) # Add charcter to window (countTW[ ord(txt[i]) ]) += 1 # remove charcter from window (countTW[ ord(txt[i-M]) ]) -= 1 # Check for the last window if compare(countP, countTW): print("It is Found at Index : ", N-M) # main txt = "TUTORIALSPOINT" pat = "TOR" search(pat, txt)
Found at Index 2
All the variables are declared in the local scope and their references are seen in the figure above.
In this article, we have learned about how we can make a Python Program for Anagram Substring Search.
- Python Program for Reversal algorithm for array rotation
- C Program for Program for array rotation?
- Java Program for array rotation
- C Program for Reversal algorithm for array rotation
- Java Program for Reversal algorithm for array rotation
- Reversal Algorithm for Array Rotation using C++
- Block swap algorithm for array rotation in C++
- Reversal Algorithm for Right Rotation of an Array using C++
- Program to find how many distinct rotation groups are there for a list of words in Python
- Program to check right rotation forms increasing or decreasing array with first n natural numbers or not in Python
- Program to find length of longest palindromic substring after single rotation in Python
- Program to check strings are rotation of each other or not in Python
- Find the Rotation Count in Rotated Sorted array in C++
- Python Program for QuickSort