Algorithms-Fall-24-Mid
Algorithms-Fall-24-Mid
int count = 0;
for (int i = N; i>0; i-2)
for (int j = 0; j<i;jtt)
count+ t;
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:
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