Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Loop Invariants The csort function contains several loops, including one set of nested loops. Its operation is destructive to the contents of the starting vector,
Loop Invariants
The csort function contains several loops, including one set of nested loops. Its operation is destructive to the contents of the starting vector, so in order to prove the correctness of this algorithm, we need to establish meaningful loop invariants. Note that the notation Aij refers to elements i through j in vector A inclusive.
In this problem we should assert, among other things, that our code does not change the overall number of occurrences of each distinct grade. You will complete the rest of the loop invariant in the problem below.
The purpose of the loop occupying lines through is simply to initialize the value of each index of H to zero. We will not bother to determine a loop invariant for this, nor prove its correctness.
Here we describe an invariant for the loop occupying lines through Invariant H Choose the most appropriate selections from the dropdown boxes:
At the start of the iteration described by the variable
index
of the array H contains the number of occurrences of the value
in the array Aj
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started