Dsa Lab Report 443
Dsa Lab Report 443
SUBMITTED TO:
MA’AM IQRA JABEEN
SUBMITTED BY:
MUHAMMAD HARIS
REGISTRATION NO:
21-TE-37
COURSE TITLE:
DATA STRUCTURE AND ALGORITHM
DEPARTMENT:
TELECOM
UNIVERSITY OF ENGINEERING AND TECHNOLOGY
TAXILA
Lab Task:
Demonstration and development of the program in python for linear search in an array.
Lab objective:
Try to understand linear search
Linear Search Algorithm
Searching index
Using while and for loop
LINEAR SEARCH:
DEFINITION:
Linear search in Python makes the searching technique quite efficient and easy for any element
to be searched. Linear searching in Python is also known as sequential search where the
searching is performed in a sequential manner by comparing one element to the next and so on
until the required element is found for manipulation and transformation. It makes the overall
search using indices.
EXAMPLE:
Now, we want to search the index of the element 12. For this, we will start from index 0 and
check if 12 is present there or not. If yes, we will return 0 as result or we will move to index 1.
We will keep moving in this way to index 6 where 12 is present. After checking that 12 is
present at index 6, we will return 6 as an output. If any element is not present, we will return -1
which will specify that the element is not present in the list.
LAB TASK 1
THEORY:
In this code using for loop is used for the linear search of an array, and the output gives the index
od searched number.
INPUT:
OUTPUT:
LAB TASK 2
THEORY:
By making a function using for loop we will find the maximum number of an array.
INPUT:
OUTPUT
LAB TASK 3
THEORY:
By making a function using for loop we will find the minimum number of an array.
INPUT:
OUTPUT:
LAB TASK 4
THEORY:
With the help of for loop, we can make an array content for our array.
INPUT:
OUTPUT:
Lab Task 5
THEORY:
With the help of for loop list is made and using the append function elements are appended to the
list, the code can also tell the position of an element in a list.
INPUT:
OUTPUT: