What is an Algorithm?
An "Algorithm" is a set of explicit steps or rules used to solve a specific problem or complete a certain task.
For example: An algorithm is like a travel itinerary
Suppose you want to travel from Shanghai to Beijing, and your goal is "to successfully arrive at the destination from the starting point."
Then, different "algorithms" are like different travel plans:
🚗 Driving Route Algorithm: Which way to drive? Take Highway 1? Which day to depart? Which cities to rest in along the way? This is a "routing algorithm".
✈️ Most Cost-Effective Flight Algorithm: Which tool to use for price comparison? Which airport is cheapest to depart from? Layover or direct flight? This is an "optimization algorithm".
🗺️ Attraction Visit Sequence Algorithm: To visit Beijing in 3 days, should you go to the Forbidden City or the Great Wall first? How to schedule to save the most time? This is a "scheduling/permutation algorithm".
An algorithm is a series of clear steps to achieve a goal, just like a reasonable travel itinerary that helps you efficiently and smoothly get from your starting point (input) to your destination (output).
The process of writing an algorithm is equivalent to personally creating a detailed and efficient travel itinerary before departure.
You are not just telling someone "I want to go to Beijing," but you are:
- Carefully planning the route (how to get there)
- Scheduling the time (how long each step takes)
- Avoiding detours and repetitions (e.g., not backtracking)
- Optimizing resource utilization (time, money, physical energy)
Therefore, writing an algorithm = creating a clear, efficient itinerary to solve a problem or achieve a goal.