diff --git a/src/components/dsa/AlgorithmExplanation.jsx b/src/components/dsa/AlgorithmExplanation.jsx new file mode 100644 index 0000000..9ee63e2 --- /dev/null +++ b/src/components/dsa/AlgorithmExplanation.jsx @@ -0,0 +1,40 @@ +import { sortingAlgorithmsMeta } from "@/data/sortingAlgorithmsMeta"; +const AlgorithmExplanation = ({ algorithm, darkMode }) => { + const info = sortingAlgorithmsMeta[algorithm]; + if (!info) return null; + + return ( +
+

{info.name}

+

{info.description}

+ +
+
How it works:
+
    + {info.steps?.map((step, index) => ( +
  1. {step}
  2. + ))} +
+
+ +
+ + Time:{" "} + {info.time.average || info.time} + + + Space: {info.space} + +
+
+ ); + }; + + export default AlgorithmExplanation; + \ No newline at end of file diff --git a/src/data/sortingAlgorithmsMeta.js b/src/data/sortingAlgorithmsMeta.js new file mode 100644 index 0000000..9965525 --- /dev/null +++ b/src/data/sortingAlgorithmsMeta.js @@ -0,0 +1,111 @@ +export const sortingAlgorithmsMeta= { + BubbleSort: { + name: "Bubble Sort", + description: + "Bubble Sort repeatedly compares adjacent elements and swaps them if they are in the wrong order. Larger elements gradually move to the end of the array.", + + steps: [ + "Start from the first element of the array.", + "Compare the current element with the next element.", + "If the current element is greater, swap them.", + "Move to the next pair and repeat.", + "After each pass, the largest element moves to the end.", + "Repeat until no swaps are needed." + ], + + time: { + best: "O(n)", + average: "O(n²)", + worst: "O(n²)" + }, + space: "O(1)", + stable: true + }, + + SelectionSort: { + name: "Selection Sort", + description: + "Selection Sort selects the smallest element from the unsorted portion and places it at the beginning.", + + steps: [ + "Divide the array into sorted and unsorted parts.", + "Find the smallest element in the unsorted part.", + "Swap it with the first unsorted element.", + "Move the boundary of the sorted part forward.", + "Repeat until the array is sorted." + ], + + time: { + best: "O(n²)", + average: "O(n²)", + worst: "O(n²)" + }, + space: "O(1)", + stable: false + }, + + InsertionSort: { + name: "Insertion Sort", + description: + "Insertion Sort builds the sorted array one element at a time.", + + steps: [ + "Assume the first element is already sorted.", + "Pick the next element and compare it with previous elements.", + "Shift larger elements one position to the right.", + "Insert the element into its correct position.", + "Repeat until the array is sorted." + ], + + time: { + best: "O(n)", + average: "O(n²)", + worst: "O(n²)" + }, + space: "O(1)", + stable: true + }, + + MergeSort: { + name: "Merge Sort", + description: + "Merge Sort divides the array into halves, sorts them recursively, and merges the sorted halves.", + + steps: [ + "Divide the array into two halves.", + "Recursively divide each half until single elements remain.", + "Merge the smaller sorted arrays into larger sorted arrays.", + "Repeat until the full array is merged." + ], + + time: { + best: "O(n log n)", + average: "O(n log n)", + worst: "O(n log n)" + }, + space: "O(n)", + stable: true + }, + + QuickSort: { + name: "Quick Sort", + description: + "Quick Sort selects a pivot and partitions the array around it.", + + steps: [ + "Choose a pivot element.", + "Partition the array so smaller elements go left and larger go right.", + "Recursively apply the same process to subarrays.", + "Continue until the array is sorted." + ], + + time: { + best: "O(n log n)", + average: "O(n log n)", + worst: "O(n²)" + }, + space: "O(log n)", + stable: false + } + }; + \ No newline at end of file diff --git a/src/pages/DsaVisualization.jsx b/src/pages/DsaVisualization.jsx index 5caefa3..6e3bf33 100644 --- a/src/pages/DsaVisualization.jsx +++ b/src/pages/DsaVisualization.jsx @@ -32,6 +32,7 @@ import TreeVisualizer from '@/components/dsa/TreeVisualizer'; import HeapVisualizer from '@/components/dsa/HeapVisualizer'; import DPVisualizer from '@/components/dsa/DPVisualizer'; import ContributorsSection from '@/components/dsa/ContributorsSection'; +import AlgorithmExplanation from '@/components/dsa/AlgorithmExplanation'; // --- Existing Sorting/Graph Components --- @@ -628,12 +629,13 @@ const DsaVisualization = () => { )} {(activeTab === 'sorting') && ( +
setCustomInput(e.target.value)} className="h-8 text-xs" /> -
+
)} @@ -650,7 +652,10 @@ const DsaVisualization = () => { - 공급 + + + + {isComparisonMode && ( @@ -658,8 +663,13 @@ const DsaVisualization = () => {

{secondAlgorithm.replace(/([A-Z])/g, ' $1').trim()}

+
+ +
+ + )} ) : activeTab === 'graphs' ? (