MHB Will the Command in the Algorithm Execute if A[1]==5?

  • Thread starter Thread starter evinda
  • Start date Start date
AI Thread Summary
The discussion revolves around the execution of a command within a recursive algorithm that checks if the first element of an array equals 5. When the function is called with updated indices, the value of A[1] remains unchanged, as the algorithm operates on the indices rather than modifying the array itself. Consequently, the command associated with the if-statement will be executed based on the original value of A[1], which does not change regardless of the recursive calls. The key takeaway is that the logical result of the if-statement depends solely on the initial state of the array, not on the subarray created during recursion.
evinda
Gold Member
MHB
Messages
3,741
Reaction score
0
Hello! (Wave)

Consider that we have an algorithm of the form:

Code:
Algorithm(A[1...n], low, high){
    mid=low+floor((high-low)/2);
    if (A[1]==5) { command }
    commands
    Algorithm(A,mid+1,high)
}

When we call
Code:
Algorithm(A,mid+1,high)
will the command of the if statement (if A[1]==5) be executed? (Thinking)
 
Technology news on Phys.org
evinda said:
Hello! (Wave)

Consider that we have an algorithm of the form:

Code:
Algorithm(A[1...n], low, high){
    mid=low+floor((high-low)/2);
    if (A[1]==5) { command }
    commands
    Algorithm(A,mid+1,high)
}

When we call
Code:
Algorithm(A,mid+1,high)
will the command of the if statement (if A[1]==5) be executed? (Thinking)

It will be executed but the logical result of the if statement depends on the array it self (Is the first value equal to 5?) .

Am I misunderstanding your question ?
 
Last edited:
ZaidAlyafey said:
It will be executed but the logical result of the if statement depends on the array it self (Is the first value equal to 4 ?) .

Am I misunderstanding your question ?

If we call the function
Code:
 Algorithm(A,mid+1,high)
will the first element of the subarray be equal to $A[1]$ or to $A[mid+1]$?

So, will the command of the if-statement be executed or not? (Thinking)
 
evinda said:
If we call the function
Code:
 Algorithm(A,mid+1,high)

will the first element of the subarray be equal to $A[1]$ or to $A[mid+1]$?

So, will the command of the if-statement be executed or not? (Thinking)

Code:
Let the following 
A = {4 , 5 , 6 , 2 , 3 , 1} 
If we call Alogrithm(A , 1 , 6);
mid = 3;
A[1] = 4 

in the second call 

Alogrithm (A , 4 , 6)
mid = 5
A[1] = 4 // no change in the value of the array.
 
ZaidAlyafey said:
Code:
Let the following 
A = {4 , 5 , 6 , 2 , 3 , 1} 
If we call Alogrithm(A , 1 , 6);
mid = 3;
A[1] = 4 

in the second call 

Alogrithm (A , 4 , 6)
mid = 5
A[1] = 4 // no change in the value of the array.

So, the value of A[1] will not change, right? (Thinking)

Thanks a lot! (Smile)
 
evinda said:
So, the value of A[1] will not change, right? (Thinking)

Thanks a lot! (Smile)

Yes , because we are not changing the value we are changing the indices.
 
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...
Back
Top