// returns n!
int fact(int n) {
int f_n = 1;
for(int i = n; i > 1; --i) {
f_n *= n;
}
return f_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
The fastest algorithm for finding the shortest path in a graph is Dijkstra's algorithm.
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
The fastest shortest path algorithm for finding the most efficient route between two points is Dijkstra's algorithm.
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).
Newton's method, also known as Newton-Raphson method, is an iterative technique for finding the roots of a real-valued function. It starts with an initial guess and refines the estimate in each iteration by using the derivative of the function. The method is based on the principle that a function can be approximated locally by a linear function at a root.
The average running time of Dijkstra's algorithm for finding the shortest path in a graph is O(V2), where V is the number of vertices in the graph.
The A algorithm is more efficient than Dijkstra's algorithm because it uses heuristics to guide its search, making it faster in finding the shortest path. A is also optimal when using an admissible heuristic, meaning it will always find the shortest path. Dijkstra's algorithm, on the other hand, explores all possible paths equally and is not as efficient or optimal as A.