Write a Java program segment to search for a value v in a sorted array a of size n using binary search.
Arrays
Original Khojo Papers practice question — not from a past board paper.
for (int i = 0; i < n - 1; i++) { int min = i; for (int j = i + 1; j < n; j++) if (a[j] < a[min]) min = j; int t = a[i]; a[i] = a[min]; a[min] = t; }
No citable source has been recorded for this record. Treat it as practice material, not as fact.
Selection sort makes at most n − 1 swaps, which is fewer than bubble sort, though the number of comparisons is the same.
From the same topic and chapter, at a similar level.
Write a Java program segment to search for a value v in a sorted array a of size n using binary search.
Arrays
State the worst-case number of comparisons made by bubble sort on an array of n elements.
Arrays
Write a Java program segment to find the sum of the elements of the left diagonal of a square matrix a of size n.
Arrays
How many elements are there in a two-dimensional array declared as int a[5][4], and how much memory does it occupy if an int takes 4 bytes?
Arrays
Write a Java program segment to print the transpose of a square matrix a of size n.
Arrays
State and verify the absorption law X + X·Y = X using a truth table.
Boolean Algebra