0% found this document useful (0 votes)
40 views1 page

DSA-Assignment-1-Spring-2021-22032021-122403pm 1

1) The document is an assignment from Bahria University for a Data Structures and Algorithms course asking students to describe an algorithm to find the location of the second largest element in an array. 2) The solution initializes two variables, first and second, to the minimum integer value to track the first and second largest elements. 3) It then traverses the array, updating first and second if the current element is greater than first or between first and second. 4) After traversing the array, second will contain the location of the second largest element.

Uploaded by

Shwifty
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)
40 views1 page

DSA-Assignment-1-Spring-2021-22032021-122403pm 1

1) The document is an assignment from Bahria University for a Data Structures and Algorithms course asking students to describe an algorithm to find the location of the second largest element in an array. 2) The solution initializes two variables, first and second, to the minimum integer value to track the first and second largest elements. 3) It then traverses the array, updating first and second if the current element is greater than first or between first and second. 4) After traversing the array, second will contain the location of the second largest element.

Uploaded by

Shwifty
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/ 1

BAHRIA UNIVERSITY, (Karachi

Campus)
Department of Computer Engineering
Assignment 1 – Spring 2021

COURSE TITLE: Data Structures And Algorithms


COURSE CODE: CSC-221
CLO 1: [Knowledge] PLO 1:[Engineering Knowledge]
Class: BCE-4(A) Shift: Morning
Course Instructor: Engr. Naveera Sami Time Allowed: 28th Mar 2021
Max. Marks: 05 Marks
Q1. Describe a Procedure (Algorithm) FIND (DATA,N,LOC1,LOC2) which finds the location
LOC2 of the second largest element in an array DATA with n>1 elements.

SOLUTION:

1) Initialize two variables first and second to INT_MIN as first = second = INT_MIN

2) Start traversing the array,


A. If the current element in array says arr[i] is greater than first. Then update first
and second as, second = first first = arr[i]
B. If the current element is in between first and second, then update second to
store the value of current variable as second = arr[i]
3) Return the value stored in second.

You might also like