In deterministic algorithm, for a given particular input, the computer will always produce the same output going through the same states but in case of non-deterministic algorithm, for the same input, the compiler may produce different output in different runs. In fact non-deterministic algorithms can’t solve the problem in polynomial time and can’t determine what is the next step. The non-deterministic algorithms can show different behaviors for the same input on different execution and there is a degree of randomness to it.

To implement a non-deterministic algorithm, we have a couple of languages like Prolog but these don’t have standard programming language operators and these operators are not a part of any standard programming languages.
Some of the terms related to the non-deterministic algorithm are defined below:
- choice(X) : chooses any value randomly from the set X.
- failure() : denotes the unsuccessful solution.
- success() : Solution is successful and current thread terminates.
Example :
Problem Statement : Search an element x on A[1:n] where n>=1, on successful search return j if a[j] is equals to x otherwise return 0.
Non-deterministic Algorithm for this problem :
1.j= choice(a, n) 2.if(A[j]==x) then { write(j); success(); } 3.write(0); failure();
| Deterministic Algorithm | Non-deterministic Algorithm |
|---|---|
| For a particular input the computer will give always same output. | For a particular input the computer will give different output on different execution. |
| Can solve the problem in polynomial time. | Can’t solve the problem in polynomial time. |
| Can determine the next step of execution. | Cannot determine the next step of execution due to more than one path the algorithm can take. |
Recommended Posts:
- What is the difference between GUI and CUI?
- Difference between Where and Group By
- What is the difference between the | and || or operator in php?
- Difference between std::quick_exit and std::abort
- Difference between Applets and Servlets
- Difference between Definition and Declaration
- What is the difference between HTTP_HOST and SERVER_NAME in PHP?
- Difference between bindParam and bindValue in PHP
- Difference between Recursion and Iteration
- How to calculate the difference between two dates in PHP?
- Difference between HTML and HTML5
- Difference between Static and Shared libraries
- What is the difference between is_a() function and instanceof in PHP?
- What is the difference between echo, print, and print_r in PHP?
- Minimum absolute difference between N and a power of 2
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



