DEV Community

Cover image for The Beginners Approach to Algorithm.
Janice Alecha
Janice Alecha

Posted on • Updated on

The Beginners Approach to Algorithm.

In computer programming terms, an algorithm is a set of well-defined instructions to solve a particular problem.

Why are Algorithms Important to Understand?

Algorithmic thinking, or the ability to define clear steps to solve a problem, is crucial in many different fields. Even if we’re not conscious of it, we use algorithms and algorithmic thinking all the time. Algorithmic thinking allows students to break down problems and conceptualize solutions in terms of discrete steps. Being able to understand and implement an algorithm requires students to practice structured thinking and reasoning abilities.
This article originally appeared on junilearning.com

What better way to practice algorithmic problem solving than to find solutions to check Palindrome in JavaScript.

palindrome

First off, what is a Palindrome?
A palindrome is a word, number, phrase, or another sequence of characters that can be read backward and forwards, like a kayak or racecar.

Instruction:

Write a function isPalindrome that will receive one argument, a string. Your function should return true if the string is a palindrome (that is, if it reads the same forwards and backwards, like "kayak" or "racecar"), and return false if it is not a palindrome.

In our exercises, we were given recommended steps as follows:

Rewrite The Problem in Your Own Words

I love this part since we're able to write the problem the way we understand it.
/I need to make an isPalindrome function() that returns either true or false. When the input string is the same forwards and backwards, I should return true. That means that if the input string is the same after I reverse it, I should return true. For instance, "kayak" in reverse is also "kayak", and "racecar" in reverse is also "racecar", so my solution should return true for these cases. "hello" in reverse is "olleh", so my solution should return false for this case./

Write Your Own Test Cases

In software engineering, creating your own test cases involves specifying the input values that your code should handle and the expected output it should produce. This iterative process helps develop a model to effectively solve the problem at hand.

Examples From Our Lecture:

test code

  • Pseudocode

How do you effectively write a Pseudocode and What are its advantages? So many questions.

questions

Defining Pseudocode

Pseudocode is a simple way of writing programming code in English. Pseudocode is not an actual programming language. It uses short phrases to write code for programs before you create them in a specific language. Once you know what the program is about and how it will function, then you can use pseudocode to create statements to achieve the required results for your program.-Alisa Perry

It is like writing your code on your terms and rules in short statements. I'm learning slowly but surely.

  • CODE

Using Built-In JavaScript Methods:

code

The split() method is a built-in method provided by JavaScript. This method splits the string into a list of substrings.

The reverse() method on the other hand is a built-in method provided by JavaScript. This method reverses an original array instead.

Lastly, The join() method is a built-in method provided by JavaScript. This method creates and returns a new string by concatenating all the elements in an array (or array-like object), separated by commas or a specified delimiter string.

Make It Clean And Readable

It's important to ensure your code is well-structured and readable. Avoid redundancy and strive for simplicity by following the DRY principle - Don't Repeat Yourself. Establish a clear and organized structure to improve readability.

OPTIMIZE

This means to find a more efficient solution to a problem, such as reducing the number of steps required to reverse a string, or exploring alternative approaches like using a for loop instead.

Conclusion:

I still have a lot to learn and a long way to go. To improve my skills, I need to focus on understanding the basics of data structures and algorithms. I plan to do this by reading books and watching tutorials. I will also practice by using websites such as Coderbyte and HackerRank or writing down algorithms on my notepad. It's important to remember that this is a learning process and to take it one step at a time.

Top comments (0)