Skip to main content
Practice

Life is Practical! Algorithm Problem Solving

When you are training your logical thinking by solving algorithm problems, it is crucial to fully understand the problem and approach it by breaking it down into smaller stages.

Problem Solving Tips

  1. Understand the Problem Thoroughly: Do not start coding until you have completely understood the problem. If necessary, read the problem multiple times and use the provided examples to accurately comprehend the requirements.

  2. Use a Divide and Conquer Strategy: Use a divide and conquer strategy to solve bigger problems by breaking them into smaller parts and combining the results. This approach makes it easier to solve the problem.

  3. Experience Solving Various Problems: Algorithm problems often repeat similar types at a high level. By solving a range of problems, improve your ability to quickly identify similar types of problems.

  4. Analyze Other Solutions: After solving a problem, compare your solution with others' solutions found via internet searches.


Let's take a simple algorithm as an example to find the smallest element in a given array.

The code sets the first element of the array as the minimum value and iterates through all elements of the array to find the minimum value using conditional statements.

Finding the Minimum Element in an Array
def find_minimum(arr):
min_value = arr[0] # Set the first element of the array as the minimum value
for value in arr: # Traverse all elements of the array
if value < min_value: # If an element smaller than the minimum value is found
min_value = value # Update the minimum value to this element
return min_value # Return the minimum value

Initially, implementing logical thinking into code to solve problems may not be easy. However, as you solve more and more problems, you will naturally gain proficiency in handling algorithmic challenges.

In the upcoming lessons, we will tackle simple algorithm problems to train logical thinking. Solutions and Python example codes will be provided after each problem. Try to solve the problems on your own without consulting the solutions.