Introduction
The task in the Codecademy Intro to IT Course is to create pseudocode for a pattern searching algorithm, searching for a specific value in a larger set of data.
Steps to outline algorithm
- Input the text to be searched through and the pattern to look for.
- Create a text_length variable set to the number of characters in the text (redundant!)
- Create a pattern_length variable set to the number of characters in the pattern
- Create a match_count variable set to 0
- Has the entire text been searched? If not continue to 6, if so skip to 9
- Iterate to the next character in text
- Increment text_length (no!)
- Does the current character + pattern_length = pattern a. If yes match_count + 1 b. Else go back to 5.
- Display match_count
Flowchart
Pseudocode
Define text
Define pattern
Create a patt_length variable and set it to the length of the pattern input
Create a match_count variable and set it to 0
if the entire text hasn’t been searched:
iterate to the next character in text
if current character of text + (pattern_length – 1) = pattern
+1 to match_count
Display “The text contains “pattern” “match_count” times.
Conclusion
I guess this should work?! I realised while doing the flowchart that the text_length variable shouldn't be needed so I omitted that from the pseudocode. Once I learn some languages I would be able to say whether the iteration bit is clear enough to make it through the text from start to finish.
Top comments (0)