
Page 1
1 e sExerci
Develop an algorithm to find a value V in a sorted array T[1..N] using the following
steps:
a = 1 and b = N initialize the search range.
In each iteration, a random index i is generated between a and b using the Rand
(n) function.
If T[i] equals V, the search ends successfully by returning the index .
If V is greater than T[i], the search continues in the range [i+1,b].
If V is less than T[i], the search continues in the range [a,i−1].
The process stops either when V is found or when a exceeds b, in which case V
is not present in the array.
You can call this function with an ordered array T, the size of the array N, and the value
V you want to search for. If the value is found, the function will return its position
(based index), otherwise, it will return -1.
2Exercise
We have a buffer in main memory (buf). Display the contents of the file (F) arranged in
a fixed format (TOF), knowing that all the records are stored consecutively.
3Exercise
Spread the records evenly across consecutive blocks i, i+1, and i+2 of a TOF file (a
ordered array of blocks with a fixed record format). For example, if the blocks initially
hold 10, 4, and 8 records, after redistribution, they will contain 8, 7, and 7 records,
respectively.
Sidi Bel Abbes on 16/10 /2024
FILE STRUCTURE AND DATA STRUCTURE
Tutorial : 3