in Algorithms recategorized by
606 views
0 votes
0 votes

A sequential search operation is performed on an array $A$ for the key value of $'x'$ (ignore quotes). Consider the following piece of assembly language code that uses back patching to perform the sequential search.
i=0;
P: if (i<A.length) goto ____;
Q: goto ____;
R: if (x==A[i]) goto ____
S: goto _____;
T: return i;
U: return -1;

What should be the correct values in the blanks provided ordered from top to bottom?

  1. R T U P
  2. R U T P
  3. P U T R
  4. P T U R
in Algorithms recategorized by
606 views

1 Answer

2 votes
2 votes
Best answer

it's like below-

i=0; 
P: if (i<A.length) goto __R__; // if length of the array is not 0 then next we'll check the condition on R.
Q: goto __U__; // if array length is 0 then return -1.
R: if (x==A[i]) goto __T__ // if element is found then return the index.
S: goto ___P__; // else not found go to P.
T: return i; 
U: return -1; 

Option B.

 

selected by
Answer:

Related questions