Question: Consider the following method: public boolean isprefix ( String s 1 , String s 2 ) { int i = 0 ; if ( s

Consider the following method:
public boolean isprefix(String s1, String s2){
int i =0;
if(s1.length > s2.length)
return false;
while(i < s1.length){
if(s1[i]!= s2[i])
return false;
i++;
}
return true;
}
Exactly how many lines of code (statements) are executed by the method isprefix() in the worst case? Express your answer in terms of n, the length of the string s1.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!