0% found this document useful (0 votes)
14 views4 pages

DAA Lab

Uploaded by

Vansh Aggarwal
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)
14 views4 pages

DAA Lab

Uploaded by

Vansh Aggarwal
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/ 4

DESIGN AND ANALYSIS OF ALGORITHMS

LABORATORY
PRACTICAL FILE
(LPCCS-108)

SUBMITTED IN PARTIAL FULFILMENT OF THE REQUIREMENTS FOR THE


AWARD OF THE DEGREE OF

BACHELOR OF TECHNOLOGY

(Computer Science and Engineering)

Submitted by: Submitted to:

Vansh Aggarwal Prof. Harkomalpreet Kaur

D3 CSE C-1

CRN: 2215184

URN: 2203575

Department of Computer Science and Engineering

Guru Nanak Dev Engineering College

Ludhiana,141006
INDEX
S.No. Date Name of the Practical Page Remarks
No.
PRACTICAL-1

Title : Write a program to find out a roll number from college database using
binary search algorithm.
Code:
#include <iostream>
using namespace std;
int binarySearch(int arr[], int size, int rollNumber) {
int left = 0, right = size - 1;
while (left <= right) {
int mid = left + (right - left) / 2;
if (arr[mid] == rollNumber)
return mid;
if (arr[mid] < rollNumber)
left = mid + 1;
else
right = mid - 1;
}
return -1;
}
int main() {
int n;
cout<<"Name: Vansh Aggarwal"<<endl;
cout<<"Class:
= D-3 CSE C-1"<<endl;
cout<<"CRN:
= 2215184"<<endl;
cout<<"URN:
= 2203575"<<endl;
cout <<"Enter the number of roll numbers: ";
cin >> n;
int* arr = new int[n];
cout <<"Enter the roll numbers in ascending order:\n";
for (int i = 0; i < n; ++i) {
cout << "Roll number " << i + 1 << ": ";
cin >> arr[i];
}
int rollNumber;
cout <<"Enter roll number to search: ";
cin >> rollNumber;
int result = binarySearch(arr, n, rollNumber);
if (result != -1) {
cout <<"Roll number " << rollNumber << " found at index " << result << "." << endl;
} else {
cout <<"Roll number " << rollNumber << " not found in the database." << endl;
}
delete[] arr;
return 0;
}

Output:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy