Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please answer these questions this is figure 1. Modify the sequential search procedure in Figure 5.6 to allow for lists that are not sorted 2.

please answer these questions
image text in transcribed
this is figure
image text in transcribed
1. Modify the sequential search procedure in Figure 5.6 to allow for lists that are not sorted 2. Convert the pseudocode routine Z = 0; X - 1; while (X 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 5.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 5.11 to "greater than or equal to" 6. A variation of the insertion sort algorithm is the selection sort. It begins by selecting the smallest entry in the list and moving it to the front. It then selects the smallest entry from the remaining entries in the list and moves it to the second position in the list. By repeatedly selecting the smallest entry from the remaining portion of the list and moving that entry forward, the sorted version of the list grows from the front of the list, while the back portion of the list consisting of the remaining unsorted entries shrinks. Use our pseudocode to express a procedure similar to that in Figure 5.11 for sorting a list using the selection sort algorithm. 7. Another well-known sorting algorithm is the bubble sort. It is based on the process of repeatedly comparing two adjacent names and inter- changing them if they are not in the correct order relative to each other. Let us suppose that the list in question has n entries. The bubble sort would begin by comparing (and possibly interchanging the entries in positions n and n-1. Then, it would consider the entries in positions n - 1 and n-2, and continue moving forward in the list until the first and second entries in the list had been compared (and possibly inter- changed). Observe that this pass through the list will pull the smallest entry to the front of the list. Likewise, another such pass will ensure that the next to the smallest entry will be pulled to the second position in the list. Thus, by making a total of n - 1 passes through the list, the entire list will be sorted. (If one watches the algorithm at work, one sees the small entries bubble to the top of the list-an observation from which the algo- rithm gets its name.) Use our pseudocode to express a procedure similar to that in Figure 5.11 for sorting a list using the bubble sort algorithm. ructions is an importa algorithmic concept. One method of implementing such repetition is the ite tive structure known as the loop, in which a collection of instructions, called body of the loop, is executed in a repetitive fashion under the direction of sor control process. A typical example is found in the sequential search algorith represented in Figure 5.6. Here we use a while statement to control the repe tion of the single statement Select the next entry in List as the TestEntr Indeed, the while statement while (condition) do (body) Figure 5.6 The sequential search algorithm in pseudocode procedure Search (List, TargetValue) if (List empty) then (Declare search a failure) else (Select the first entry in List to be TestEntry: while (TargetValue > TestEntry and there remain entries to be considered) do (Select the next entry in List as TestEntry.): if (TargetValue =TestEntry) then (Declare search a success.) else (Declare search a failure.) ) end if 206 Chapter 5 Algorithms exemplifies the concept of a loop structure in that its execut pattern check the condition. execute the body. check the condition. execute the body

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

=+j Explain the relationship between unions and MNEs.

Answered: 1 week ago