Updated May 17, 2023
Introduction to Algorithm
In this topic, we discussed the introduction to the algorithm, which represents how to solve any problem. It is essential to understand how a common man applies the algorithm everywhere to complete any work in day-to-day life; it’s very common. It’s very compulsory to complete the work effectively. Suppose a farmer sells a crop in the market and earns some money; many cases occur where the farmer will think about the best approach with a huge profit.
The farmer will check the market price, Size of the market, and demand-supply, and the farmer will also think about how to sell the crop per Kg or quintal to make more profit. Here, the farmer applies some logic and algorithm to complete the work ineffective for more profit. These ideas came from experience and challenges faced by the same or other farmers. In technical terms, if we talk about any programming language without any algorithm, it’s impossible to write any effective logic.
Before writing any logic in any programming language, we should consider the following things.
- The correctness of the program: In any conditions, your output should be correct; before applying any algorithm, make sure your output is cent percent correct; otherwise, there is no meaning of the algorithm or your program.
- Time: Time is essential everywhere; you must consider how long your algorithm takes to complete the work.
- Complexity: How much is your algorithm complicated in terms of logic, the time taken, and the memory used to complete the work?
Components of Algorithm
As discussed earlier in an algorithm introduction, it has different components, which differ in different situations.
Generally, algorithms comprise four components:
1. Input or Feedback
As we know, algorithms are sequences of steps to be followed to get some output; we need to provide some inputs to an algorithm; one good example from daily life is when we need sugar as output, we have to give sugarcane as input. Nowadays, smartphones incorporate a face lock feature, which requires you to position yourself in front of the camera for your face to be captured as input. The algorithm then utilizes facial features such as face structure, wrinkles, hair, and other parameters to evaluate and compare them with the stored face data initially registered on the mobile device.
2. Sequence of Algorithms
After having inputs and introduction to algorithms, then the next step to follow is the sequencing of steps present in the algorithm; according to what output we want, we have to arrange steps present in the algorithm.
- Condition: Sometimes, we have to check conditions according to input; for example, IRCTC(Indian railway ticket booking app) checks if a person is eligible for a discount based on age by using the Age as input algorithm checks if the person is above 65 or not. If a person is above 65, then he will be eligible for a discount. Otherwise, not.
- Repetition: Sometimes, there are steps that we have to repeat until we reach the desired outputs. For example, if I want to search for a record in files, I have to compare our input with different files until we find our desired output; in this case, the same steps are repeated until the output(Files).
Applications of Algorithm
If an employee comes from the office, he will consider reaching home as soon as possible and try to take the shortest path to cover the distance.
Below is some very important use case where the algorithm has been used.
- If you search for any item on any shopping site next time, you will get something similar to a suggestion.
- If you watch any video on YouTube next time, you will get similar suggestions as recommended videos.
- Have you thought about how the Google search engine works and why within seconds, results appear?
- In the same way, if we used Facebook, we would get friends’ suggestions based on some keys like School Name, College Name, Places, etc.
Recommender System
Nowadays, it is widespread in our day-to-day life everywhere recommender system works directly or indirectly according to the activities, which is very beneficial for both provider and user.
Example: If you are searching for shoes on Amazon and the next time you will get recommendations of similar types of shoes as suggestions it will be very easy for you to select an item for Amazon as well, there is a perfect chance that you can get buy shoes and based on user’s data recommender system work, and behind this recommender system machine learning algorithm works.
Characteristics of Algorithm
Below are the characteristics mentioned:
- Finiteness: An algorithm should be complete at one particular time, and this is very important for any algorithm; otherwise, your algorithm will go into an infinite state, and it will not ever be complete.
- Definiteness: Each algorithm should be unambiguous.
- Effectiveness: Each line of an algorithm should be essential. We should try to write simply so it would be basic.
- Input: Every algorithm should take input; it can be Zero or one or more. So, according to the conditions, the user can use it.
- Output: For any work, some output should come; this is a must; otherwise, there is no meaning in any work. In the same way, each algorithm should generate one or more outputs.
- Generality: The algorithm should be common for the set of input and requirements so the same algorithm can apply in multiple places according to the user’s needs.
Advantages and Disadvantages of Algorithms
Below are the advantages and disadvantages mentioned:
Advantages:
- Understanding algorithms have become very easy as they can be expressed in a simple language accessible to anyone.
- Different pieces can break down algorithms, making them easy to implement practically.
- Understanding the sequence to be followed in processing using algorithms is easy.
Disadvantages:
- It isn’t easy to convert a complex task into proper algorithms.
- It is a time-consuming process because we need to spend proper time writing the algorithm, and later, we need to implement it in a programming language.
- Understanding each flow in terms of loops and branches can be challenging because presenting the functionalities for each step of the algorithm introduction can be complicated.
Recommended Articles
This has been a guide to Introduction to Algorithm. Here we have discussed the introduction, components, applications, characteristics, advantages, and disadvantages. You may also look at the following articles to learn more –