answersLogoWhite

0


Best Answer

var largest : integer

largest = array[0]

for n : integer in array

if n > largest

largest = n

endif

endfor

return largest

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What will be the algorithm to input n integers and output the largest one?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Why do you have a monitor and what are the uses?

A monitor is the "gateway" to your computer. It is the output of your computer. E.g. a mathematical formula has an input, an output and an algorithm. The keyboard & mouse is the input, the computer is the algorithm, and the monitor is the output.


What are the functions of algorithm?

A function is any relationship between inputs and outputs in which each input leads to exactly one output. It is possible for a function to have more than one input that yields the same output.


Which cache algorithm will optimize a storage arrays Input and Output response time if sequential access is detected?

Read Ahead


What is distribution sort?

Any sort algorithm where data is distributed from its input to multiple intermediate structures which are then gathered and placed on the output.


How do you write a program to print the first n multiples of 7?

Algorithm: multiples input: two positive integers, m and n output: print first n multiples of m i = m; for j = 1 to n print i i = i + m; next j


How do you explain characteristics of algorithm?

Characteristics of algorithms are: Finiteness: terminates after a finite number of steps Definiteness: rigorously and unambiguously specified Input: valid inputs are clearly specified Output: can be proved to produce the correct output given a valid input Effectiveness: steps are sufficiently simple and basic.


What is the input and output of kalman filter?

The Kalman filter is an algorithm to eliminate noise from statistical observations. The inputs and outputs are dependent on what you are applying it to.


What a C function that will compute the K in largest and K in smallest element along with their positions in an array of N signed integers. Assume the following 5 N 50 and 1K?

To compute the largest value in an array, assume that the first element is the largest and store the value. Then traverse the remainder of the array. Each time a larger value is encountered, update the stored value. Once all values are traversed, return the stored value. In pseudocode, this algorithm would be implemented as follows: Algorithm: largest Input: array A of length N Output: largest value in A let largest = A[0] // store first value for index = 1 to N-1 // traverse remaining elements if A[index] > largest then largest = A[index] // update stored value if current value is larger next index return largest To determine the position of the largest value, we alter the algorithm as follows: Algorithm: largest_by_index Input: array A of length N Output: index of the largest value in A let largest = 0; // store index 0 for index = 1 to N-1 // traverse remaining elements if A[index] > A[largest] then largest = index // update stored index next index return largest We can do the same to find the position of the smallest element: Algorithm: smallest_by_index Input: array A of length N Output: index of the smallest value in A let smallest = 0; // store index 0 for index = 1 to N-1 // traverse remaining elements if A[index] < A[smallest] then smallest = index // update stored index next index return smallest To perform both algorithms simultaneously, we need to return two values. To achieve this we can use a simple data structure known as a pair: struct pair { int smallest; int largest; }; Algorithm: range_by_index Input: array A of length N Output: a pair indicating the position of the smallest and largest values in A pair result = {0, 0} // initialise the pair for index = 1 to N-1 // traverse remaining elements if A[index] < A[result.smallest] then result.smallest = index // update stored index else if A[index] > A[result.largest] then result.largest = index // update stored index next index return result


Is an OMR an input or output?

is an omr and input or output device?


Is interactive whiteboard an input or output device?

both input r output


Is a graphic tablet output or input?

Input device.


What is the Black box concept?

A black box is where only the owner of that black box knows the algorithm that makes the mechanism change the input to the output. For example, in algorithmic trading, there is proprietary software that transacts with the incoming data and decides when to buy or sell depending on what the algorithm in that proprietary software states. Each owner of a black box has their own proprietary mechanism to change the input to the output.