0% found this document useful (0 votes)
1 views

DSA Lab 3

This laboratory manual outlines the implementation of linear search as part of the Data Structures and Algorithms course at BUITEMS. It includes lab outcomes, tools required, theoretical background, pseudo-code, and a coding task for students to complete. Additionally, it provides a rubric for evaluating student performance in the lab exercises.
Copyright
© © All Rights Reserved
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
0% found this document useful (0 votes)
1 views

DSA Lab 3

This laboratory manual outlines the implementation of linear search as part of the Data Structures and Algorithms course at BUITEMS. It includes lab outcomes, tools required, theoretical background, pseudo-code, and a coding task for students to complete. Additionally, it provides a rubric for evaluating student performance in the lab exercises.
Copyright
© © All Rights Reserved
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/ 5

LABORATORY MANUAL

Electrical Engineering Department

Data Structures and Algorithms

Submitted by

Huzaifa Ali 59384


Instructor
Mr. Muhammad Atif
Assistant professor, Department of Computer Science,
Faculty of Information & Communication Technology, BUITEMS, Quetta.

Lab Engineer
Engr. Ali Israr
Lab Engineer, Department of Electrical Engineering,
Faculty of Information & Communication Technology, BUITEMS, Quetta.
Session Fall – 2024
LAB MANUAL Data Structures and Algorithms

LAB NO. 3 01/ 10 / 2024


Implementation of linear search
Lab outcomes:
After completing this lab, students will be able to.

 Implement linear search.

Corresponding CLO and PLO:


 CLO-1, PLO-5 (Modern Tool Usage)

Tools:
 VS Code
 Dev C++

Theory:
1. Linear search
Search begins by comparing the first element of the list with the target element. If it matches,
the search ends. Otherwise, move to next element and compare. In this way, the target
element is compared with all the elements until a match occurs. If the match does not occur
and there are no more elements to be compared, conclude that target element is absent in the
list.
For Example:
List of numbers: - [5 9 7 8 11 2 6 4]

To search for element 11(i.e Key element = 11).


First compare the target element with first element in list i.e. 5. Since both are not matching, we
move on the next elements in the list and compare. Finally found the match after 5 comparisons.

Pseudo-code:
function linear_search (list, value)
for each item in the list
if match item == value
LAB MANUAL Data Structures and Algorithms

return the item's location


end if
end for
end function

Lab Experiments/Tasks:
Task-1: Linear Search
Write a method that takes an array and a number as argument and return index if the number is in the
array, otherwise return -1.
Code

//Huzaifa Ali 59384


#include <iostream>
using namespace std;
int main() {
cout<<"Enter the size of Array";
int size;
cin>>size;
int array[size],key,i;
for(int j=0;j<size; j++) {
cout<<"Enter"<<j<<"Element";
cin>>array[j];
}
for(int a=0;a<size;a++) {
cout<<"Array["<<a<<"]=";
cout<<array[a]<<endl;
}
cout<<"Enter key to search in Array";
cin>>key;
for(i=0;i<size;i++){
if(key==array[i]){
cout<<"key found at index number:"<<i<<endl;
break;
}
}
LAB MANUAL Data Structures and Algorithms

}
}
if(i!=size){
cout<<"Key found at index:"<<i;
}
else {
cout<<"key not found";
}
return 0;
}

Output

Observations:
In this lab, we gained knowledge about executing a linear search with the assistance of a function,
and we also acquired insights into performing a binary search using a function within the Dev C++
environment.
LAB MANUAL Data Structures and Algorithms

Rubrics:
Absent Student is Student can Student has Student has Student
unable to understand followed constructed perfectly
follow the the provided instructions the implemented a
provided laboratory to construct functional/ working
instructions instructions the working model/ logic/
properly. and familiar fundamental schematic/ circuit/ block
The student with the lab schematic/ model/ block diagram/ code
can name the environment block diagram/ and
Demonstration hardware or (Trainer/ diagram/ code, and successfully
simulation software/ code/ model have executed the
platform, but IDE), but on the successfully lab objective in
unable to cannot protoboard/ executed the Realtime or in
implement implement on trainer/ program/ run a simulation
anything the platform simulation circuit on environment
practically or practically or software. software and produced
on the software on the platform the desired
software results
Category Ungraded Very Poor Poor Fair Good Excellent
Percentage [0] [1-20] [21-40] [41-60] [61-80] [81-100]
Marks 0.0 0.1 0.2 0.3 0.4 0.5

Date Total Marks Instructor’s Signature

Report not Plagiarized Requirements Observations Appropriate Correctly


submitted content are listed and are recorded computations drawn
presented or experimental along with or numerical conclusion
Laboratory incomplete procedure is detailed analysis is with
Reports submission presented procedure performed exact results
and complete
report in all
respects
Category Ungraded Very Poor Poor Fair Good Excellent
Percentage [0] [1-20] [21-40] [41-60] [61-80] [81-100]
Marks 0.0 0.1 0.2 0.3 0.4 0.5
Date Total Marks Instructor’s Signature

You might also like