Prove correctness for following

Assignment Help Computer Engineering
Reference no: EM132911

Question

A nonempty slice of integers L [p: q] is unimodal if 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 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) else if L[ v-1] >l[v]: v=v-1
5) else: w=0
6) if w ?= 0 : return u
7) else: return -1

 

Reference no: EM132911

Questions Cloud

What is the worst-case delay for acknowledging an interrupt : What is the worst-case delay for acknowledging an interrupt
Make an employee class with enough numbers of data members : Make an Employee class with enough numbers of data members
Modify compound interest program : Modify compound interest program
Write down a java implementation : Write down a Java implementation
Prove correctness for following : Prove correctness for following
Can a relation be stored as a sequential file : Can a relation be stored as a sequential file
Study and analyze the principles of inheritance : Study and analyze the principles of inheritance
How to develop a problem definition : How to develop a problem definition
Generate a work breakdown structure code : Generate a Work Breakdown Structure Code

Reviews

Write a Review

Computer Engineering Questions & Answers

  Write a function that creates a cell and structure array

Write a function that creates a cell and structure array.

  Is it right that rbac functionality is complicated

Is it right that RBAC functionality is complicated

  Describe a project that increase an intranet

Describe a project that increase an Intranet.

  How to create program that performs arithmetic function

How to create program that performs arithmetic function Prompt a user for values for the variables. Pass both variables to methods named sum() and difference().

  How to set up or recover cybersecurity

How to set up or recover cybersecurity.

  Explain networking of cis 505

Explain networking of CIS 505? 1. Network Neutrality 2. Web2.0

  Generate the tables attach the primary key and foreign key

Generate the tables attach the primary key and foreign key

  Accessing and reading a mouse

Accessing and reading a mouse

  How to plan a payroll class

How to plan a PayRoll class.

  Explore paper on vmware security

Explore paper on VMware Security

  Problem on stack

Problem on Stack

  Determining the priority of period of execution of irqj

Determining the priority of period of execution of IRQJ

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd