Skip to content

Commit cea5875

Browse files
committed
feat:<Linear Search> linear search add
1 parent 7288bc9 commit cea5875

File tree

3 files changed

+96
-12
lines changed

3 files changed

+96
-12
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">Linear Search Algorithm</h1>
2+
<div class="mt-md-4 mt-3" [innerHtml]="linearSearchMetaData.defination"></div>
3+
<div class="mt-md-4 mt-3" [innerHtml]="linearSearchMetaData.explainImage"></div>
4+
<div class="mt-md-4 mt-3" [innerHtml]="linearSearchMetaData.properties"></div>
5+
<div class="mt-md-4 mt-3" [innerHtml]="linearSearchMetaData.flowChart"></div>
6+
<div class="mt-md-4 mt-3" [innerHtml]="linearSearchMetaData.workingProcedure"></div>
7+
<div class="mt-md-4 mt-3" [innerHtml]="linearSearchMetaData.applications"></div>
8+
<div class="mt-md-4 mt-3" [innerHtml]="linearSearchMetaData.other"></div>
9+
<div class="mt-md-4 mt-3" [innerHtml]="linearSearchMetaData.advantage"></div>
10+
<div class="mt-md-4 mt-3" [innerHtml]="linearSearchMetaData.disadvantage"></div>

src/app/components/Algorithms/searching/linear-search/linear-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 { linearSearchMetaData } from 'src/app/core/algorithms/searching-meta-data';
23

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

1213
ngOnInit(): void {
Lines changed: 84 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,88 @@
1-
import { Helper } from "src/app/helper/helper"
1+
import { Helper } from 'src/app/helper/helper';
2+
import { Algorithms } from 'src/app/shared/interfaces/algorithms.interface';
23

34
const searchingData = {
4-
defination: "The searching algorithms are used to search or find one or more than one element from a dataset. These type of algorithms are used to find elements from a specific data structures.<br> Searching may be sequential or not. If the data in the dataset are random, then we need to use sequential searching. Otherwise we can use other different techniques to reduce the complexity.<br> Search algorithms can be classified based on their mechanism of searching into three types of algorithms: linear, binary, and hashing",
5-
terminologies: [
6-
"<b>Sequential Search</b>: In this, the list or array is traversed sequentially and every element is checked. For example: Linear Search",
7-
"<b>Interval Search</b>: These algorithms are specifically designed for searching in sorted data-structures. These type of searching algorithms are much more efficient than Linear Search as they repeatedly target the center of the search structure and divide the search space in half. For Example: Binary Search",
8-
]
9-
}
5+
defination: `The searching algorithms are used to search or find one or more than one element from a dataset.
6+
These type of algorithms are used to find elements from a specific data structures.<br> Searching may be
7+
sequential or not. If the data in the dataset are random, then we need to use sequential searching.
8+
Otherwise we can use other different techniques to reduce the complexity.<br> Search algorithms can
9+
be classified based on their mechanism of searching into three types of algorithms: linear, binary, and hashing`,
10+
terminologies: [
11+
`<b>Sequential Search</b>: In this, the list or array is traversed sequentially and every
12+
element is checked. For example: Linear Search`,
13+
`<b>Interval Search</b>: These algorithms are specifically designed for searching in sorted
14+
data-structures. These type of searching algorithms are much more efficient than Linear Search
15+
as they repeatedly target the center of the search structure and divide the search space in half.
16+
For Example: Binary Search`,
17+
],
18+
};
1019

1120
export const searchingMetaData = {
12-
defination: Helper.setHeader(searchingData.defination),
13-
terminologies: Helper.setListwithTitleHtml('Types of Searchs', searchingData.terminologies),
14-
}
21+
defination: Helper.setHeader(searchingData.defination),
22+
terminologies: Helper.setListwithTitleHtml(
23+
'Types of Searchs',
24+
searchingData.terminologies
25+
),
26+
};
27+
28+
// ------------------------------- Linear Search Algorithm ---------------------------------//
29+
30+
const linearSearchData = {
31+
defination: `Linear Search is defined as a sequential search algorithm that starts at one end and goes through each
32+
element of a list until the desired element is found, otherwise the search continues till the end of the data set.
33+
It is the easiest searching algorithm`,
34+
flowChart: 'assets/ds-image/DSA-404.webp',
35+
explainImage: 'assets/ds-image/DSA-404.webp',
36+
workingProcedure: [
37+
`Start from the leftmost element of arr and one by one compare 'x' with each element of arr`,
38+
`If 'x' matches with an element, return the index`,
39+
`If 'x' doesn’t match with any of the elements, return -1`
40+
],
41+
properties: [
42+
'It can be implemented on both a single and multidimensional array',
43+
'It is preferrable for the small-sized data sets',
44+
'The linear search can be implemented on any linear data structure such as an array, linked list, etc',
45+
`In a linear search, the elements don't need to be arranged in sorted order`
46+
],
47+
advantages: [
48+
`Will perform fast searches of small to medium lists. With today's powerful computers,
49+
small to medium arrays can be searched relatively quickly`,
50+
`The list does not need to sorted. Unlike a binary search, linear searching does not require an ordered list`,
51+
`Not affected by insertions and deletions. As the linear search does not require the list to be sorted,
52+
additional elements can be added and deleted. As other searching algorithms may have to reorder the list
53+
after insertions or deletions, this may sometimes mean a linear search will be more efficient`
54+
],
55+
disadvantages: [
56+
`Slow searching of large lists. For example, when searching through a database of everyone in the
57+
Northern Ireland to find a particular name, it might be necessary to search through 1.8 million names
58+
before you found the one you wanted. This speed disadvantage is why other search methods have been developed`
59+
],
60+
applications: [
61+
`Linear search can be applied to both single-dimensional and multi-dimensional arrays`,
62+
`Linear search is easy to implement and effective when the array contains only a few elements`,
63+
`Linear Search is also efficient when the search is performed to fetch a single search in an unordered-List`
64+
],
65+
performance: [
66+
`<b>Best Case Complexity</b> - In Linear search, best case occurs when the element we are finding is at the first position of
67+
the array. The best-case time complexity of linear search is O(1)`,
68+
`<b>Average Case Complexity</b> - The average case time complexity of linear search is O(n)`,
69+
`<b>Worst Case Complexity</b> - In Linear search, the worst case occurs when the element we are looking is present
70+
at the end of the array. The worst-case in linear search could be when the target element is not present in the given
71+
array, and we have to traverse the entire array. The worst-case time complexity of linear search is O(n)`,
72+
`<b>Space Complexity</b> - The space complexity of linear search is O(1)`
73+
],
74+
};
75+
76+
export const linearSearchMetaData: Algorithms = {
77+
defination: Helper.setHeader(linearSearchData.defination),
78+
properties: Helper.setListwithTitleHtml('Properties of Linear Search', linearSearchData.properties),
79+
explainImage: Helper.setExampleImage('Linear Search Image', linearSearchData.explainImage),
80+
flowChart: Helper.setExampleImage('Flowchart of Linear Search', linearSearchData.flowChart),
81+
advantage: Helper.setListwithTitleHtml('Advantages of Linear Search', linearSearchData.advantages),
82+
disadvantage: Helper.setListwithTitleHtml('Disadvantages of Linear Search', linearSearchData.disadvantages),
83+
applications: Helper.setListwithTitleHtml('Applications of Linear Search', linearSearchData.applications),
84+
other: Helper.setListwithTitleHtml('Performance of Linear Search', linearSearchData.performance),
85+
workingProcedure: Helper.setListwithTitleHtml('Follow the below steps to solve the problem', linearSearchData.workingProcedure),
86+
}
87+
88+
// ----------------------------------- End ----------------------------------------------//

0 commit comments

Comments
 (0)