top of page
Subham Das

Bubble Sort is a internal sorting method by which a set unsorted of elements can be sorted in ascending or descending order very easily. Bubble sort is a simple sorting algorithm. This sorting algorithm is comparison-based algorithm in which each pair of adjacent elements is compared and the elements are swapped if they are not in order. This algorithm is not suitable for large data sets as its average.


# Program for bubble sort

# You can take list from user or assign a list.

list=[5,1,4,2,8]

flag = 1

pos = 0

l = len(list)

count = 0

while pos <= l-1 and flag ==1 :

flag = 0

for j in range(0,(l-1-pos)) :

if list[j] > list[j+1] :

list[j],list[j+1] = list[j+1],list[j]

flag = 1

count += 1

print("The shorted list is:",list)


# This will print the number of pass.

print("The number of pass:",count)





23 views0 comments
Subham Das

There so many mathematical series. One of the series is given below. And we use different programming language to print the sum or the series in faster. Because calculating the sum is bit tougher. So we think better to use computer languages. And here is the optimize program to print the series and sum.


2 - 5 + 8 - ........................................

9 13 17


# Program to print the series and sum too.

# Here enter the number of elements.

n = int(input("Enter number :"))

sum = 0.0

i = 1

a = 2

b = 9

while i <= n :

if i%2 == 0 :

sum = sum+(a/b)*(-1)

print((-1)*a,"/",b, end=',')

else :

sum = sum+(a/b)

print(a,"/",b, end=',')

a += 3

b += 4

i += 1

print()

print(sum)

158 views0 comments
Subham Das

A Fibonacci Series in which the first two numbers are 0 and 1 and the next numbers is sum of the preceding ones. It is a mathematical series, in which a number is get from the sum the two numbers present before it.


Xn = Xn-1 + Xn-2


# Program for Fibonacci series.

# Series : 0, 1, 1, 2, 3, 5, 8, 13, ..................


n = eval(input("Enter Number:"))

sum = 0

a = 0

b = 1

i = 1

while i < n :

if i == 1 :

print(0,end=" ")

elif i == 2 :

print(1,end=" ")

else :

sum = a+b

a = b

b = sum

print(sum,end=" ")

i += 1

print()



17 views0 comments
logo12.PNG
bottom of page