Question

I need to use a Bubble Sort to sort data: “C”, “Y”, “B”, “N”, “Q”, “G”,...

I need to use a Bubble Sort to sort data: “C”, “Y”, “B”, “N”, “Q”, “G”, “C” – show count of “swaps” for each 8 Queens: Place initial “Queen” on row 6, column 1 *Knight’s Tour – initial position Row 1, Column 1, for the Queens question I just need the final position of the Queen

Homework Answers

Answer #1

PART 1:

The number of swaps using bubble sort algorithm to sort the data list [“C”, “Y”, “B”, “N”, “Q”, “G”, “C”] is 11 swaps

This can be easily verified using following python code

number_comparisons, number_swaps = 0, 0
for j in range(len(input_list)):
for i in range(1, len(input_list)-j):
    number_comparisons += 1
    if input_list[i-1] > input_list[i]:
        number_swaps += 1
        input_list[i-1], input_list[i] = input_list[i], input_list[i-1]

for PART 2, the question is not completely clear. If you are looking for solution to the placement of 8 queens on chess board when the the given initial position of queen is row 6 column 1, there is no feasible solution to the 8-queens problem.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
# Parts to be completed are marked with '<<<<< COMPLETE' import random N = 8 MAXSTEPS...
# Parts to be completed are marked with '<<<<< COMPLETE' import random N = 8 MAXSTEPS = 5000 # generates a random n-queens board # representation: a list of length n the value at index i is # row that contains the ith queen; # exampe for 4-queens: [0,2,0,3] means that the queen in column 0 is # sitting in row 0, the queen in colum 1 is in row, the queen in column 2 # is in row 0,...
Y = C + I + G + (N-X), Explain what each component in this equation...
Y = C + I + G + (N-X), Explain what each component in this equation stands for. Now show long run equilibrium on a graph using Aggregate Demand and Aggregate Supply curves. Make sure to label everything. ?this essay question, please explain detailely?
(1 point) A Bernoulli differential equation is one of the form dydx+P(x)y=Q(x)yn     (∗) Observe that, if n=0...
(1 point) A Bernoulli differential equation is one of the form dydx+P(x)y=Q(x)yn     (∗) Observe that, if n=0 or 1, the Bernoulli equation is linear. For other values of n, the substitution u=y1−n transforms the Bernoulli equation into the linear equation dudx+(1−n)P(x)u=(1−n)Q(x).dudx+(1−n)P(x)u=(1−n)Q(x). Consider the initial value problem y′=−y(1+9xy3),   y(0)=−3. (a) This differential equation can be written in the form (∗) with P(x)= , Q(x)= , and n=. (b) The substitution u= will transform it into the linear equation dudx+ u= . (c) Using...
Y = C[(1-t)Y] + I[ i, Y ] + G a) Derive its slope. b) Assuming...
Y = C[(1-t)Y] + I[ i, Y ] + G a) Derive its slope. b) Assuming that the IS is upward sloping, show how a change in G shifts the IS line, assuming dY=0 (a vertical slice). Draw a diagram to illustrate your result. c) Assuming that the IS is upward sloping, show how a change in G shifts the IS line, assuming di=0 (a horizontal slice). Draw a diagram to illustrate your result.
x y s t P 1 -3 1 0 0 12 1 2 0 1 0...
x y s t P 1 -3 1 0 0 12 1 2 0 1 0 3 -6 -4 0 0 1 0 The pivot element for the initial simplex tableau show is the red 1. So we need to zero out the other elements of column x. What is the formula used to zero out row 1 and column x? Multiply Row _____by_______ and then add the result to Row_____ What is the formula used to zero out row...
in C++ Please and thanks Here is a list of 6 numbers. Use the selection sort...
in C++ Please and thanks Here is a list of 6 numbers. Use the selection sort algorithm to sort this list. Fill in this table with each iteration of the loop in the selection sort algorithm. Mark the place from which you are looking for the 'next smallest element'. In this display, the upper numbers are the indices, the lower numbers are in the corresponding positions. Use the several rows provided to show the sequence of steps. 0 1 2...
Let X and Y have the joint PDF (i really just need g and h if...
Let X and Y have the joint PDF (i really just need g and h if that makes it easier) f(x) = { c(y + x^2) 0 < x < 1 and 0 < y < 1 ; 0 elsewhere a) Find c such that this is a PDF. b) What is P(X ≤ .4, Y ≤ .2) ? C) Find the Marginal Distribution of X, f(x) D) Find the Marginal Distribution of Y, f(y) E) Are X and Y...
C++ Question I have a text file that contains data from a CD (ex 1. Adagio...
C++ Question I have a text file that contains data from a CD (ex 1. Adagio “MoonLight” Sonata - Ludwig Van Beethoven /n 2. An Alexis - F.H. Hummel and J.N. Hummel) How do I sort the data by author since that information is in the middle of the string? Here's what I have that sorts the string from the beginning: if (file.is_open())    {        while (getline(file, line))        {            lines.push_back(line);        }...
Questions on C++, I am not 100% sure on answers, so need to clarify. Simple explanation...
Questions on C++, I am not 100% sure on answers, so need to clarify. Simple explanation next to the question would be nice as well. In mathematic notation, which is equivalent to the following statement when writing a pseudocode? x = 4y A. x == 4y B. x := 4y C. x -> 4y D. 4y = x Given the following pseudocode, the final value of x is __. Start int x = 5; for i in 1 to 3...
Consider permutations of the 26-character lowercase alphabet Σ={a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}. In how many of these permutations do a,b,c...
Consider permutations of the 26-character lowercase alphabet Σ={a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}. In how many of these permutations do a,b,c occur consecutively and in that order? In how many of these permutations does a appear before b and b appear before c?
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT