Using Java to solve Algorithm problems and making a focus on Time Complexity.

Algorithms

Recently, I finished studying the new features of Java 11, and I posted an article mentioning my opinion here. Also, I bought a book of Java certification tests, and I solved many of them in a GitHub repository that you can find here. In my opinion, this is not enough if you wish to apply this knowledge to solve real logical problems, and algorithms enter here. Ok, those are no real-world problems, but they improve your programming logic.

I obtained a subscription on the AlgoExpert.io platform to access many algorithm problems. For me, the idea is to solve those algorithms using Java. I also create a repository on GitHub for this project, which you can find here. I am trying to solve these kinds of problems using Java 17, and until now, I have been pleased to do this activity. I found some places where the IDE subjects me to improve my code using many Java 17 characteristics.

But wait a minute!! Try to think not only about solving algorithm problems but also remember concepts like “Time Complexity” in algorithms theory. Try to improve your code (or the mine) thinking with this concept in mind. For this reason, I also create a main class that must be run when you package and execute the JAR. This main class calls all solved algorithms methods sending test data as input parameters. Observe the time consumed by your computer hardware when the program is finished. It outputs the entire time consumed in milliseconds for each method call. When you try to improve this project with your code, do not forget to see if the execution time decreases.

The last thing I would like to mention here, is that you can also build a native image using GraalVM. It uses the packaged JAR mentioned previously and creates a native image that you can use to execute the program. Observe that the entire execution time of the program decreases considerably. I put all these instructions in the project's README file, and you can also use them in your own Java projects.

Well, I hope this information will aggregate value for you (Java developer or not). We need to promote Java as a powerful programming language. In the future, I will be posting the use of Java as Lambda Functions on AWS. We know that Java is widely used in microservices around world-class products, but I will expose the use of pure Java standard (not Java EE) as a native programming language in serverless technologies, and our programming logic will be very important here.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store