0% found this document useful (0 votes)
103 views9 pages

Dsa Lab Report 443

The document describes a lab report on linear search in Python. It defines linear search, provides an example, and outlines steps to implement linear search by traversing an array with a loop to compare elements until a match is found. It then details 5 lab tasks demonstrating linear search, finding maximum/minimum values, creating arrays, and determining element positions in lists.

Uploaded by

Muhammad Haris
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
103 views9 pages

Dsa Lab Report 443

The document describes a lab report on linear search in Python. It defines linear search, provides an example, and outlines steps to implement linear search by traversing an array with a loop to compare elements until a match is found. It then details 5 lab tasks demonstrating linear search, finding maximum/minimum values, creating arrays, and determining element positions in lists.

Uploaded by

Muhammad Haris
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

:LAB REPORT 4:

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.

IMPLEMENT LINEAR SEARCH FOLLOWING THE BELOW STEPS:


 Traverse the list/array using a loop.
 In every iteration, associate the target value with the given value of the list/array.
 If the values match, return the current index of the list/array.
 Otherwise, move on to the next array/list element.
 If no match is found, return -1.

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:

You might also like