Answer:
True: In binary search algorithm, we follow the below steps sequentially:
Input: A sorted array B[1,2,...n] of n items and one item x to be searched.
Output: The index of x in B if exists in B, 0 otherwise.
- low=1
- high=n
- while( low < high )
- { mid=low + (high-low)/2
- if( B[mid]==x)
- {
- return(mid) //returns mid as the index of x
- }
- else
- {
- if( B[mid] < x) //takes only right half of the array
- {
- low=mid+1
- }
- else // takes only the left half of the array
- {
- high=mid-1
- }
- }
- }
- return( 0 )
Explanation:
For each iteration the line number 11 or line number 15 will be executed.
Both lines, cut the array size to half of it and takes as the input for next iteration.
Answer:
a) range check
Explanation:
Validation can be defined as an automatic computer check that is designed to ensure any data entered is sensible, consistent, feasible and reasonable.
Basically, there are five (5) main validation methods and these includes;
I. Presence check: checks that the user enters (inputs) data into the field. It ensures a field isn't accidentally left blank.
II. Length check: checks that the data entered isn't too short or too long. It ensures that the data meets the minimum characters.
III. Type check: checks that the data entered is in the right format. For example, string, integer, float, etc.
IV. Check digit: checks that the digit entered is acceptable and consistent with the rest of the digits.
V. Range check: checks that the data entered is between the accepted lower (minimum) and upper (maximum) level.
Hence, range check is a validation type you would use to check that numbers fell within a certain range.
For example, 0 < x > 1000 is a range check.
Answer:
Explanation:
The following code is written in Java and runs a thread every 45 seconds that adds the two counters together and saves them in an integer variable called register. Then prints the variable. If this code runs 5 times it automatically breaks the loop. This can be changed or removed by removing the breakLoopCounter variable.
public static void add_Counters(int counterOne, int counterTwo) {
int register = 0;
int breakLoopCounter = 0;
try {
while (true) {
register += counterOne + counterTwo;
System.out.println(register);
Thread.sleep(45000);
breakLoopCounter += 1;
if (breakLoopCounter == 5) {
break;
}
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}