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
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.
Get Answers For Free
Most questions answered within 1 hours.