FDS Paper Solution
FDS Paper Solution
Tips –
- Practice all above question as it is asked in each example for 9 marks.
- While writing answers read question carefully & write according to it.
Example:
According to the algorithm following is the example of sorting the
elements using Fibonacci Search.
Example
As mentioned earlier the necessity of this method is that all the elements
should be sorted. So let us take an array of sorted elements.
Time Complexity:
- The time complexity of this algorithm is O(1).
For example -
• Note that the sorted index table is maintained. First we search the index
table and then with the help of an index, actual array is searched for the
element.
--------------------------------------------------------------------------------
5) Sentinel Search
- Sentinel search is an optimization over linear search.
- The sentinel value is a specialized value that acts as a flag or dummy
data. This specialized value is used in context of an algorithm which uses
its presence as a condition of termination.
2. Second step:
o low = 6, high = 10
3. Third step:
o low = 9, high = 10
o mid = (9 + 10) // 2 = 9, so A[9] = 95
o Since 95 < 100, update low = mid + 1 = 10
4. Fourth step:
o low = 10, high = 10
o mid = (10 + 10) // 2 = 10, so A[10] = 100
o Key found at index 10
--------------------------------------------------------------------------
Note
a. You can write another pseudocode too
b. Execution of Binary Search on the Given Array can be written in another
ways mentioned in Q.2.
c. Check Details and do practice- Following is the Practice Example
A[0] to A[10] : 9, 17, 23,38,45,50,57,76,90,100 to search numbers 10 & 100.
Algorithm
The quick sort algorithm is performed using following two important functions
Quick and partition.
Quick (A [0...n-1],low,high)
//Problem Description: This algorithm performs sorting of
//the elements given in Array A [0...n-1]
//Input: An array A[0...n-1] in which unsorted elements are given.
-- //The low indicates the leftmost element in the list
//and high indicates the rightmost element in the list
//Output: Creates a sub array which is sorted in ascending order
if(low<high)then
//split the array into two sub arrays
m -- partition(A[low...high])// m is mid of the array
Quick (A[low...m-1])
Quick (A[mid+1...high])
Example:
Consider 25, 57, 48, 37, 12, 92, 86, 33 Sort stepwise using radix sort.
Example:
A [ 30, 70, 20, 50, 40, 10, 60 ]
Pass 1
Compare 10 and 5: Swap → 5,10,4,18,17,1,2
Compare 10 and 4: Swap → 5,4,10,18,17,1,2
Compare 10 and 18: No Swap → 5,4,10,18,17,1,2
Compare 18 and 17: Swap → 5,4,10,17,18,1,2
Compare 18 and 1: Swap → 5,4,10,17,1,18,2
Compare 18 and 2: Swap → 5,4,10,17,1,2,18
End of Pass 1: 5, 4, 10, 17, 1, 2, 18
Pass 2:
Compare 5 and 4: Swap → 4,5,10,17,1,2,18
Compare 5 and 10: No Swap → 4,5,10,17,1,2,18
Compare 10 and 17: No Swap → 4,5,10,17,1,2,18
Compare 17 and 1: Swap → 4,5,10,1,17,2,18
Compare 17 and 2: Swap → 4,5,10,1,2,17,18
Compare 17 and 18: No Swap → 4,5,10,1,2,17,18
End of Pass 2: 4,5,10,1,2,17,18
Pass 3:
Compare 4 and 5: No Swap → 4,5,10,1,2,17,18
Compare 5 and 10: No Swap → 4,5,10,1,2,17,18
Compare 10 and 1: Swap → 4,5,1,10,2,17,18
Compare 10 and 2: Swap → 4,5,1,2,10,17,18
Compare 10 and 17: No Swap → 4,5,1,2,10,17,18
Compare 17 and 18: No Swap → 4,5,1,2,10,17,18
End of Pass 3: 4,5,1,2,10,17,18
Pass 5:
Compare 4 and 1: Swap → 1,4,2,5,10,17,18
Compare 4 and 2: Swap → 1,2,4,5,10,17,18
Compare 4 and 5: No Swap → 1,2,4,5,10,17,18
Compare 5 and 10: No Swap → 1,2,4,5,10,17,18
Compare 10 and 17: No Swap → 1,2,4,5,10,17,18
Compare 17 and 18: No Swap → 1,2,4,5,10,17,18
End of Pass 5: 1,2,4,5,10,17,18
Pass 6:
Compare 1 and 2: No Swap → 1,2,4,5,10,17,18
Compare 2 and 4: No Swap → 1,2,4,5,10,17,18
Compare 4 and 5: No Swap → 1,2,4,5,10,17,18
Compare 5 and 10: No Swap → 1,2,4,5,10,17,18
Compare 10 and 17: No Swap → 1,2,4,5,10,17,18
Compare 17 and 18: No Swap → 1,2,4,5,10,17,18
End of Pass 6: 1,2,4,5,10,17,18
Time Complexity:
• Best Case: O(n)
Step 2: Sort the elements according to second last digits and sort them.
Second Last digit Elements
0 06
1
2 25
3
4 40,45
5 50
6 60
7
8
9
Sorted Elements after Step 2: 06, 25, 40, 45, 50, 60
Time Complexity:
• Best Case: O(nlogn)
• Average Case: O(nlogn)
• Worst Case: O(nlogn)
Practice question: 29, 57, 47, 39, 36, 20, 55, 28, 31, 39
*Note: This question can be asked for 9 marks as it is asked in nov_dec-2023 exam so all steps
may mandatory for 9 marks.
▪ Instruction
1. All Unit Wise Solution available on telegram channel
2. For the Customized Micro PDFs Solution of All Paper contact us on telegram.
3. Notes – Handwritten Notes / Textbook notes available
4. Join the telegram channel to get access to all.
5. Feel free to message us on Each single doubt, we will definitely help you regarding.….!!
---------------------------------------------------------------------------------------------------------------------------------
• Upto 9 CGPA