Understanding sorting || Sumita Arora || Class 11 || Practical || Computer Science || Solution



P.I.P:- 10.1

 


Q3. Implement a “bouncing” bubble sort algorithm. In this version of bubble sort, instead of making passes through a list that starts at the beginning and runs through to the end, you should reverse the direction of each pass. That is, if the first pass starts at the beginning of the list and runs through to the end, the second pass would run from the end of the list back to the beginning, and then the third pass would start at the beginning again.

Assume all items in the list are integers.




P.I.P:- 10.2

 


Q2. Write a program to perform insertion sort on a given list of strings.



Q3. Write a program to perform sorting on a given list of strings, on the basis of just the first letter of the strings. Ignore all other letters for sorting purposes.

Choose sorting algorithm of yourself.




Q4. Consider the following incorrect implementation of insertion sort that sorts a given list namely List in decreasing order. Explain what is wrong and show how to fix it.

[Hint: You only need to change one line.]

for i in range(1, len(List)):
    i2 = i
    i1 = i - 1
while i1 >= 0:
    if List[i1] > List[i2]:
        v = List[i1]
        List[i1] = List[i2]
        List[i2] = v
        i1 -= 1
        i2 -= 1
    else:
        break




Q5. Write a program that inputs a sequence A of numbers and creates another sequence B of number of same size as per following guidelines:

Ask the desired order of sorting.

Place first element of sequence A into sequence B and then take each element in the sequence A:






Q6. Write a code that reduces number of comparisons in above code while creating sequence B.

2 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post