(a.) The java code for the above problem statement is as follows:-
}
The pseudocode of the above code will be as follows:-
Images Not Shown
The time complexity of the above code will be O(n) where n is the number of weights in the array, this is because for n number of times the recursive function counter will be called and on each calling of function only simple execution of if else statement will takes place. therefore total complexity will be only n*1 which is n therefore the time complexity will be O(n).
(b.) The output of the above code on input array [1,2,4,5,5,6,7,8,8,9] a=3 and b=8 will be 7 as there are only 7 weights wXXXX XXXX between X XXX 8 (XXXXXXXXX)that XX {X,X,X,6,7,8,X}, XXX tracing XX the XXXXXXXXX is XX XXXXXXX:-
print(counter(ar,X, 9,X,8))
for counter(ar,X,X,X,8) :-
XXXXX X!=9 therefore it will call XXXXXXX(ar,X,X,3,8) + counter(XX,5,9,3,X)
1. for XXXXXXX(XX,X,4,3,X) :-
since X!=X therefore it XXXX XXXX XXXXXXX(ar,X,X,X,X) + counter(XX,3,4,3,8)
X.X for counter(ar,X,X,X,8) :-
XXXXX 0!=2 therefore it will XXXX XXXXXXX(XX,0,X,3,8) + XXXXXXX(XX,2,2,3,X)
1.X.X XXX counter(XX,X,X,3,X) :-
since X!=X XXXXXXXXX it will call XXXXXXX(ar,X,X,X,8) + counter(XX,X,1,3,X)
X.X.X.1 XXX counter(XX,X,0,X,8) :-
XXXXX X==X but X!<=1 is false therefore it will return X
X.X.1.2 for XXXXXXX(XX,X,X,X,X) :-
XXXXX X==1 but 3!&XX;=2 XX XXXXX XXXXXXXXX it will XXXXXX 0
XXX value return XX XXXXXXX(ar,X,X,3,X) will be X+X =X
1.1.X XXX XXXXXXX(XX,X,2,3,8) :-
since X==2 XXX 3&XX;=4 XXX 4<=X is true XXXXXXXXX it XXXX return 1
the value return XX XXXXXXX(ar,0,X,X,8) will be 0+1 = X
X.2 for XXXXXXX(XX,3,4,3,X) :-
XXXXX 3!=X XXXXXXXXX it will call XXXXXXX(XX,3,3,3,8) + XXXXXXX(ar,4,4,3,X)
X.X.1 for XXXXXXX(ar,3,X,X,X) :-
XXXXX 3==3 and X&XX;=5 and 5&XX;=8 is XXXX XXXXXXXXX it will XXXXXX 1
X.2.2 XXX XXXXXXX(ar,4,4,X,X) :-
since X==X and 4<=5 and 5<=X XX true therefore it will return X
the value XXXXXX by counter(XX,3,4,X,X) XXXX be 1+1 = 2
the value return by counter(XX,0,X,X,8) will XX 1+X = 3
2. for XXXXXXX(XX,5,9,3,X) :-
XXXXX X!=9 XXXXXXXXX it will call counter(XX,X,7,X,X) + XXXXXXX(XX,X,9,X,X)
2.1 XXX XXXXXXX(XX,5,X,3,8) :-
since 5!=X therefore it XXXX XXXX XXXXXXX(ar,X,6,3,8) + counter(ar,X,X,X,X)
2.X.X for XXXXXXX(ar,5,X,X,8) :-
XXXXX 5!=X therefore it will call counter(ar,5,X,3,X) + XXXXXXX(ar,6,X,X,8)
X.1.1.X for counter(ar,X,X,3,X) :-
since 5==5 XXX X&XX;=X and 6&XX;=X is true XXXXXXXXX it will XXXXXX X
2.X.1.2 for XXXXXXX(ar,6,6,X,X) :-
since 6==6 XXX 3&XX;=X iand 7&XX;=8 is true XXXXXXXXX it XXXX XXXXXX X
XXX value return by counter(XX,5,X,X,X) XXXX XX 1+1 =X
X.1.2 for counter(XX,X,X,3,8) :-
since 2==X XXX X&XX;=X XXX X&XX;=X is true XXXXXXXXX it XXXX return 1
XXX XXXXX return by XXXXXXX(XX,5,X,3,X) XXXX XX 2+X = 3
X.X XXX counter(ar,8,9,X,X) :-
XXXXX 8!=X therefore it will call XXXXXXX(ar,X,X,3,8) + counter(ar,9,9,X,X)
X.X.1 for XXXXXXX(XX,8,8,X,8) :-
XXXXX X==8 and 3<=8 XXX X&XX;=X is XXXX therefore it XXXX return X
X.X.2 for XXXXXXX(XX,9,9,3,X) :-
since 4==4 and X&XX;=X but X!&XX;=8 is false therefore it XXXX XXXXXX X
XXX XXXXX return by XXXXXXX(XX,X,X,3,X) XXXX be 1+X = X
the value XXXXXX XX counter(XX,X,9,3,8) will XX X+3 = 4
the value return XX counter(XX,X,9,3,X) will be X+X = X which is XXX final XXX XXXXXXX answer
">