Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please answer all questions. Thanks! 2. Convert the pseudocode routine Z0; while

ID: 3741484 • Letter: P

Question

Please answer all questions. Thanks!

2. Convert the pseudocode routine Z0; while (X 6) do (z ? z + x; to an equivalent routine using a repeat statement. 3. Some of the popular programming languages today use the syntax while (.) do( to represent a pretest loop and the syntax do (.) while (.) to represent a posttest loop. Although elegant in design, what problems could result from such similarities? 4. Suppose the insertion sort as presented in Figure 11 was applied to the list Gene, Cheryl, Alice, and Brenda. Describe the organization of the list at the end of each execution of the body of the outer while structure. 5. Why would we not want to change the phrase "greater than" in the while statement in Figure 11 to "greater than or equal to?

Explanation / Answer

Ans 2.

Following is the code , I have used R language as "repeat" is used in R language.

CODE:

Z <- 0
X <- 1

repeat {
Z <- Z + X
X <- X + 1
  
if(X >= 6) {
  
break
}
}

Ans 3.

Such similarities may lead to confusion, although there are very less chances of that . Even if there are minute chances , any confusion between post test and pretest should be avoided as it may lead to crash of the program. In post test , the body is executed once , then it is test for the test condition. That means is the test condition was false from the begining the body will still get executed for one time. This is undesirable in many cases.

Ans 4.

For 1st iteration let pivot = Cheryl

then after 1st iteration list will be = Cheryl, Gene, Alice, Brenda

For 2nd iteration let pivot = Alice

then after 2ns iteration list will be = Alice, Cheryl, Gene, Brenda

For 3rd iteration let pivot = Brenda

then after 3rd iteration list will be =  Alice, Brenda, Cheryl, Gene

List is now sorted completely.

Ans 5.

Since figure 11 is not given with the question, I am assuming it is reffering to comparision between pivot element and another following element of array. So my answer is according to my assumption.

There is no need to move of shift the element if it is equal to pivot element as other elements will move according to their correct place and eventually this element will come to its correct position.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote