Chapter 3: Q3E (page 202)
Device an algorithm that finds the sum of all the integers in a list.
Short Answer
The algorithm that finds the sum of all the integers in a list:
Chapter 3: Q3E (page 202)
Device an algorithm that finds the sum of all the integers in a list.
The algorithm that finds the sum of all the integers in a list:
All the tools & learning materials you need for study success - in one app.
Get started for freeDescribe an algorithm that takes an input a list of integers and finds the number of negative integers in the list.
a) Describe in detail (and in English) the steps of an algorithm that finds the maximum and minimum of a sequence of elements by examining pairs of successive elements, keeping track of a temporary maximum and a temporary minimum. Ifn is odd, both the temporary maximum and temporary minimum should initially equal the first term, and ifn is even, the temporary minimum and temporary maximum should be found by comparing the initial two elements. The temporary maximum and temporary minimum should be updated by comparing them with the maximum and minimum of the pair of elements being examined.
b) Express the algorithm described in part (a) in pseudocode.
c) How many comparisons of elements of the sequence are carried out by this algorithm? (Do not count comparisons used to determine whether the end of the sequence has been reached.) How does this compare to the number of comparisons used by the algorithm in Exercise 5?
Describe an algorithm to find the longest word in an English sentence (where a sentence is a sequence of symbols, either a letter or a blank, which can then be broken into alternating words and blanks).
How many comparisons does the insertion sort use to sort the list 1,2,3,…,n?
Adapt the bubble sort algorithm so that it stops when no interchanges are required. Express this more efficient version of the algorithm in pseudo code?
What do you think about this solution?
We value your feedback to improve our textbook solutions.