Codecademy Pseudocode Searching Algorithm

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 searc…


This content originally appeared on DEV Community and was authored by David Wishart

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

  1. Input the text to be searched through and the pattern to look for.
  2. Create a text_length variable set to the number of characters in the text (redundant!)
  3. Create a pattern_length variable set to the number of characters in the pattern
  4. Create a match_count variable set to 0
  5. Has the entire text been searched? If not continue to 6, if so skip to 9
  6. Iterate to the next character in text
  7. Increment text_length (no!)
  8. Does the current character + pattern_length = pattern a. If yes match_count + 1 b. Else go back to 5.
  9. Display match_count

Flowchart

Image description

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.


This content originally appeared on DEV Community and was authored by David Wishart


Print Share Comment Cite Upload Translate Updates
APA

David Wishart | Sciencx (2024-08-11T16:09:34+00:00) Codecademy Pseudocode Searching Algorithm. Retrieved from https://www.scien.cx/2024/08/11/codecademy-pseudocode-searching-algorithm/

MLA
" » Codecademy Pseudocode Searching Algorithm." David Wishart | Sciencx - Sunday August 11, 2024, https://www.scien.cx/2024/08/11/codecademy-pseudocode-searching-algorithm/
HARVARD
David Wishart | Sciencx Sunday August 11, 2024 » Codecademy Pseudocode Searching Algorithm., viewed ,<https://www.scien.cx/2024/08/11/codecademy-pseudocode-searching-algorithm/>
VANCOUVER
David Wishart | Sciencx - » Codecademy Pseudocode Searching Algorithm. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/08/11/codecademy-pseudocode-searching-algorithm/
CHICAGO
" » Codecademy Pseudocode Searching Algorithm." David Wishart | Sciencx - Accessed . https://www.scien.cx/2024/08/11/codecademy-pseudocode-searching-algorithm/
IEEE
" » Codecademy Pseudocode Searching Algorithm." David Wishart | Sciencx [Online]. Available: https://www.scien.cx/2024/08/11/codecademy-pseudocode-searching-algorithm/. [Accessed: ]
rf:citation
» Codecademy Pseudocode Searching Algorithm | David Wishart | Sciencx | https://www.scien.cx/2024/08/11/codecademy-pseudocode-searching-algorithm/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.