diff --git a/docs/dsa/algorithms/searching_algorithm.md b/docs/dsa/algorithms/searching_algorithm.md index d8a8e0203..a26f654e6 100644 --- a/docs/dsa/algorithms/searching_algorithm.md +++ b/docs/dsa/algorithms/searching_algorithm.md @@ -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) @@ -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. + + +
+ ```python def linear_search(arr, target): for i in range(len(arr)): @@ -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 @@ -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 { @@ -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 = { @@ -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. @@ -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. diff --git a/src/components/Lesson/index.tsx b/src/components/Lesson/index.tsx index 265964008..b51d6eb59 100644 --- a/src/components/Lesson/index.tsx +++ b/src/components/Lesson/index.tsx @@ -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 = ({ id, title, tags, description }) => { +const Lesson: React.FC = ({ title, tags, description }) => { return (
{/* Container for the lesson */}

{title}

{/* Title of the lesson */}

{description}

{/* Description or content of the lesson */}
{/* Container for tags */} {tags.map((tag, index) => ( - {tag} + {tag} )) }
diff --git a/src/dsa/searching-algorithms/LinearSearchVisualizer/index.tsx b/src/dsa/searching-algorithms/LinearSearchVisualizer/index.tsx index 30f4cf7f6..f9ecaed61 100644 --- a/src/dsa/searching-algorithms/LinearSearchVisualizer/index.tsx +++ b/src/dsa/searching-algorithms/LinearSearchVisualizer/index.tsx @@ -42,9 +42,15 @@ const LinearSearchVisualizer: React.FC = () => { setSearching(false); }; + const shuffleArray = () => { + const shuffledArray = [...array].sort(() => Math.random() - 0.5); + setArray(shuffledArray); + resetVisualization(); + }; + return (
- Linear Search Visualization + Linear Search Visualization
{array.map((num, index) => (
{ +
); }; -export default LinearSearchVisualizer; \ No newline at end of file +export default LinearSearchVisualizer; diff --git a/src/pages/about/index.tsx b/src/pages/about/index.tsx index bb467e009..3c099a531 100644 --- a/src/pages/about/index.tsx +++ b/src/pages/about/index.tsx @@ -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 ( - + ); diff --git a/src/pages/blogs/index.tsx b/src/pages/blogs/index.tsx index 6814f1851..44e212dfb 100644 --- a/src/pages/blogs/index.tsx +++ b/src/pages/blogs/index.tsx @@ -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 (