Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

SEQUENCE ALLIGNMENT Find strings x and y such that in the completed \"opt\" tabl

ID: 3857225 • Letter: S

Question

SEQUENCE ALLIGNMENT

Find strings x and y such that in the completed "opt" table (where opt[i][j] = optimum cost of aligning x0 x1 x2 ... x_{m-1} with y0 y1 y2 ... y_{n-1}), there exist (provide them) values i and j such that the following holds:

x_i == y_j and    opt[ i ][ j ] = 2 + opt[ i+1][ j ] = 2 + opt[ i ][ j+1]    = 0 + opt[ i + 1][ j + 1].

or

prove that this cannot happen for ANY strings x and y.

y T A A G G T C A - x 0 1 2 3 4 5 6 7 8 A 0 7 8 10 12 13 15 16 18 20 A 1 6 6 8 10 11 13 14 16 18 C 2 6 5 6 8 9 11 12 14 16 A 3 7 5 4 6 7 9 11 12 14 G 4 9 7 5 4 5 7 9 10 12 T 5 8 8 6 4 4 5 7 8 10 T 6 9 8 7 5 3 3 5 6 8 A 7 11 9 7 6 4 2 3 4 6 C 8 13 11 9 7 5 3 1 3 4 C 9 14 12 10 8 6 4 2 1 2 - 10 16 14 12 10 8 6 4 2 0

Explanation / Answer

SEQUENCE ALLIGNMENT

strings x and y such that in the completed "opt" table (where opt[i][j] = optimum cost of aligning

           

mode 1:defint a-z

input "Board size: ",size

input "Start position: ",a$

x=asc(mid$(a$,1,1))-96

y=val(mid$(a$,2,1))

dim play(size,size)

for q=1 to 8

read dx(q),dy(q)

next

data 2,1,1,2,-1,2,-2,1,-2,-1,-1,-2,1,-2,2,-1

pen 0:paper 1

for q=1 to size

locate 3*q+1,24-size

print chr$(96+q);

locate 3*(size+1)+1,26-q

print using "#"; q;

next

pen 1:paper 0

' main loop

n=n+1

play(x,y)=n

locate 3*x,26-y

print using "##"; n;

if n=size*size then call &bb06:end

nmov=100

for q=1 to 8

xc=x+dx(q)

yc=y+dy(q)

gosub 360

if nm<nmov then nmov=nm:qm=q

next

x=x+dx(qm)

y=y+dy(qm)

goto 200

' find moves

if xc<1 or yc<1 or xc>size or yc>size then nm=1000:return

if play(xc,yc) then nm=2000:return

nm=0

390 for q2=1 to 8

xt=xc+dx(q2)

yt=yc+dy(q2)

if xt<1 or yt<1 or xt>size or yt>size then 460

if play(xt,yt) then 460

nm=nm+1

' skip this move

next

return

OR

#!/usr/bin/Rscript

# M x N Chess Board.

M = 8; N = 8; board = matrix(0, nrow = M, ncol = N)

# Get/Set value on a board position.

getboard = function (position) { board[position[1], position[2]] }

setboard = function (position, x) { board[position[1], position[2]] <<- x }

# (Relative) Hops of a Knight.

hops = cbind(c(-2, -1), c(-1, -2), c(+1, -2), c(+2, -1),

c(+2, +1), c(+1, +2), c(-1, +2), c(-2, +1))

# Validate a move.

valid = function (move) {

all(1 <= move & move <= c(M, N)) && (getboard(move) == 0)

}

# Moves possible from a given position.

explore = function (position) {

moves = position + hops

cbind(moves[, apply(moves, 2, valid)])

}

# Possible moves sorted according to their Wornsdorff cost.

candidates = function (position) {

moves = explore(position)

# No candidate moves available.

if (ncol(moves) == 0) { return(moves) }

wcosts = apply(moves, 2, function (position) { ncol(explore(position)) })

cbind(moves[, order(wcosts)])

}

# Recursive function for touring the chess board.

knightTour = function (position, moveN) {

# Tour Complete.

if (moveN > (M * N)) {

print(board)

quit()

}

# Available moves.

moves = candidates(position)

# None possible. Backtrack.

if (ncol(moves) == 0) { return() }

# Make a move, and continue the tour.

apply(moves, 2, function (position) {

setboard(position, moveN)

knightTour(position, moveN + 1)

setboard(position, 0)

})

}

# User Input: Starting position (in algebraic notation).

square = commandArgs(trailingOnly = TRUE)

# Convert into board co-ordinates.

row = M + 1 - as.integer(substr(square, 2, 2))

ascii = function (ch) { as.integer(charToRaw(ch)) }

col = 1 + ascii(substr(square, 1, 1)) - ascii('a')

position = c(row, col)

# Begin tour.

setboard(position, 1); knightTour(position, 2)