String handling operations in a programming language

EasyMedium
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
Question 50
Easy

The LOCATE_PATTERN subroutine returns the position of the first occurrence of a substring in a target string (using 0-based indexing).

For example:

  • LOCATE_PATTERN("AGCTTAG", "CTT") would return 2
  • LOCATE_PATTERN("AGCTTAG", "AG") would return 0

targetMotif and sequence are variables used in the algorithm in Figure 1.

Complete the pseudo-code statement to find the position of the first occurrence of the contents of the variable targetMotif in the variable sequence and store this position in the variable position.

You must use the LOCATE_PATTERN subroutine in your answer.

Figure 1

sequence ← "AGCTTAG"
species ← "S. cerevisiae"
OUTPUT "Enter a sequence motif to search for:"
targetMotif ← USERINPUT

position ←

[1]

String handling operations in a programming language Questions

  1. GCSE
  2. /Computer Science
  3. /String handling operations in a programming language