// returns n!
int fact(int n) {
int f_n = 1;
for(int i = n; i > 1; --i) {
f_n *= n;
}
return f_n;
}
O(n)
' Iterative solution Function iterativeFactorial(ByVal n As Long) As Long Dim factorial As Long = 1 For i As Long = 1 To n factorial *= i Next Return factorial End Function ' Recursive solution Function recursiveFactorial(ByVal n As Long) As Long If n <= 1 Then Return n End If Return n * recursiveFactorial(n - 1) End Function
evaluation iz same as the testing of an algorithm. it mainly refers to the finding of errors by processing an algorithm..
Algorithm is deterministic if for a given input the output generated is same for a function. A mathematical function is deterministic. Hence the state is known at every step of the algorithm.Algorithm is non deterministic if there are more than one path the algorithm can take. Due to this, one cannot determine the next state of the machine running the algorithm. Example would be a random function.FYI,Non deterministic machines that can't solve problems in polynomial time are NP. Hence finding a solution to an NP problem is hard but verifying it can be done in polynomial time. Hope this helps.Pl correct me if I am wrong here.Thank you.Sharada
Prims Algorithm is used when the given graph is dense , whereas Kruskals is used when the given is sparse,we consider this because of their time complexities even though both of them perform the same function of finding minimum spanning tree. ismailahmed syed
The factorial f(n) = n * (n-1) * (n-2) * .. 1. For example factorial 5 (written as 5!) = 5 x 4 x 3 x 2 x 1 = 120. The function below returns the factorial of the parameter n. int factorial( int n) { if (n==1) return 1 else return n* factorial( n-1) ; }
' Iterative solution Function iterativeFactorial(ByVal n As Long) As Long Dim factorial As Long = 1 For i As Long = 1 To n factorial *= i Next Return factorial End Function ' Recursive solution Function recursiveFactorial(ByVal n As Long) As Long If n <= 1 Then Return n End If Return n * recursiveFactorial(n - 1) End Function
no answer....pls post
evaluation iz same as the testing of an algorithm. it mainly refers to the finding of errors by processing an algorithm..
design an algorithm for finding all the factors of a positive integer
kjhk
Any iterative sequence.
A root-finding algorithm is a numerical method, or algorithm, for finding a value. Finding a root of f(x) − g(x) = 0 is the same as solving the equation f(x) = g(x).
The definition of the word algorithm is a set of rules for solving a problem in a finite number of steps, as for finding the greatest common divisor.
Algorithm is deterministic if for a given input the output generated is same for a function. A mathematical function is deterministic. Hence the state is known at every step of the algorithm.Algorithm is non deterministic if there are more than one path the algorithm can take. Due to this, one cannot determine the next state of the machine running the algorithm. Example would be a random function.FYI,Non deterministic machines that can't solve problems in polynomial time are NP. Hence finding a solution to an NP problem is hard but verifying it can be done in polynomial time. Hope this helps.Pl correct me if I am wrong here.Thank you.Sharada
Prims Algorithm is used when the given graph is dense , whereas Kruskals is used when the given is sparse,we consider this because of their time complexities even though both of them perform the same function of finding minimum spanning tree. ismailahmed syed
The Reverse Delete Algorithm for finding the Minimum Spanning Tree was first introduced by Edsger Dijkstra in 1959. He presented this algorithm in his paper titled "A note on two problems in connexion with graphs" which was published in Numerische Mathematik.
The factorial f(n) = n * (n-1) * (n-2) * .. 1. For example factorial 5 (written as 5!) = 5 x 4 x 3 x 2 x 1 = 120. The function below returns the factorial of the parameter n. int factorial( int n) { if (n==1) return 1 else return n* factorial( n-1) ; }