A nonempty slice of integers l


A nonempty slice of integers L[p : q] is unimodal iff there is some number m ∈ N such that p ≤ m < q, L[p : m+1] is increasing, and L[m : q] is decreasing. Such a number m, if it exists, is called the mode of L[p : q].
Prove correctness for the following :
? Precondition: L is a list of integers, p,q ∈ N, and 0 ≤ p < q ≤ len(L).
? Postcondition: Return the mode of L[p : q] if L[p : q] is unimodal; otherwise return -1.
Mode(L, p, q)
1) u = p ; v = q-1 ; w= 1 
2) while w ?= 0 and u < v :
3) if L[u] < L [u+1]: u= v + 1
4) eleif L[ v-1] >l[v]: v=v-1
5) else: w=0
6) if w ?= 0 : return u 
7) else: return -1 

Request for Solution File

Ask an Expert for Answer!!
Basic Computer Science: A nonempty slice of integers l
Reference No:- TGS090203

Expected delivery within 24 Hours