forked from Sohan-Rout/DSA
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.jsx
More file actions
executable file
·240 lines (220 loc) · 9.23 KB
/
Copy pathcontent.jsx
File metadata and controls
executable file
·240 lines (220 loc) · 9.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
"use client";
import { useEffect, useState } from "react";
import DailyDSAEmbed from "@/app/components/ui/DailyDSAEmbed";
const content = () => {
const [theme, setTheme] = useState("light");
useEffect(() => {
const updateTheme = () => {
const savedTheme = localStorage.getItem("theme") || "light";
setTheme(savedTheme);
};
updateTheme();
window.addEventListener("storage", updateTheme);
window.addEventListener("themeChange", updateTheme);
return () => {
window.removeEventListener("storage", updateTheme);
window.removeEventListener("themeChange", updateTheme);
};
}, []);
const paragraph = [
`Implementing a Queue using an array is a fundamental approach where we use a fixed-size or dynamic array to store elements while maintaining FIFO order. The array implementation requires careful handling of front and rear pointers to efficiently enqueue and dequeue elements.`,
`In a circular array implementation, we treat the array as circular to maximize space utilization. When either pointer reaches the end of the array, it wraps around to the beginning.`,
`Queues are widely used in scenarios like printer job scheduling, call center systems, and network packet handling where order preservation is crucial.`,
];
const implementationSteps = [
{
points:
"Initialize an array of fixed size (for static implementation) or dynamic array",
},
{
points:
"Initialize two pointers: front (for dequeue) and rear (for enqueue), both set to -1 initially",
},
{
points:
"Implement boundary checks for overflow (full queue) and underflow (empty queue) conditions",
},
{
points:
"For circular queue implementation, use modulo arithmetic for pointer updates",
},
];
const enqueueAlgorithm = [
{
points:
"Check if queue is full (if (rear == capacity - 1) for linear array)",
},
{ points: "For empty queue, set both front and rear to 0" },
{ points: "For circular queue: rear = (rear + 1) % capacity" },
{ points: "Insert new element at items[rear]" },
{ points: "Increment size counter" },
];
const dequeueAlgorithm = [
{ points: "Check if queue is empty (front == -1)" },
{ points: "Store the front element to return later" },
{ points: "If only one element (front == rear), reset pointers to -1" },
{ points: "For circular queue: front = (front + 1) % capacity" },
{ points: "Decrement size counter" },
{ points: "Return the stored element" },
];
const complexity = [
{
points:
"Enqueue Operation: O(1) - Amortized constant time for dynamic arrays",
},
{
points:
"Dequeue Operation: O(1) - No shifting needed with pointer approach",
},
{ points: "Peek Operation: O(1) - Direct access via front pointer" },
{ points: "Space Usage: O(n) - Linear space for storing elements" },
];
const prosCons = [
{
points:
"Pros: Simple implementation, cache-friendly (array elements contiguous in memory)",
},
{ points: "Pros: Efficient O(1) operations with pointer tracking" },
{ points: "Cons: Fixed size limitation in static array implementation" },
{
points:
"Cons: Wasted space in linear array implementation without circular approach",
},
];
return (
<main className="max-w-7xl mx-auto grid grid-cols-1 md:grid-cols-5 md:gap-4">
<DailyDSAEmbed mobile={false} theme={theme} />
<article className="col-span-4 max-w-4xl bg-white dark:bg-neutral-950 rounded-xl shadow-sm border border-gray-200 dark:border-gray-700 overflow-hidden mb-8">
{/* Queue Array Implementation Overview */}
<section className="p-6 border-b border-gray-100 dark:border-gray-700">
<h1 className="text-2xl font-bold text-gray-900 dark:text-white mb-4 flex items-center">
<span className="w-1 h-6 bg-blue-500 mr-3 rounded-full"></span>
Queue Implementation Using Array
</h1>
<div className="prose dark:prose-invert max-w-none">
<p className="text-gray-700 dark:text-gray-300 leading-relaxed">
{paragraph[0]}
</p>
</div>
</section>
{/* Implementation Steps */}
<section className="p-6 border-b border-gray-100 dark:border-gray-700">
<h1 className="text-2xl font-bold text-gray-900 dark:text-white mb-4 flex items-center">
<span className="w-1 h-6 bg-blue-500 mr-3 rounded-full"></span>
Implementation Steps
</h1>
<div className="prose dark:prose-invert max-w-none">
<ol className="space-y-2 list-decimal pl-5 marker:text-gray-500 dark:marker:text-gray-400">
{implementationSteps.map((item, index) => (
<li
key={index}
className="text-gray-700 dark:text-gray-300 pl-2"
>
{item.points}
</li>
))}
</ol>
</div>
</section>
{/* Enqueue Algorithm */}
<section className="p-6 border-b border-gray-100 dark:border-gray-700">
<h1 className="text-2xl font-bold text-gray-900 dark:text-white mb-4 flex items-center">
<span className="w-1 h-6 bg-blue-500 mr-3 rounded-full"></span>
Enqueue Algorithm
</h1>
<div className="prose dark:prose-invert max-w-none">
<ol className="space-y-2 list-decimal pl-5 marker:text-gray-500 dark:marker:text-gray-400">
{enqueueAlgorithm.map((item, index) => (
<li
key={index}
className="text-gray-700 dark:text-gray-300 pl-2"
>
{item.points}
</li>
))}
</ol>
</div>
</section>
{/* Dequeue Algorithm */}
<section className="p-6 border-b border-gray-100 dark:border-gray-700">
<h1 className="text-2xl font-bold text-gray-900 dark:text-white mb-4 flex items-center">
<span className="w-1 h-6 bg-blue-500 mr-3 rounded-full"></span>
Dequeue Algorithm
</h1>
<div className="prose dark:prose-invert max-w-none">
<ol className="space-y-2 list-decimal pl-5 marker:text-gray-500 dark:marker:text-gray-400">
{dequeueAlgorithm.map((item, index) => (
<li
key={index}
className="text-gray-700 dark:text-gray-300 pl-2"
>
{item.points}
</li>
))}
</ol>
</div>
</section>
{/* Time Complexity */}
<section className="p-6 border-b border-gray-100 dark:border-gray-700">
<h1 className="text-2xl font-bold text-gray-900 dark:text-white mb-4 flex items-center">
<span className="w-1 h-6 bg-blue-500 mr-3 rounded-full"></span>
Time & Space Complexity
</h1>
<div className="prose dark:prose-invert max-w-none">
<ul className="space-y-2 list-disc pl-5 marker:text-gray-500 dark:marker:text-gray-400">
{complexity.map((item, index) => (
<li
key={index}
className="text-gray-700 dark:text-gray-300 pl-2"
>
<span className="font-mono bg-gray-100 dark:bg-gray-700 px-2 py-1 rounded text-sm">
{item.points.split(":")[0]}:
</span>
<span className="ml-2">{item.points.split(":")[1]}</span>
</li>
))}
</ul>
</div>
</section>
{/* Pros and Cons */}
<section className="p-6 border-b border-gray-100 dark:border-gray-700">
<h1 className="text-2xl font-bold text-gray-900 dark:text-white mb-4 flex items-center">
<span className="w-1 h-6 bg-blue-500 mr-3 rounded-full"></span>
Pros and Cons
</h1>
<div className="prose dark:prose-invert max-w-none">
<ul className="space-y-2 list-disc pl-5 marker:text-gray-500 dark:marker:text-gray-400">
{prosCons.map((item, index) => (
<li
key={index}
className="text-gray-700 dark:text-gray-300 pl-2"
>
{item.points}
</li>
))}
</ul>
</div>
</section>
{/* Additional Info */}
<section className="p-6">
<div className="prose dark:prose-invert max-w-none">
<div className="px-4 bg-blue-50 dark:bg-blue-900/20 rounded-lg border border-blue-200 dark:border-blue-800">
<h3 className="text-lg font-semibold text-gray-900 dark:text-white mb-2">
Practical Considerations
</h3>
<p className="text-gray-700 dark:text-gray-300 leading-relaxed">
{paragraph[1]}
</p>
<p className="text-gray-700 dark:text-gray-300 mt-2 leading-relaxed">
{paragraph[2]}
</p>
</div>
</div>
</section>
</article>
{/* Mobile iframe at bottom */}
<DailyDSAEmbed mobile theme={theme} />
</main>
);
};
export default content;