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

Algorithms-Fall-24-Mid

This document is a midterm examination paper for the Algorithms course at Daffodil International University, covering various topics including code complexity, binary search, quicksort, Huffman coding, and a knapsack problem scenario. Students are required to answer all questions, which involve algorithm analysis, sorting methods, and optimization strategies. The exam consists of multiple questions with specific marks allocated to each, totaling 25 marks.

Uploaded by

6yzdahmed
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)
13 views

Algorithms-Fall-24-Mid

This document is a midterm examination paper for the Algorithms course at Daffodil International University, covering various topics including code complexity, binary search, quicksort, Huffman coding, and a knapsack problem scenario. Students are required to answer all questions, which involve algorithm analysis, sorting methods, and optimization strategies. The exam consists of multiple questions with specific marks allocated to each, totaling 25 marks.

Uploaded by

6yzdahmed
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/ 2

For more questions: https://diuqbank.

com | Uploader: SUPAN ROY

Daffodil International University


Faculty of Science & Information Technology
Departmentof ComputerScience and Engineering
Midterm Examination, Fall 2024
Course Code: CSE213, Course Title: Algorithms
Level: 2 Term: 1 Batch: 65
Time: 01:30 Hours Marks: 25

Answer ALL Questions


The figuresin the right margin indicatethefull marks and correspondingcourse
outcomes.All portionsof each question must be answeredsequentially]
1. a) Discuss the complexity of the following code snippct: [CO1]
int main(){ (2.5]
int i,j,;
scanf("%d",&N);

int count = 0;
for (int i = N; i>0; i-2)
for (int j = 0; j<i;jtt)
count+ t;

b) Write an algorithm to swap two given numbers withoutusing a temporaryvariable. [2.5]


Explain the time complexityof your generatedalgorithm.

2. Describe the below inquiries in case of the binary search algorithm: [5] [CO1]
Outline the main steps involved in performingthe binary search algorithm.
What is the time complexityof binary search in the worst-casescenario?
III. Describe how the 'divide and conquer' approach applies to binary search.
V. If you have an ordered list containing128 elements,what is the maximum number
of steps nceded tofind aspecificclementusing binary search?
V. Can binary search be applied to an unorderedlist? Justifyyour answer.
3. Alex is organizing agaming tournamentand needs to sort the scores of theparticipantsto (5] [CO2]
Cxecute the final rankings.The scores are currentlyin random order:
[150, 92, 185, 120, 160]

Alex decides to use the quicksort algorithm to sort these scores in ascending order. He
chooses the first element as the pivot for simplicity and needs to sort the list step by step.
How can youhelp Alex to sort the scores?

4. Harun
Harun sent
and aBiplob are good friends. They usuallychat with cach other regularly. Once
greeting 'Hi Friend' to Biplob. Someone tried to snip that message but it was
(5] |CO2]
encrypted. However, Huffman coding was used for the encryption. Demonstrate the
encryptedcode for the transmittedmessage.
Page l of 2
For more questions: https://diuqbank.com | Uploader: SUPAN ROY

5 Sarah is a treasurehunter, and she has discoveredan ancientvault filled with preciousgems. (5] [CO3|
However, her backpackhas a weight limit of 30 kg, and she must choose wisely from the
following gems, each with a specificweight and estimatedmarket value:

Gem Weight (kg) Value (S)


Ruby 10 |60,000
Sapphire 15 90,000
Emerald 5 |50,000
Diamond 12 100,000

Sarah can take whole gems or fractions of them, as the gems can be cut without losing
value. How can she organizeher backpackto maximizethe total value of the gems she can
carry without exceedingthe 30 kg weight limit?

The End

You might also like