We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
WORKSHEET 3.1
Student Name: Abdul Samad Khan UID: 21BCS1843
Branch: CSE Section/Group: 604-A Semester: 4th Date of Performance: 03-05-2023 Subject Name: Programming in Python Lab Subject Code: 21CSP-259
AIM: Program to implement various kinds of searching and sorting algorithms
SOURCE CODE AND IMPLEMENTATION:
1. Python program to implement linear search.
def linear_Search(list1, n, key): for i in range(0, n): if (list1[i] == key): return i return -1 list1 = [1 ,3, 5, 4, 7, 9] key = 7 n = len(list1) res = linear_Search(list1, n, key) if(res == -1): print("Element not found") else: print("Element found at index: ", res)
Abdul Samad Khan 21BCS1843
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING
2. Python program to implement bubble sort.
def bubbleSort(nlist): for passnum in range(len(nlist)-1,0,-1): for i in range(passnum): if nlist[i]>nlist[i+1]: temp = nlist[i] nlist[i] = nlist[i+1] nlist[i+1] = temp