answersLogoWhite

0


Want this question answered?

Be notified when an answer is posted

Add your answer:

Earn +20 pts
Q: How do you swap the hieghest value n array with the lowest value give an algorithm for it?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is the first value that is searched for in an array when using a selection sort algorithm?

The first value is marked first, and then the smallest value is searched to compare to the first and then place in the appropriate location.


What is recursive call in terms of algorithm?

A recursive call in an algorithm is when a function (that implements this algorithm) calls itself. For example, Quicksort is a popular algorithm that is recursive. The recursive call is seen in the last line of the pseudocode, where the quicksort function calls itself. function quicksort('array') create empty lists 'less' and 'greater' if length('array') ≤ 1 return 'array' // an array of zero or one elements is already sorted select and remove a pivot value 'pivot' from 'array' for each 'x' in 'array' if 'x' ≤ 'pivot' then append 'x' to 'less' else append 'x' to 'greater' return concatenate(quicksort('less'), 'pivot', quicksort('greater'))


What will be the Flowchart for adding all elements in an array in c plus plus?

It is not possible to show a flowchart in this website -- it is text only. The algorithm can be summarised as follows: int sum(std::array<int>& a) { int sum = 0; // initialise the return value for (auto i : a) // for each value in the array sum += i; // increment the sum by the value return sum; // return the sum }


Which algorithm is preferable to find a specific number from unsorted array?

If the array is unsorted then there is no algorithm that can be applied other than a sequential traversal from one end of the array to the other until the number is found or the end of the array is reached. This is an extremely poor algorithm as the worst case would be O(n) for n elements. While this may be fine for small arrays, it is highly inefficient for larger arrays. To apply a more efficient algorithm with a worst case of O(log n), you must sort the array. You can then use a binary search algorithm by starting at the middle element. If that's your value, you're done. If not and the value you seek is less than this value, then you can eliminate all the elements in the upper half of the array, otherwise you can eliminate all the elements in the lower half of the array. Repeat the process with the remaining subarray, reducing the number of remaining elements by half each time. If you end up with a subarray with no elements then the value does not exist. Sorted arrays that are perfectly balanced offer the best performance. For instance, an array with 63 elements is perfectly balanced because after the first iteration you are left with another perfectly balanced array of 31 elements (because you eliminated 31 elements plus the middle element). After the next iteration you will be left with 15 elements, then 7, 3, 1 and finally 0. Thus a 63-element array takes no more than 6 iterations to determine that a value does not exist, compared to 63 iterations with a sequential traversal search upon an unsorted array. 6 iterations is also the average because the 6th iteration can locate any one of 32 values, which is more than half the values.


What algorithm uses a loop to step through each element of an array starting with the first element searching for a value?

What you're describing is called a sequential search or linear search.


Find largest value algorithm in c?

** pseudo code ** if array length == 1, return first element else if array length > 1 max = first element for second item to last item if item > max max = item return max else // array length is 0 error


What is the condition of second largest number?

There is no such condition. The algorithm to locate the second largest number in an array of numbers is: Sort the array in descending order. Remove the duplicate values from the array. If there are two or more elements remaining, return the second number. If there is less than two elements remaining, return the NaN value (not a number).


What is the algorithm for find the first biggest and second biggest of a list of numbers?

Here's a way to do it in pseudo-code:create an array with two elementsif the first number in the provided list is greater than the second one assign the first one to the first array elementassign the second one to the second array elementelse assign the first one to the second array elementassign the second one to the first array elementfor every other number in the list if the number is greater than the first element in the array swap their valuesif the number is greater than the second element in the array assign it to the second elementAnd that's it. You may notice that this algorithm will work no matter how many of the largest numbers you're looking for. Here's an example of how to do it in PHP:


How do I write a program that converts sentences into Morse code?

This is done with an algorithm that takes a text string and process each letter in turn. In computing text letters are usually coded as ASCII characters where the character is encoded as a specific numeric value. The algorithm will obtain this value and use it as in index into an array storing the Morse Code representation for every ASCII character. The output of the algorithm with thus be a Morse translation of the text input.


How to Write a psuedocode algorithm to read in three numbers and print the highest and lowest number?

read num1 read num2 sum = num1 num2 print highest value


Array is value type or reference type in CSharp?

Array is a class name, hence ought to be a value type.


How do you print an array in php?

There are a few methods however the following is the method that will allow you to do the most with the information afterwards. foreach($array as $key => $value){ echo '[' . $key . '] ' . $value; #$key becomes the array key and value because what the current array item has inside. }