DSA Lab 3
DSA Lab 3
Submitted by
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
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]
Pseudo-code:
function linear_search (list, value)
for each item in the list
if match item == value
LAB MANUAL Data Structures and Algorithms
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
}
}
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