Question

Devise an algorithm that takes a list of n > 1 integers and finds the largest...

Devise an algorithm that takes a list of n > 1 integers and finds the largest and smallest values in the list.

Homework Answers

Answer #1

In algorithm, we have implemented the Bubble Sort algorithm that will sort the list element in an ascending order. The First element of the list will always be smallest element and the last element of the list will always be largest element of the list. Please rate our program as Helpful. Let us know if there is any further query. Thanks.


Explanation:

Solution:

Algorithm_1(DATA, N)

  1. Start
  2. Read the Array DATA with N Number of elements in the list.
  3. Repeat Steps 4 and 5 for K = 1 to N-1
  4. Set PTR := 1[Initialize the Pointer Variable]
  5. Repeat while PTR ≤ N-K (Execute Pass)

(a) if DATA[PTR] > DATA[PTR + 1] then:

i. Set temp := DATA[PTR]

ii. Set DATA[PTR] := DATA[PTR +1]

iii. Set DATA[PTR + 1] := temp

[End of If Structure]

(b) Set PTR := PTR +1

[End of Inner Loop]

[End of Step Outer 3 Loop]

6. Set Smallest := DATA[0]

7. Set Largest := DATA[N-1]

8. Exit.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
1). Describe an algorithm that takes a list of n integers a1,a2,...,an and find the average...
1). Describe an algorithm that takes a list of n integers a1,a2,...,an and find the average of the largest and smallest integers in the list.
Pseudocode an algorithm that takes as input a list of n integers and finds the number...
Pseudocode an algorithm that takes as input a list of n integers and finds the number of even integers in the list.
Describe an algorithm that takes as input a list of n integers and finds the location...
Describe an algorithm that takes as input a list of n integers and finds the location of the first even integer or returns -1 if there is no even integer in the list. Here is the operation's header: procedure locationOfFirstEven(a1, a2, a3, ..., an : integers)
design an algorithm in a c++ function that takes as input a list of n integers...
design an algorithm in a c++ function that takes as input a list of n integers and find the location of the last even integer in the list or returns 0 if there are no even integers in the list
Given a list of n integers, find the largest integer in the list. Use Java or...
Given a list of n integers, find the largest integer in the list. Use Java or C++ please
Algorithm problem 3 [BvG1.5] Show that [lg(n+ 1)] =[lg n] + 1 for integers n≥1. Hint:...
Algorithm problem 3 [BvG1.5] Show that [lg(n+ 1)] =[lg n] + 1 for integers n≥1. Hint: Group values of n into ranges of the form (2^(k)) ≤ n < (2^(k+1))
Give an algorithm for finding the second largest integer in a finite sequence of integers. Write...
Give an algorithm for finding the second largest integer in a finite sequence of integers. Write the algorithm in pseudocode format
a) Give a recursive algorithm for finding the max of a finite set of integers, making...
a) Give a recursive algorithm for finding the max of a finite set of integers, making use of the fact that the max of n integers is the larger of the last integer in the list and the max of the first n-1 integers in the list. Procedure power(x,n): If (n=0): return 1 Else: return power(x,n-1) · x b) Use induction to prove your algorithm is correct
a. Find an algorithm for solving the following problem: Given a positive integer n, find the...
a. Find an algorithm for solving the following problem: Given a positive integer n, find the list of positive integers whose product is the largest among all the lists of positive integers whose sum is n. For example, if n is 4, the desired list is 2, 2 because 2 × 2 is larger than 1 × 1 × 1 × 1, 2 × 1 × 1, and 3 × 1. If n is 5, the desired list is 2,...
Describe an algorithm that, given a set S of n integers and another integer x, determines...
Describe an algorithm that, given a set S of n integers and another integer x, determines whether or not there exist two elements in S whose sum is exactly x. Your algorithm must be nlogn. Evaluate how long each step in the algorithm takes to demonstrate that it meets this requirement.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT