Explore BrainMass
Share

Span of an element in a non-decreasing sorted sequence

This content was COPIED from BrainMass.com - View the original, and get the already-completed solution here!

Give the pseudo code for finding the span of an element in a non-decreasing sorted sequence of given length. Sequence is indexed from 1 onwards.

For example, in the sequence {0,2,3,3,4,5,5,5,5,6,8,10,11,11,12}, span of element 5 is [6-9], and for element 2 it is [2,2].

© BrainMass Inc. brainmass.com March 21, 2019, 1:51 pm ad1c9bdddf
https://brainmass.com/computer-science/sorting/span-element-nondecreasing-sorted-sequence-107943

Solution Preview

In the following pseudocode, let S[1..N] indicate the sequence of size N, and e the element whose span we want to find in this sequence.

spanStart = 0
spanEnd = 0
index = 0

While (index < ...

Solution Summary

Solution gives the pseudocode for a simple algorithm to find the span of a given element in the given non-decreasing sorted sequence.

$2.19