AP 1.2_removed___

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING

Experiment-1.2
Student Name: Manohar Chaudhary UID: 21BCS4422
Branch: CSE Section/Group: 603-B
Semester: 6th Date of Performance: 23/01/2024
Subject Name: AP Lab-2 Subject Code:21CSP-351

1. Aim: To demonstrate the concept of String-Matching algorithms.


I. Problem statement - Given two strings s and goal, return true if and only if s
can become goal after some number of shifts on s. A shift on s consists of
moving the leftmost character of s to the rightmost position. For example, if s
= "abcde", then it will be "bcdea" after one shift.
II. Problem Statement- t - Given two strings a and b, return the minimum
number of times you should repeat string a so that string b is a substring of it.
If it is impossible for b to be a substring of a after repeating it, return -1.

2. Objective:
✓ Highlight the importance of string-matching algorithms.
✓ Define the problem of transforming one string into another through left shifts.

3. Code
1.

class Solution:
def rotateString(self, s: str, goal: str) -> bool:
if len(s) != len(goal):
return False
check = s + s
return check.find(goal) != -1

2.
class Solution:
def solve(self, a: str, b: str) -> int:
s = a
m = 1
n = len(b) // len(a)
for i in range(n + 2):
if b in s:
return m
s += a
m += 1
return -1
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

def repeatedStringMatch(self, a: str, b: str) -> int:


return self.solve(a, b)

4. OUTPUT
1.

2.
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

5. Learning Outcomes

✓ Learnt the uses a conditional statement


✓ Learnt String Manipulation techniques.
✓ Learnt Substring Search.

You might also like