As someone who has just opened his eyes to the world of IT and it's possibilities, I find myself being a bit overwhelmed. I have always had a passion for computers and for fixing things, fixing anything really, IKEA is a particular speciality.
Either way life seemed to get in the way of the world of tech...until now. Massive Explosion
Anyway, I have been learning as quickly as I can through online courses in the attempts to make my passion a career.
I have been tasked to create a flow chart, pseudocode and write a blog post about what I did for it. I'll be honest I have no clue if it will work but I'll give it a go. So...
I started with planning the Algorithm -
Planning the Pattern-Searching Algorithm
Understanding the Problem:
- Input: A text string (haystack) and a pattern string (needle).
- Output: The indices of all occurrences of the needle within the haystack.
Algorithm Design:
We'll use a modified Naive Pattern Searching algorithm, incorporating a failure function to optimise the process.
I won't go into too much detail to save time but these are the main headings of what I done (don't worry I have all the data for it stored).
Algorithm Steps
Preprocessing, Pattern Matching, Implementation Considerations, Failure Function
Next Steps:
Implement the algorithm: Choose a programming language (Python, C++, Java, etc.) and write the code, incorporating the failure function.
Test the algorithm: Create various test cases with different patterns and texts to ensure correctness.
Optimize the implementation: Consider optimizations like using string hashing or parallel processing for large inputs.
From this I created a Flowchart, if I have done something wrong please let me know because I have no idea at this point.
And finally the Pseudocode:
function patternSearch(text, pattern)
n = length(text)
m = length(pattern)
// Calculate the failure function f
computeFailureFunction(pattern, f)
i = 0 // Index for text
j = 0 // Index for pattern
while i < n
if text[i] == pattern[j]
i = i + 1
j = j + 1
if j == m
print "Pattern found at index " + (i - j)
j = f[j-1]
else
if j != 0
j = f[j-1]
else
i = i + 1
end while
If you've made it this far, thanks for sticking around, have a drink on me.
Top comments (0)