This content was deleted by the author. You can see it from Blockchain History logs.

Algorithms and Codewars

What are algorithms?

An algorithm is a specific procedure for solving a well-defined computational problem. In simpler terms, an algorithm is a piece of code that has well-defined steps and solves a problem in an optimal way.

Here are some real-life examples of algorithms: the recipe for baking a cake, the process of doing laundry, solving a Rubik’s cube, and the functionality of a search engine are all examples of an algorithm.



Source: flaticon

They are very important!

Algorithms are very important in computer science. The best-chosen algorithm makes sure the computer will do the given task in the best possible manner. In cases where efficiency matters (usually always) a proper algorithm is really vital to be used. An algorithm is important in optimizing a computer program according to the available resources.

Ultimately when anyone decides to solve a problem through better algorithms then searching for the best combination of program speed and least amount of memory consumption is desired.

Algorithmic complexity

When speaking about algorithms we can measure two different resources that really matter that we need to design the algorithm around: time and space.

Algorithmic time complexity is a measure of how long an algorithm would take to complete given an input of size n.

Algorithmic space complexity is a measure of how much memory an algorithm would allocate to complete given an input of size n.

When we want to annotate the complexity of an algorithm mathematically we use the Big O annotation. Big O specifically describes the worst-case scenario and can be used to describe the execution time or space required for an algorithm to run to completion.

If we have an input of size n, meaning the input of the algorithm is an array with n different items, and the algorithm runs in a linear time complexity, we can describe the complexity as O(n).



Source: devopedia

Types of Algorithms

Algorithms are classified based on the concepts that they use to accomplish a task. While there are many types of algorithms, the most basic types of computer science algorithms are:

Divide and conquer algorithms – divide the problem into smaller subproblems of the same type, then solve those smaller problems, and combine those solutions to solve the original problem.

Brute force algorithms – try all possible solutions until a satisfactory solution is found. Algorithms that use this approach are usually worst performing and should be used only when there is not smarter solution to a given problem.

Greedy algorithms – find an optimal solution at the local level with the intent of finding an optimal solution for the whole problem. These algorithms should be used with caution because they might introduce the local optimum problem.

Recursive algorithms – solve the lowest and simplest version of a problem to then solve increasingly larger versions of the problem until the solution to the original problem is found.

Backtracking algorithms – divide the problem into subproblems, each of which can be attempted to be solved; however, if the desired solution is not reached, move backward in the problem until a path is found that moves it forward. These algorithms are most commonly used to solve chess problems, Rubick's cube, Sudoku, etc...

Dynamic programming algorithms – break a complex problem into a collection of simpler subproblems, then solve each of those subproblems only once, storing their solution for future use instead of re-computing their solutions. Usually, dynamic algorithms are custom-made for each problem that they solve. The most famous dynamic algorithm is the knapsack algorithm.

Best language to practice algorithms?

Almost every computer language can be used to create an optimal algorithm, but in my opinion, some languages are better suited for the task. When practicing algorithms, the point is to have well-defined steps that are clear even at first glance and are easy to fix if there is a bug in the solution.

Naturally, strongly typed languages like C#, Java, C++, and many others are most used when learning new algorithms since they force us to write cleaner code than dynamic languages.

Even if that is the case, many developers chose to hone their algorithmic skills using python or ruby because they offer some nice libraries that often solve the most basic types of problems with 1 line of code.

My rule of thumb is to use the language that I'm most familiar with because that way I will not struggle with language syntax and built-in functionalities like sorting, filtering, etc..., and focus on solving the problem at hand.

Where can I practice algorithms?

Codewars is a community-driven platform for creating and solving algorithmic problems. There is a system in place to guide new Codewarriors (users) by introducing them to simpler problems at the beginning and increasing the difficulty as the user gains more experience. Of course, more experienced developers can start with tougher problems from the get-go.

Because the problems are created by the users, the solutions can be posted in a different list of languages for different problems, but most commonly C#, Java, JavaScript, and Python are always implemented. Some more popular problems can be solved in up to 35 different languages even.

The last thing left to do is visit codewars and start coding! 😄


image.png
Source: codewars

Non-affiliation disclaimer!
I'm not endorsed by, directly affiliated with, or sponsored by Codewars.

Codewars glossary

Source: https://www.codewars.com/about

Kata
...is real code challenges focused on improving skill and technique. Some train programming fundamentals, while others focus on complex problem-solving. Each kata is crafted for and by the community.

Kyu/Dan Ranks
Each kata on the site is set to a Kyu/Dan rank, based on its subject area and difficulty. The community collectively determines rank in the Beta Process. Every new Codewarrior on Codewars starts being ranked as 8 Kyu.

What are Kyu and Dan?
The terms are borrowed from a system in Japanese martial arts, which is in turn borrowed from the game of Go. Kyu indicates the number of degrees away from master level (Dan). This is why they count downward. Once you reach master level, we count upward.

Earning Ranks
You can advance through the ranks by completing kata at or above your rank - the harder the kata the faster you advance.

Honor
...represents the level of respect a user has earned from the community, based on their skill and contributions. Honor is earned fastest through creating kata, crafting great solutions, and constructive comments.

Hope this post helps new developers to hone their skills in solving algorithmic problems. 😄

Happy coding,
DotNetGuru