➕︎ Aa ➖︎ |Dark 1 ● Dark 2 ● Light|Hack ● Fira Code|Back to PT Mono✖
// CPCS 223 Analysis & Design of Algorithms
// Brute force string matching - coding hints
// 2020, Dr. Muhammad Al-Hashimi
// to define a string simply assign to var
var txt = "text to search!";
var pattern = "sear";
// access string as a character array
var n = txt.length;
document.write( // tag output as paragraph
"<p>First letter in pattern and last letter in text: ",
pattern [0],
txt [n-1],
"</p>"
);
// write next a brute-force string matching function
// insert vars to count: match trials, and comparisons for each trial
// compare to worst-case formula for total comparisons based on n,m
// report results in the course group