What is an algorithm?
An algorithm is a clear, step by step set of instructions for solving a problem or completing a task. A good algorithm is correct, finishes in a finite number of steps, and is efficient in time and memory. Following a recipe to cook a dish is a everyday example of an algorithm.
What makes a good algorithm
- Correct: it produces the right output for every valid input.
- Finite: it finishes rather than running forever.
- Well defined: each step is unambiguous.
- Efficient: it uses reasonable time and memory.
In software, algorithms power everything from sorting a list and searching a database to routing a map and ranking search results. Data structures and algorithms go hand in hand, since the right structure often makes the algorithm simple and fast.
If asked to describe your approach before coding, state your algorithm in plain steps first. Interviewers value a clear plan, and it helps you catch mistakes before you write a single line.
Common follow up questions
Related interview questions
Want the full DSA guide?
Read every DSA concept with notes, diagrams, and code in one place. Track your progress as you go.
Open the DSA guide All DSA questions