hi again, i'm just full of problems.

i have a vectors of ints and i am trying to find a way to check if there is a repeatting sequence within the vector and what size this sequence is.
Does anyone have any suggestions on how i should go about this?
not looking for code just a nudge in the right direction.
:)

Recommended Answers

All 5 Replies

I am not that great with pseudocode, but this is a possible process. Basically you can use a map with string keys and int values to keep track of each sequence and if the same sequence is run into on the map, increment the value by 1--

// Input: a map with string keys and int values
// Output: 2 values - the size of the largest sequence
function FindLargestSequence(map[0... n-1])

	largestValue = 0
	largestSequence = ""

	for each key k value v in map

		if v < largestValue
			
			largestValue = v
			largestSequence = k
		end
	end

	return largestValue, largestSequence
end

// Input: a vector of length n
// Output: 2 values - the size of the largest sequence, and 
// a string with the values of the largest sequence
function VectorSequence(vector[0... n-1])

	largestSequence = 1
	s = ""

	for h = 0, h < n, h++

		for i = 0, i < n, i = i + largestSequence

			for j = 0, j < largestSequence AND i + largestSequence < n, j++

				s = s + vector[i+j]

				if j != largestSequence - 1
					s = s + ","
			end

			if occurrenceMap[s] != 0

				occurrenceMap[s] = 0
			else

				occurrenceMap[s] = occurrenceMap[s] + 1
			end

			s = ""
		end

		largestSequence = largestSequence + 1
	end

	return FindLargestSequence(occurrenceMap)
end

thanks gonna go work on this now.

Sorry, the line - "v < largestValue" is supposed to be "v > largestValue"

I dun goof'd >_<

Edit: Another problem--

if occurrenceMap[s] != 0

				occurrenceMap[s] = 0
			else

				occurrenceMap[s] = occurrenceMap[s] + 1

if occurrenceMap[s] != 0 is supposed to be if its NULL

Again, I'm sorry. The whole point is that you can use a map to help you with this kind of problem.

This pseudocode is much more intuitive. Please forgive me for the previous mistake(s).

//This vector is a vector where {2, 4} is the largest reoccurring sequence
//{1, 8, 3, 2, 4, 5, 7, 2, 4, 5, 8, 9, 2, 4}

//I'm not that good with Pseudocode, but how about this?

// returns the length of the string
function length(string[0... n-1]);

// Input: a map with string keys and int values
// Output: 2 values - the size of the largest sequence and
// a string with the values of the largest sequence
function FindLargestSequence(map[0... n-1])

	largestValue = 0
	largestSequence = ""

	for each key k value v in map

		if v >= largestValue && length(k) > length(largestSequence)
			
			largestValue = v
			largestSequence = k
		end
	end

	return largestValue, largestSequence
end

// Input: a vector of length n
// Output: 2 values - the size of the largest sequence, and 
// a string with the values of the largest sequence
function VectorSequence(vector[0... n-1])

	s = ""

	for largestSequence = 1, largestSequence <= n, largestSequence = largestSequence + 1

		for i = 0, i < n, i = i + largestSequence

			for j = 0, j < largestSequence, j = j + 1

				s = s + vector[i+j]

				if j != largestSequence - 1
					s = s + ","
			end

			if occurrenceMap[s] == NULL

				occurrenceMap[s] = 0
			else

				occurrenceMap[s] = occurrenceMap[s] + 1
			end

			s = ""
		end

		
	end

	return FindLargestSequence(occurrenceMap)
end

thanks for all the help gonna go and try to digest this now.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.