Question: 2. Consider the function SPLIT, which takes as input three arguments: a nonempty array of integers, a positive integer n representing the number of the

 2. Consider the function SPLIT, which takes as input three arguments:

2. Consider the function SPLIT, which takes as input three arguments: a nonempty array of integers, a positive integer n representing the number of the elements of P, and a positive integer e. The function SPLIT outputs three (possibly empty) arrays A, B and C such that: Array A contains all the elements of P occurring before the first occurrence of e in P. Array C contains all the elements of P occurring after the last occurrence of e in P. . Array B contains all the elements of P occurring after the first and before the last occurrence of e in P. All elements in the array P except the first and the last occurrence of e should appear in either A, B or C. preserving their original order in P. For example, given P = 13,0.2.1.20.2.1) then A, B and C are the following arrays: . For e=0, A=[3], B=12.1.2) and C=12.1]. Fore=1, A=(3,0.2), B=(2,0.2) and C=1]. For e=2, A=(3,0), B=[1.2.0) and C-[1]. For e=3, A = 0), B = 1 and C= 10.2.1.2.0.2.1). . For e=4, A=1, B-1 and C=. Assuming that array indexing starts from 0, provide a formal specifica- tion in terms of mathematical logic formulas, with the usual predicates and relations on the integers, for the following items. a. Specify the integer valued function first(X. s. e), whose value is the smallest index, in the array X having sizes, where the value e is stored b. Specify the integer valued function last(X, $, e), whose value is the largest index, in the array X having sizes, where the value e is stored c. Specify the function SPLIT in terms of pre- and post-conditions, using also the previously specified functions first and last

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!