实验要求
1、根据实验内容设计算法,分别用KMP算法和Rabin-Karp搜索子串;
2、对所设计的算法采用大O符号进行时间复杂性分析;
3、上机实现算法;
4、实验报告内容应包括问题描述、问题分析、算法设计、算法实现、运行结果及算法复杂度分析等内容。
实验内容
给定2个字符串S和T,在主串S中查找子模式串T,并输出结果。
如主串acabaabaabcacaabc,模式串abaabcac,其输出结果为5。如果查找失败返回-1。
kmp
include <iostream>
#include <cstring>
#include <cstdlib>
using namespace std;
int* make_pmt(const char* p) //O(n)
{
int len = strlen(p);
int* ret = static_cast<int*>(malloc(sizeof(int) * len));
if(ret !=