0% found this document useful (0 votes)
8 views5 pages

DSA Assignment 01

xyz

Uploaded by

hassanasif1210
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)
8 views5 pages

DSA Assignment 01

xyz

Uploaded by

hassanasif1210
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

Muhammad Hassan Asif 24-SE-86

SE-204: Data Structures and Algorithms


Assignment

Submitted to : Dr. Mahia Liaqat


Submitted by: Muhammad Hassan Asif
Reg no: 24-SE-86
Date of Submission: Oct 4, 2025
Muhammad Hassan Asif 24-SE-86

Q1. Design Binary Search algorithm for:


• Arrays with unique elements
• Arrays with repeating elements

Algorithms

• Arrays with unique elements:-

2 3 5 7 9 11 15

lb ub

• Input:
• An array Data of size n sorted in ascending order.
• Variables: lb (lower bound index), ub (upper bound index), item (element to
search).

• Output:
• "Underflow" if array is empty (ub = -1).
• "Item found at location i" if present.
• "Item not found" otherwise.

• Basic Idea:
1. If ub = -1, then print "Underflow" and return.
2. Repeat steps 3–5 while lb ≤ub.
3. Calculate mid:
𝑙𝑏 + 𝑢𝑏
𝑚𝑖𝑑 =
2

4. If item = Data[mid], 𝑡ℎ𝑒𝑛 print "Item found at location mid" and return.
5. Else if item < Data[mid], set ub = mid - 1.
Else set lb = mid + 1.
6. Print "Item not found" and return
Muhammad Hassan Asif 24-SE-86

• Arrays with repeating elements:-

2 3 4 5 5 6 7

lb repeating ub

• Input:
• A sorted array Data of size n.

• Variables: lb (lower bound index), ub (upper bound index), item.

• Output:
• "Underflow" if array is empty (ub = -1).
• Index of first occurrence of item if present.

• "Item not found" otherwise.

• Basic Idea:
1. If ub = -1, then print "Underflow" and return.

2. Set result = -1. (to store first occurrence index)

3. Repeat steps 4–6 while lb ≤ ub.

4. Calculate mid :
𝑙𝑏 + 𝑢𝑏
𝑚𝑖𝑑 =
2
5. If item = Data[mid]:

o Set result = mid.

o Set ub = mid - 1 (keep searching left part for earlier occurrence).

6. Else if item < Data[mid], set ub = mid - 1.


Else set lb = mid + 1.

7. If result ≠ -1, print "Item found at location result".


Else print "Item not found".
Muhammad Hassan Asif 24-SE-86

Q2. Explore at least two real-life applications of arrays and search


algorithms (linear or binary) in Pakistani systems.

Arrays and search algorithms are integral to the functioning of various systems
in Pakistan, particularly in government services and banking. Below are two
real-life applications illustrating their use:

(1)

NADRA's CNIC Verification System


• Organization: National Database & Registration Authority (NADRA)
• Data Searched: Computerized National Identity Card (CNIC) numbers
• Search Algorithm: While specific algorithms are not publicly disclosed,
the system likely employs efficient search techniques such as binary
search or hash-based indexing to quickly retrieve CNIC details from a
vast database.
• Benefits:
• Efficiency: Rapid verification of identity for services like passport
issuance, voter registration, and financial transactions.
• Security: Ensures that only authorized individuals can access or
update personal information.
• Accessibility: Enables citizens to verify their CNIC status online,
reducing the need for physical visits to NADRA offices.
• Example: Citizens can check their CNIC details through NADRA's
official portal or by sending an SMS to 7000. Zameen
Muhammad Hassan Asif 24-SE-86

Banking Sector's Customer Data Management


• Organizations: Various commercial banks in Pakistan, such as Habib
Bank Limited (HBL), Faysal Bank, and Bank Alfalah.
• Data Searched: Customer account numbers, transaction records, and
loan information.
• Search Algorithm: Banks utilize advanced data structures and
algorithms, including hash tables and binary trees, to manage and retrieve
customer data efficiently.
• Benefits:
o Fraud Detection: Real-time monitoring of transactions to identify
and prevent fraudulent activities.
o Customer Service: Quick retrieval of customer information to
provide timely assistance.
o Regulatory Compliance: Ensures adherence to financial
regulations by maintaining accurate and accessible records.
• Technological Integration: The adoption of AI and machine learning
models further enhances the ability to detect anomalies and predict
potential risks.

You might also like