a) perform a linear search by hand for the array [20,−20,10,0,15], loching for 0 , and showing each iteration one line at a time b) perform a binary search by hand fo the array [20,0,10,15,20], looking for 0 , and showing each iteration one line at a time c) perform a bubble surt by hand for the array [20,−20,10,0,15], shouing each iteration one line at a time d) perform a selection sort by hand for the array [20,−20,10,0,15], showing eah iteration one line at a time

Answers

Answer 1

In the linear search, the array [20, -20, 10, 0, 15] is iterated sequentially until the element 0 is found, The binary search for the array [20, 0, 10, 15, 20] finds the element 0 by dividing the search space in half at each iteration, The bubble sort iteratively swaps adjacent elements until the array [20, -20, 10, 0, 15] is sorted in ascending order and The selection sort swaps the smallest unsorted element with the first unsorted element, resulting in the sorted array [20, -20, 10, 0, 15].

The array is now sorted: [-20, 0, 10, 15, 20]

a) Linear Search for 0 in the array [20, -20, 10, 0, 15]:

Iteration 1: Compare 20 with 0. Not a match.

Iteration 2: Compare -20 with 0. Not a match.

Iteration 3: Compare 10 with 0. Not a match.

Iteration 4: Compare 0 with 0. Match found! Exit the search.

b) Binary Search for 0 in the sorted array [0, 10, 15, 20, 20]:

Iteration 1: Compare middle element 15 with 0. 0 is smaller, so search the left half.

Iteration 2: Compare middle element 10 with 0. 0 is smaller, so search the left half.

Iteration 3: Compare middle element 0 with 0. Match found! Exit the search.

c) Bubble Sort for the array [20, -20, 10, 0, 15]:

Iteration 1: Compare 20 and -20. Swap them: [-20, 20, 10, 0, 15]

Iteration 2: Compare 20 and 10. No swap needed: [-20, 10, 20, 0, 15]

Iteration 3: Compare 20 and 0. Swap them: [-20, 10, 0, 20, 15]

Iteration 4: Compare 20 and 15. No swap needed: [-20, 10, 0, 15, 20]

The array is now sorted: [-20, 10, 0, 15, 20]

d) Selection Sort for the array [20, -20, 10, 0, 15]:

Iteration 1: Find the minimum element, -20, and swap it with the first element: [-20, 20, 10, 0, 15]

Iteration 2: Find the minimum element, 0, and swap it with the second element: [-20, 0, 10, 20, 15]

Iteration 3: Find the minimum element, 10, and swap it with the third element: [-20, 0, 10, 20, 15]

Iteration 4: Find the minimum element, 15, and swap it with the fourth element: [-20, 0, 10, 15, 20]

To know more about Iteration refer to-

https://brainly.com/question/31197563

#SPJ11


Related Questions

Other Questions
currently the federal minimum wage is 7.25 should the federal government raise the minimum wage? why or why not?How will this impact businesses and consumers? would there be any other things to vonsider if wages are raised?Currently, the federal minimum wage is 7.25 should the federal government raise the minimum wage? why or why not?How will this impact businesses and consumers? would there be any other things to consider if wages are raised? a racquetball strikes a wall with a speed of 30 m/s and rebounds in the opposite direction with a speed of 1 6 m/s. the collision takes 5 0 ms. what is the average acceleration (in unit of m/s 2 ) of the ball during the collision with the wall? What is the use of pancreas in the human body A piano tuner stretches a steel piano wire with a tension of 765 N. The steel wire has a length of 0. 600m and a mass of 4. 50g. What is the frequency f1 of the string's fundamental mode of vibration?Express your answer numerically in hertz using three significant figures For the given function, find (a) the equation of the secant line through the points where x has the given values and (b) the equation of the tangent line when x has the first value. y=f(x)=x^2+x;x=4,x=1 Suppose that in January a profit-maximizing firm has 25 employees. By February, the firm has decreased employment. One can infer that, when 25 employees are hired, theA) firm is losing market share.B) firm is minimizing losses.C) wage exceeds the value of the marginal product of labor.D) value of the marginal product of labor exceeds the wage A compound consisting of carbon and hydrogen consists of 67.90%carbon by mass. If the compound is measure to have a mass of 37.897Mg, how many grams of hydrogen are present in the compound? A split-plot design is also known as a:counterbalanced designmixed designTukey HSDblock design Explain the steps to generate machine code from a C/C++ code. 0.059 and 0.01 which is greater? Eight guests are invited for dinner. How many ways can they be seated at a dinner table if the table is straight with seats only on one side?A) 1B) 40,320C) 5040D) 362,880 determine the resultant force acting on the 0.7-m-high and 0.7-m-wide triangular gate Write the slope -intercept form of the equation of the line containing the point (5,-8) and parallel to 3x-7y=9 We can use JS DOM to add event listeners to elements?true or false the area of the pool was 4x^(2)+3x-10. Given that the depth is 2x-3, what is the wolume of the pool?