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)
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
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
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.
In this programming exercise you will create an algorithm for solving the following version of the...
In this programming exercise you will create an algorithm for solving the following version of the m Smallest Numbers problem.   Instead of just returning the m smallest values as in homework 1, you want to return a list of the positions where the m smallest values are located without changing the original array. Your algorithm should meet the following specifications: mSmallest( L[1..n], m ) Pre: L is a list of distinct integer values. n is the number of elements in...
A program devise a recursive algorithm to find a2n, where a is a real number and...
A program devise a recursive algorithm to find a2n, where a is a real number and n is a positive integer (hint: use the equality a2n+1 = (a^2n)^2
1) You must implement a recursive Quicksort algorithm that will read integers from the attached MyList.txt...
1) You must implement a recursive Quicksort algorithm that will read integers from the attached MyList.txt file. Your algorithm must sort the list(integers)in ascending order. 2)You must implement a recursive Mergesort algorithm that will read integers from the attached MyList.txt file. Your algorithm must sort the list(integers)in ascending order. My List txt Values 7 3 4 1 4 4 9 9 4 8 4 5 3 9 2 3 7 0 6 4 4 5 0 1 9 2 1...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT