Skip to content

Commit 4f1ca30

Browse files
committed
feat:<Searching> jump search and interpolation add
1 parent e7b2f1e commit 4f1ca30

File tree

5 files changed

+138
-4
lines changed

5 files changed

+138
-4
lines changed
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,10 @@
1-
<h1 class="text-center">Coming soon</h1>
1+
<h1 class="text-center">Interpolation Search Algorithm</h1>
2+
<div class="mt-md-4 mt-3" [innerHtml]="interpolationSearchMetaData.defination"></div>
3+
<div class="mt-md-4 mt-3" [innerHtml]="interpolationSearchMetaData.explainImage"></div>
4+
<div class="mt-md-4 mt-3" [innerHtml]="interpolationSearchMetaData.properties"></div>
5+
<div class="mt-md-4 mt-3" [innerHtml]="interpolationSearchMetaData.flowChart"></div>
6+
<div class="mt-md-4 mt-3" [innerHtml]="interpolationSearchMetaData.workingProcedure"></div>
7+
<div class="mt-md-4 mt-3" [innerHtml]="interpolationSearchMetaData.applications"></div>
8+
<div class="mt-md-4 mt-3" [innerHtml]="interpolationSearchMetaData.other"></div>
9+
<div class="mt-md-4 mt-3" [innerHtml]="interpolationSearchMetaData.advantage"></div>
10+
<div class="mt-md-4 mt-3" [innerHtml]="interpolationSearchMetaData.disadvantage"></div>

src/app/components/Algorithms/searching/interpolation-search/interpolation-search.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { Component, OnInit } from '@angular/core';
2+
import { interpolationSearchMetaData } from 'src/app/core/algorithms/searching-meta-data';
23

34
@Component({
45
selector: 'app-interpolation-search',
56
templateUrl: './interpolation-search.component.html',
67
styleUrls: ['./interpolation-search.component.css']
78
})
89
export class InterpolationSearchComponent implements OnInit {
9-
10+
interpolationSearchMetaData = interpolationSearchMetaData;
1011
constructor() { }
1112

1213
ngOnInit(): void {
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,10 @@
1-
<h1 class="text-center">Coming soon</h1>
1+
<h1 class="text-center">Jump Search Algorithm</h1>
2+
<div class="mt-md-4 mt-3" [innerHtml]="jumpSearchMeatData.defination"></div>
3+
<div class="mt-md-4 mt-3" [innerHtml]="jumpSearchMeatData.explainImage"></div>
4+
<div class="mt-md-4 mt-3" [innerHtml]="jumpSearchMeatData.properties"></div>
5+
<div class="mt-md-4 mt-3" [innerHtml]="jumpSearchMeatData.flowChart"></div>
6+
<div class="mt-md-4 mt-3" [innerHtml]="jumpSearchMeatData.workingProcedure"></div>
7+
<div class="mt-md-4 mt-3" [innerHtml]="jumpSearchMeatData.applications"></div>
8+
<div class="mt-md-4 mt-3" [innerHtml]="jumpSearchMeatData.other"></div>
9+
<div class="mt-md-4 mt-3" [innerHtml]="jumpSearchMeatData.advantage"></div>
10+
<div class="mt-md-4 mt-3" [innerHtml]="jumpSearchMeatData.disadvantage"></div>

src/app/components/Algorithms/searching/jump-search/jump-search.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { Component, OnInit } from '@angular/core';
2+
import { jumpSearchMeatData } from 'src/app/core/algorithms/searching-meta-data';
23

34
@Component({
45
selector: 'app-jump-search',
56
templateUrl: './jump-search.component.html',
67
styleUrls: ['./jump-search.component.css']
78
})
89
export class JumpSearchComponent implements OnInit {
9-
10+
jumpSearchMeatData = jumpSearchMeatData;
1011
constructor() { }
1112

1213
ngOnInit(): void {

src/app/core/algorithms/searching-meta-data.ts

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,117 @@ export const binarySearchMetaData : Algorithms = {
151151
}
152152

153153
// ----------------------------------- End ----------------------------------------------//
154+
155+
// ----------------------------------- Jump Search ----------------------------------------------//
156+
157+
const jumpSearchData = {
158+
defination:`Jump Search is a searching algorithm for sorted arrays. The basic idea is to check fewer elements by
159+
jumping ahead by fixed steps or skipping some elements in place of searching all elements.`,
160+
flowChart: 'assets/ds-image/DSA-404.webp',
161+
explainImage: 'assets/ds-image/DSA-404.webp',
162+
properties:[
163+
`This algorithm works only for sorted input arrays`,
164+
`Optimal size of the block to be skipped is √n, thus resulting in the time complexity O(√n2)`,
165+
`The time complexity of this algorithm lies in between linear search (O(n)) and binary search (O(log n))`,
166+
`It is also called block search algorithm`,
167+
`If we compare it with linear and binary search then it comes out then it is better than linear search but
168+
not better than binary search`,
169+
`<b>linear search < jump search < binary search </b>`
170+
],
171+
workingProcedure:[
172+
`Start from index 0`,
173+
`Jump head by 'B'(B = √N) elements. Current position = Current position + B.
174+
If position is out of element list, set current position to last position`,
175+
`If element at current position < target element, then do Linear Search on element from position
176+
current position -B to current position else go to step 2.If current position is last position. Exit. Element not found`
177+
],
178+
applications:[
179+
`If jumping back in a list takes significantly more time than jumping forward then one should use this algorithm`
180+
],
181+
advantages: [
182+
`It is faster than the linear search technique which has a time complexity of O(n) for searching an element`
183+
],
184+
disadvantages: [
185+
`It is slower than binary search algorithm which searches an element in O(log n)`,
186+
`It requires the input array to be sorted`
187+
],
188+
performance: [
189+
`Worst case time complexity: O(√N)`,
190+
`Average case time complexity: O(√N)`,
191+
`Best case time complexity: O(1)`,
192+
`Space complexity: O(1)`
193+
],
194+
};
195+
196+
export const jumpSearchMeatData : Algorithms = {
197+
defination: Helper.setHeader(jumpSearchData.defination),
198+
properties: Helper.setListwithTitleHtml('Properties of Jump Search', jumpSearchData.properties),
199+
explainImage: Helper.setExampleImage('Jump Search Image', jumpSearchData.explainImage),
200+
flowChart: Helper.setExampleImage('Flowchart of Jump Search', jumpSearchData.flowChart),
201+
advantage: Helper.setListwithTitleHtml('Advantages of Jump Search', jumpSearchData.advantages),
202+
disadvantage: Helper.setListwithTitleHtml('Disadvantages of Jump Search', jumpSearchData.disadvantages),
203+
applications: Helper.setListwithTitleHtml('Applications of Jump Search', jumpSearchData.applications),
204+
other: Helper.setListwithTitleHtml('Performance of Jump Search', jumpSearchData.performance),
205+
workingProcedure: Helper.setListwithTitleHtml('Follow the below steps to solve the problem', jumpSearchData.workingProcedure),
206+
}
207+
208+
// ----------------------------------- End ----------------------------------------------//
209+
210+
// ----------------------------- Interpolation Search ------------------------------------//
211+
212+
const interpolationSearchData = {
213+
defination:`The Interpolation Search is an improvement over Binary Search for instances, where the values in a sorted
214+
array are uniformly distributed. Interpolation constructs new data points within the range of a discrete set of known
215+
data points. Binary Search always goes to the middle element to check. On the other hand, interpolation search may go to
216+
different locations according to the value of the key being searched. For example, if the value of the key is closer to the
217+
last element, interpolation search is likely to start search toward the end side.`,
218+
flowChart: 'assets/ds-image/DSA-404.webp',
219+
explainImage: 'assets/ds-image/DSA-404.webp',
220+
properties: [
221+
`Interpolation searching algorithm is only used when the elements in an array is sorted and uniformly distributed`,
222+
`pos = low + ((target – A[low]) * (high – low) / (A[high] – A[low]))`
223+
],
224+
workingProcedure: [
225+
`<b>pos = low + ((target – A[low]) * (high – low) / (A[high] – A[low]))</b>`,
226+
`In a loop, calculate the value of pos using the above formula`,
227+
`If it is a match, return the index of the item, and exit`,
228+
`If the item is less than the element at position pos, calculate the target position of the left sub-array.
229+
Otherwise calculate the same in the right sub-array`,
230+
`Repeat until a match is found or the search space reduces to zero`
231+
],
232+
applications: [
233+
`Since the major requirement to use Interpolation Search is that the data set must be sorted and uniformly distributed, it has a very
234+
limited number of applications in real life, where data is actually quite randomised`,
235+
`Interpolation Search Algorithm is a search algorithm that has been inspired by the way humans search through a telephone book for a particular name,
236+
the key value by which the book's entries are ordered`
237+
],
238+
advantages: [
239+
`When all elements in the list are sorted and evenly distributed, then executing time of
240+
Interpolation search algorithm is log(log n)`
241+
],
242+
disadvantages: [
243+
`However, When the elements in the list are increased exponentially, then executing time of Interpolation search algorithm is 0(n)`
244+
],
245+
performance: [
246+
`Worst case time complexity: O(N)`,
247+
`Average case time complexity: O(log log N)`,
248+
`Best case time complexity: O(1)`,
249+
`Space complexity: O(1)`
250+
]
251+
};
252+
253+
export const interpolationSearchMetaData : Algorithms = {
254+
defination: Helper.setHeader(interpolationSearchData.defination),
255+
properties: Helper.setListwithTitleHtml('Properties of Interpolation Search', interpolationSearchData.properties),
256+
explainImage: Helper.setExampleImage('Interpolation Search Image', interpolationSearchData.explainImage),
257+
flowChart: Helper.setExampleImage('Flowchart of Interpolation Search', interpolationSearchData.flowChart),
258+
advantage: Helper.setListwithTitleHtml('Advantages of Interpolation Search', interpolationSearchData.advantages),
259+
disadvantage: Helper.setListwithTitleHtml('Disadvantages of Interpolation Search', interpolationSearchData.disadvantages),
260+
applications: Helper.setListwithTitleHtml('Applications of Interpolation Search', interpolationSearchData.applications),
261+
other: Helper.setListwithTitleHtml('Performance of Interpolation Search', interpolationSearchData.performance),
262+
workingProcedure: Helper.setListwithTitleHtml('Follow the below steps to solve the problem', interpolationSearchData.workingProcedure),
263+
}
264+
265+
// ----------------------------------- End ----------------------------------------------//
266+
267+

0 commit comments

Comments
 (0)