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

DAA Questions For Fast Learners

Uploaded by

jiya.mittal.aqua
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)
19 views

DAA Questions For Fast Learners

Uploaded by

jiya.mittal.aqua
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/ 3

Assignment for Fast learner based on MST-1

Subject – Design and Analysis of algorithms


Subject Code- 22CSH-311/22ITH-311

Questions for Fast Leaner’s

Q1. Find the recurrence relation for below code and also find the time complexity using
substitution method.

func Find(a []int, x int) int {


switch len(a) {
case 0:
return 0
case 1:
if x <= a[0] {
return 0
}
return 1
}
mid := 1 + (len(a)-1)/2
if x <= a[mid-1] {
return Find(a[:mid], x)
}
return mid + Find(a[mid:], x)
}

Q2. Find the recurrence relation for below code and also find the time complexity using
recursive tree method.

Merge(ary)
{
ary_start = Merge(ary[0:n/2]);
ary_end = Merge(ary[n/2:n]);
return MergeArrays(ary_start, ary_end);
}

Q3. As the head librarian, you are tasked with organizing a newly acquired collection of
books in your library. Each book is assigned a unique accession number. To streamline
the process and ensure easy access to the books, you opt to utilize a balanced tree. A
balanced tree will serve as the structure for cataloging the books, with each node
representing a book, and the tree maintaining its balance to facilitate efficient searches.
To achieve this, your goal is to construct a balanced tree for the library catalog,
systematically inserting the books based on their respective accession numbers. The
sequence of books received for insertion is as follows: 21, 26, 30, 9, 4, 14, 28, 18, 15, 10,
2, 3, and 7. As you insert each book, it's crucial to ensure the tree's balance is maintained
according to the AVL property. Perform any necessary rotations at each step to uphold
this equilibrium.
Q4. You are the head nurse in a busy hospital emergency room. You need to implement a
priority queue to manage patients based on the severity of their conditions. Explain how
you would use a max-heap or min-heap to maintain the queue, ensuring that patients with
the most critical conditions receive immediate attention.
Q5. Design an algorithm to balance an unbalanced binary search tree efficiently. The
input is an unbalanced binary search tree with N nodes, where the height of the tree is
significantly greater than log N. Your task is to create a balanced binary search tree
without modifying the structure of the original tree. The balanced tree should have the
same elements in the same order as the original tree. The algorithm should have a time
complexity of O(N) and should be able to handle large trees efficiently.
Q6. You are designing a phone book application that uses a binary search tree to store
contact information. Each node in the tree contains a contact's name and phone number.
A user wants to look up a contact by name. Describe how you would use the properties of
the BST to efficiently locate the contact based on their name and retrieve their phone
number.
Q7. Assume you are the manager of a small parking lot with ten parking spaces. You
have a group of cars arriving with unique license plate numbers. To efficiently allocate
parking spaces, you decide to use a hash table with open addressing and a hash function
`h(k) = k mod 10` to map the cars to specific parking spaces. Initially, the parking lot is
empty. Here are the license plate numbers of the cars:
- Car 1: License plate number 12
- Car 2: License plate number 18
- Car 3: License plate number 13
- Car 4: License plate number 2
- Car 5: License plate number 3
- Car 6: License plate number 23
- Car 7: License plate number 5
- Car 8: License plate number 15
Using linear probing to handle parking space collisions, you need to assign these cars to
parking spaces based on their license plate numbers. What will the final allocation of
parking spaces look like in the parking lot, and which cars are parked in which spaces?
Q8. Given a list of integers representing the exam scores of 200 students, where each
integer is in the range [0, 100], sort the list in ascending order using counting sort.
Q9. Imagine you are a teacher, and you have a class of 10 students. Each student has a
score representing their performance, and you want to rank them from the highest score
to the lowest score using the Bubble Sort algorithm. The scores of the students are stored
in a list. How would you use Bubble Sort to accomplish this task?
Input:
- Number of students (N) = 10
- List of student scores (arr) = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
Q10. Imagine you are a librarian at a library, and you have a collection of books. Each
book is identified by a unique three-digit call number, and you want to arrange the books
in numerical order based on their call numbers using the Radix Sort algorithm. The books
are currently in a disordered stack, and you need to organize them on the shelves. Here
are the call numbers of the books:
{455, 61, 63, 45, 67, 135, 74, 49, 15, 5}
How would you use the Radix Sort algorithm to sort the books based on their call
numbers and place them on the library shelves in ascending order?

You might also like