Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 11 additions & 44 deletions docs/dsa/algorithms/searching_algorithm.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,9 @@ title: Searching in Data Structures and Algorithms
sidebar_label: Searching Algorithm
sidebar_position: 1
description: ""
tags:
[dsa,data-algorithms , searching
]
tags: [dsa, data-algorithms, searching]
---




Searching is a fundamental operation in computer science and is widely used in various applications. In the context of Data Structures and Algorithms (DSA), searching refers to the process of finding a specific element within a collection of data.

![alt text](image.png)
Expand All @@ -20,6 +15,10 @@ Searching is a fundamental operation in computer science and is widely used in v

Linear search is a simple algorithm that sequentially checks each element in a collection until the target element is found or the end of the collection is reached. It is commonly used for small collections or unsorted data.

<LinearSearchVisualizer />

<br />

```python
def linear_search(arr, target):
for i in range(len(arr)):
Expand Down Expand Up @@ -69,8 +68,8 @@ Remember to provide appropriate input and handle edge cases when implementing th
## Additional Questions

1. **Question:** Implement a linear search algorithm in C++ to find the index of a target element in an array. Provide the input and output for the following scenario:
- **Input:** Array: [5, 2, 9, 7, 3], Target: 9
- **Output:** Index: 2
- **Input:** Array: [5, 2, 9, 7, 3], Target: 9
- **Output:** Index: 2

```cpp
#include <iostream>
Expand All @@ -96,8 +95,8 @@ int main() {
```

2. **Question:** Write a binary search algorithm in Java to find the index of a target element in a sorted array. Provide the input and output for the following scenario:
- **Input:** Array: [1, 3, 5, 7, 9], Target: 5
- **Output:** Index: 2
- **Input:** Array: [1, 3, 5, 7, 9], Target: 5
- **Output:** Index: 2

```java
public class BinarySearch {
Expand Down Expand Up @@ -127,8 +126,8 @@ public class BinarySearch {
```

3. **Question:** Implement a hash-based search algorithm in Python to retrieve the value associated with a given key in a dictionary. Provide the input and output for the following scenario:
- **Input:** Dictionary: ```{"apple": 1, "banana": 2, "orange": 3}```, Key: "banana"
- **Output:** Value: 2
- **Input:** Dictionary: `{"apple": 1, "banana": 2, "orange": 3}`, Key: "banana"
- **Output:** Value: 2

```python
hash_map = {
Expand All @@ -144,7 +143,6 @@ print("Value:", value)

Remember to provide appropriate input and handle edge cases when implementing these algorithms to ensure correct results.


In conclusion, searching is a fundamental operation in computer science and is widely used in various applications. In the context of Data Structures and Algorithms (DSA), there are several types of searching algorithms, including linear search, binary search, and hash-based search. Each algorithm has its own characteristics and is suitable for different scenarios.

Linear search is a simple algorithm that sequentially checks each element in a collection until the target element is found or the end of the collection is reached. It is commonly used for small collections or unsorted data.
Expand All @@ -157,37 +155,6 @@ When implementing these algorithms, it is important to provide appropriate input

Overall, understanding and implementing different searching algorithms is crucial for efficient data retrieval and manipulation in various programming scenarios.
































Searching is a fundamental operation in computer science and is widely used in various applications. In the context of Data Structures and Algorithms (DSA), searching refers to the process of finding a specific element within a collection of data.

There are several types of searching algorithms commonly used in DSA, including linear search, binary search, hash-based search, and tree-based search. Each algorithm has its own characteristics and is suitable for different scenarios.
Expand Down
5 changes: 2 additions & 3 deletions src/components/Lesson/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,19 @@ interface LessonProps {

/**
* Lesson component displays a single lesson with its title, description, and tags.
* @param id - Unique identifier for the lesson.
* @param title - Title of the lesson.
* @param tags - Array of tags associated with the lesson.
* @param description - Description or content of the lesson.
* @returns JSX element representing the lesson.
*/
const Lesson: React.FC<LessonProps> = ({ id, title, tags, description }) => {
const Lesson: React.FC<LessonProps> = ({ title, tags, description }) => {
return (
<div className="lesson"> {/* Container for the lesson */}
<h2 className="lesson-title">{title}</h2> {/* Title of the lesson */}
<p className="lesson-description">{description}</p> {/* Description or content of the lesson */}
<div className="lesson-tags"> {/* Container for tags */}
{tags.map((tag, index) => (
<span key={index} className="lesson-tag">{tag}</span>
<span key={index} className="lesson-tag">{tag}</span>
))
}
</div>
Expand Down
13 changes: 11 additions & 2 deletions src/dsa/searching-algorithms/LinearSearchVisualizer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,15 @@ const LinearSearchVisualizer: React.FC = () => {
setSearching(false);
};

const shuffleArray = () => {
const shuffledArray = [...array].sort(() => Math.random() - 0.5);
setArray(shuffledArray);
resetVisualization();
};

return (
<div className="linear-search-container">
<Heading as="h2">Linear Search Visualization</Heading>
<Heading as="h2">Linear Search Visualization</Heading>
<div className="array-container">
{array.map((num, index) => (
<div
Expand All @@ -71,9 +77,12 @@ const LinearSearchVisualizer: React.FC = () => {
<button onClick={resetVisualization} disabled={!searching && !target}>
Reset
</button>
<button onClick={shuffleArray} disabled={searching}>
Shuffle Array
</button>
</div>
</div>
);
};

export default LinearSearchVisualizer;
export default LinearSearchVisualizer;
4 changes: 2 additions & 2 deletions src/pages/about/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
import React from "react";
import Head from "@docusaurus/Head";

export default function About() {
export default function About(): React.JSX.Element {
const { siteConfig } = useDocusaurusContext();
return (
<Layout
Expand All @@ -23,7 +23,7 @@ export default function About() {
src="https://cdn.ampproject.org/v0/amp-auto-ads-0.1.js"
/>
<meta name="google-adsense-account" content="ca-pub-5832817025080991" />
</Head>
</Head>
<AboutUsSection />
</Layout>
);
Expand Down
10 changes: 1 addition & 9 deletions src/pages/blogs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,7 @@ import Link from "@docusaurus/Link";
import blogs from "../../database/blogs";
import Head from "@docusaurus/Head";

// interface Blog {
// id: number;
// title: string;
// image: string;
// description: string;
// slug: string;
// }

export default function Blogs() {
export default function Blogs(): React.JSX.Element {
const { siteConfig } = useDocusaurusContext();

return (
Expand Down
Loading