Compare between definiteness and effectiveness of an algorithm with example

 Definiteness and effectiveness are two important aspects of an algorithm. Let's explore each of them with examples:


1. Definiteness: Definiteness refers to the clarity and unambiguity of the steps in an algorithm. An algorithm should have well-defined and precise instructions that can be followed without any confusion. It should leave no room for interpretation or multiple possible outcomes.


For example, consider the following algorithm to find the maximum number among three given numbers:


Step 1: Start

Step 2: Input three numbers: num1, num2, num3

Step 3: If num1 > num2 and num1 > num3, then

            Display num1 as the maximum number

        Else if num2 > num1 and num2 > num3, then

            Display num2 as the maximum number

        Else

            Display num3 as the maximum number

Step 4: Stop


This algorithm is definite because it provides clear instructions on how to find the maximum number among the given inputs. There is no ambiguity in the steps, and it will always produce the correct result.


2. Effectiveness: Effectiveness refers to the ability of an algorithm to solve a problem efficiently. An effective algorithm should provide a solution within a reasonable amount of time and resources. It should avoid unnecessary computations or redundant steps.


For example, let's consider an algorithm to search for a specific element in an array:


Step 1: Start

Step 2: Input the array and the element to search for

Step 3: Set a variable "found" to false

Step 4: Iterate through each element in the array

            If the current element is equal to the search element, then

                Set "found" to true

                Exit the loop

Step 5: If "found" is true, then

            Display "Element found"

        Else

            Display "Element not found"

Step 6: Stop


This algorithm is effective because it searches for the element in a linear manner, checking each element one by one. It does not perform unnecessary operations and will terminate as soon as the element is found. The time complexity of this algorithm is O(n), where n is the size of the array.


In summary, definiteness ensures that an algorithm has clear and unambiguous steps, while effectiveness ensures that the algorithm solves the problem efficiently. Both aspects are crucial in designing algorithms that are easy to understand and provide optimal solutions.

Previous Post Next Post