-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
536 lines (447 loc) · 28.2 KB
/
index.html
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
<!DOCTYPE html>
<html lang="en">
<head>
<title>AlgoSparks</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<link rel="stylesheet" href="https://www.w3schools.com/lib/w3-theme-black.css">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Josefin+Sans&display=swap" rel="stylesheet">
<link href='https://fonts.googleapis.com/css?family=Lexend' rel='stylesheet'>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-8306858446960380"
crossorigin="anonymous"></script>
<link rel="icon" type="image/x-icon" href="Favicon.png">
<style>
h1,
h2,
h3,
h4,
h5,
h6 {
font-family: "Josefin Sans", sans-serif; color: #4CD4CB; font-weight: 600;
}
html,
body {
font-family: "Lexend", sans-serif
}
.w3-sidebar {
z-index: 3;
width: 250px;
top: 43px;
bottom: 0;
height: inherit;
}
</style>
</head>
<body>
<!-- Navbar -->
<div class="w3-top">
<div class="w3-bar w3-theme w3-top w3-left-align w3-large">
<a class="w3-bar-item w3-button w3-right w3-hide-large w3-hover-white w3-large w3-theme-l1"
href="javascript:void(0)" onclick="w3_open()"><i class="fa fa-bars"></i></a>
<a href="index.html" class="w3-bar-item w3-button "><img src="images\AlgoSparks-2.png" alt="logo"
width="100" height="30"></a>
<a href="index.html" class="w3-bar-item w3-button w3-hide-small w3-hover-white">Algorithm Visualizer</a>
<a href="nQueen.html" class="w3-bar-item w3-button w3-hide-small w3-hover-white">theory</a>
<a href="searching\linear.html" class="w3-bar-item w3-button w3-hide-small w3-hover-white">Visualizer</a>
<a href="https://uv7l0bwgt6x.typeform.com/to/fbmGzmQf" class="w3-bar-item w3-button w3-hide-small w3-hover-white">Quiz</a>
<a href="#" class="w3-bar-item w3-button w3-hide-small w3-hover-white">Forum</a>
</div>
</div>
<!-- Sidebar -->
<nav class="w3-sidebar w3-bar-block w3-collapse w3-large w3-theme-l5 w3-animate-left" id="mySidebar">
<a href="javascript:void(0)" onclick="w3_close()"
class="w3-right w3-xlarge w3-padding-large w3-hover-black w3-hide-large" title="Close Menu">
<i class="fa fa-remove"></i>
</a>
<h2 class="w3-bar-item"><b>Contents</b></h2>
<h3 class="w3-bar-item">Visualizers</h3>
<a class="w3-bar-item w3-button w3-hover-black" href="searching\linear.html"><b>Linear Search</b></a>
<a class="w3-bar-item w3-button w3-hover-black" href="searching\binary.html"><b>Binary Search</b></a>
<a class="w3-bar-item w3-button w3-hover-black" href="sorting\selection.html"><b>Selection Sort</b></a>
<a class="w3-bar-item w3-button w3-hover-black" href="string_matching\stringmatching.html"><b>String Matching</b></a>
<a class="w3-bar-item w3-button w3-hover-black" href="LCS\LCS.html"><b>LCS</b></a>
<h3 class="w3-bar-item">Modules</h3>
<a class="w3-bar-item w3-button w3-hover-black" href="index.html"><b>Algorithms</b></a>
<a class="w3-bar-item w3-button w3-hover-black" href="nQueen.html"><b>n-Queen Problem</b></a>
<a class="w3-bar-item w3-button w3-hover-black" href="#">Approach of Solving</a>
<a class="w3-bar-item w3-button w3-hover-black" href="#">Types</a>
<a class="w3-bar-item w3-button w3-hover-black" href="#">Brute</a>
<a class="w3-bar-item w3-button w3-hover-black" href="#">Recursive</a>
<a class="w3-bar-item w3-button w3-hover-black" href="#">Divide & Conquer</a>
<a class="w3-bar-item w3-button w3-hover-black" href="#">Greedy</a>
<a class="w3-bar-item w3-button w3-hover-black" href="#">Backtracking</a>
<a class="w3-bar-item w3-button w3-hover-black" href="#">Dynamic</a>
<a class="w3-bar-item w3-button w3-hover-black" href="#">Pattern</a>
<a class="w3-bar-item w3-button w3-hover-black" href="#">Recursive</a>
<a class="w3-bar-item w3-button w3-hover-black" href="#">Analysis</a>
</nav>
<!-- Overlay effect when opening sidebar on small screens -->
<div class="w3-overlay w3-hide-large" onclick="w3_close()" style="cursor:pointer" title="close side menu"
id="myOverlay"></div>
<!-- Main content: shift it to the right by 250 pixels when the sidebar is visible -->
<div class="w3-main" style="margin-left:250px">
<div class="w3-row w3-padding-64">
<div class="w3-twothird w3-container">
<h1 class="w3-text-teal">Algorithms</h1>
<p align="justify">An algorithm is a procedure that takes in input, follows a certain set of steps, and
then produces an
output. Oftentimes, the algorithm defines a desired relationship between the input and output. For
example, if the problem that we are trying to solve is sorting a hand of cards, the problem might be
defined as follows:</p>
<p align="justify"><b>Definition:</b><br>
Problem: Sort the input.<br>
Input: A set of 5 cards.<br>
Output: The set of 5 input cards, sorted.<br>
Procedure: Up to the designer of the algorithm!!</p>
<p align="justify">This last part is very important, it's the meat and substance of the algorithm. And,
as an algorithm
designer, you can do whatever you want to produce the desired output! Think about some ways you
could sort 5 cards in your hand, and then click below to see some more ideas.
The study of algorithms involves finding the best ways to achieve the desired output given an input
and a goal. Learning about algorithms is essential to being a successful computer programmer, and
understanding them can help give you an idea of how computers work. So, if you'd like to learn to
code, it's absolutely essential to learn about algorithms.</p>
<br>
<p align="center"><img src="images\algo 4.jfif" style="border: 2px solid #000000; height:300px; width: 500px;"></p>
</div>
<div class="w3-third w3-container">
<p class="w3-border w3-padding-large w3-padding-32 w3-center"><script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-8306858446960380"
crossorigin="anonymous"></script></p>
<p class="w3-border w3-padding-large w3-padding-64 w3-center"><script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-8306858446960380"
crossorigin="anonymous"></script></p>
</div>
</div>
<div class="w3-row ">
<div class="w3-twothird w3-container">
<h2 class="w3-text-teal">Algorithms and Computers</h2>
<p align="justify">
Even though algorithms existed before the modern computer, they lie at the heart of computing and
technology. Everything you've ever done on any piece of technology relies on algorithms because they
tell technology what to do. Algorithms are responsible for your ability to surf the web at tolerable
speeds. Imagine that you're visiting a website, and that website has a lot of unsorted content to
show you. If it randomly picked a content order every time you visited it, and threw that order away
and tried again if it wasn't correct, you'd be waiting for minutes, hours, or even days before your
web page loaded!</p>
<p align="justify">Studying computer science and computer programming always involves algorithms because
the study of
algorithms teaches you to think like a machine so that you can program them in the best way
possible. If you'd like to learn how to write applications, make websites, or do data analysis, you
need to know about algorithms so that your code will run fast and run correctly.</p>
<p align="justify">On the theoretical side, many of the simpler algorithms have long since been
discovered and heavily
studied, but there are many areas left to research. For example, in theoretical computer science, a
lingering question is whether P = NP, or in other words, "Are problems that can be quickly verified
by a computer able to be quickly solved by a computer?" Currently, we don't think so. But if it
turned out to be true, then computing and technology would experience an enormous speed increase
that we would all benefit from. However, this would also mean that modern cryptography is not safe
and any hacker could easily crack codes to any system in the world!</p>
<p align="justify">As computing grew, applications of computing grew along with it. In order to perform
the algorithms
that would enable those applications, computer scientists needed a way to represent and store that
data. If we wanted to input a set of cards into a computer program, how would we store that data?
How would we feed it into the algorithm? Early on, it was good enough to simply represent data as
computer bits (zeroes and ones). However, that method could never last, it was too difficult and
time-consuming.</p>
<p align="justify">Data structures were the answer. Their invention and research is paralleled by, and
is often taught
alongside, algorithms. The card sorting algorithm, for example, could take in an array of numbers to
represent cards. More data structures were invented over time, and they allowed algorithm design to
progress with them. With these in place, it became much easier to reason about, develop, and
research algorithms.</p>
</div>
<div class="w3-third w3-container">
<p class="w3-border w3-padding-large w3-padding-32 w3-center"><script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-8306858446960380"
crossorigin="anonymous"></script></p>
<p class="w3-border w3-padding-large w3-padding-64 w3-center"><script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-8306858446960380"
crossorigin="anonymous"></script></p>
</div>
</div>
<div class="w3-row ">
<div class="w3-twothird w3-container">
<h2 class="w3-text-teal">Properties of Algorithms</h2>
<p align="justify">Algorithms have 3 main properties that are important to remember during their design
and analysis.
<ol>
<li>
<p align="justify">Time complexity. This is the time an algorithm takes to complete, and it is
often given using
big O notation with its input as the independent variable. For example, if we want to search
a
card in the sorted n cards, we can do in logarithmic time, and the time complexity would be
O(log(n))</p>
</li>
<li>
<p align="justify">Space complexity. This is the space (in computer memory) the algorithm uses
during its
execution. Again, if we're sorting n cards, and we need to make an extra array of size n for
each card to do so, the space complexity would be O(log(n^2))</p>
</li>
<li>
<p align="justify">Correctness. An algorithm is correct if and only if, for every input, it
halts and outputs the
correct output. Contrary to what you might think, algorithms that are not correct are
sometimes
useful. For example, partially correct algorithms only guarantee that if the algorithm
halts,
the answer will be correct.</p>
</li>
</ol>
</p>
<p align="just">An algorithm can be expressed in a variety of ways, many of which you'll find in
different wikis here on Brilliant. A few examples of how an algorithm can be described are as
follows:
</p>
<p align="just">
<ol>
<li>
<p align="just">A high-level description: This might be in the form of text or prose that
describes the algorithm: it's input, output, and goal. Generally, this does not involve
implementation details of the algorithm.</p>
</li>
<li>
<p align="just">Formal definition: A formal definition will often give the input and output
of the algorithm in formal mathematical terms. The procedure by which the output is achieved
is
also formally notated. This is a more mathematical way of representing an algorithm.</p>
</li>
<li>
<p align="just">Pseudo-code: This is a way of loosely formalizing an algorithm, and it is
often used when learning algorithms. There are general implementation details; however
language-specific details are left out so as not to complicate things.</p>
</li>
<li>
<p align="just">Implementation: An implementation in a given language will be a piece of
code that is understandable and runnable by a computer. It will fulfill the goals and
procedure
of the algorithm; however, it is harder to include high-level detail in an implementation
because a computer will reject plain text.</p>
</li>
</ol>
</p>
</div>
</div>
<div class="w3-row ">
<div class="w3-twothird w3-container">
<h2 class="w3-text-teal">Types of Algorithms</h2>
<style>
table,
td,
th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
</style>
<p align="justify"><i>Labels that describe function:</i></p>
<table width="100%">
<tr>
<th>
Algorithm Label</th>
<th>
Description
</th>
</tr>
<tr>
<td>Sorting algorithms
</td>
<td>Sort a list of comparable inputs.
</td>
</tr>
<tr>
<td>Graph algorithms</td>
<td>Perform elementary graph algorithms such as search.
</td>
<tr>
<td>Shortest path algorithms</td>
<td> Find the shortest path(s) between points in a graph.</td>
</tr>
<tr>
<td>String matching algorithms </td>
<td>Search larger pieces of text for input strings.</td>
</tr>
<tr>
<td>Max-flow algorithms</td>
<td> Calculate the maximum flow in a flow network.</td>
</tr>
<tr>
<td>Computational geometry algorithms
</td>
<td>A branch of algorithms that can be stated in terms of geometry</td>
</tr>
<tr>
<td>Number-theoretic algorithms</td>
<td>Algorithms that deal with number theory such as GCD</td>
</tr>
<tr>
<td>Fast fourier transform algorithms</td>
<td>Efficient algorithms that perform fourier transform</td>
</tr>
<tr>
<td>Matrix algorithms</td>
<td>Algorithms that perform operations on matrices</td>
</tr>
</tr>
</table>
</p>
</p>
</div>
<div class="w3-third w3-container">
<p align="center">
<br><br><br><br>
<img src="images\Types of algo.jfif"
style="border: 2px solid #000000; height: 115%; width: 100%"></p>
</div>
</div>
<div class="w3-row ">
<div class="w3-twothird w3-container">
<h2 class="w3-text-teal">Approach of Solving</h2>
<p><i>Some apporach of thinking and solving a problems:</i></p>
<p align="justify">
<ul>
<li>
<p align="justify"><b>Divide and conquer algorithms:</b> Divide problem into smaller subproblems
that can be recombined for an answer.</p>
</li>
<li>
<p align="justify"><b>Greedy algorithms:</b> Simple, naive approaches to problems that typically
return sub-optimal answers</p>
</li>
<li>
<p align="justify"><b>Dynamic programming algorithms:</b> Create smaller subproblems whose
answers help solve larger and larger subproblems.</p>
</li>
<li>
<p align="justify"><b>Recursive algorithms:</b> Algorithms that continuously call upon
themselves to solve smaller and smaller problems until a basis is formed for the final
solution</p>
</li>
<li>
<p align="justify"><b>Brute force algorithms:</b> An approach to solving problems that attemps
to solve the problem with more computing power, rather than elegance</p>
</li>
<li>
<p align="justify"><b>Backtracking algorithms:</b> Algorithms that build collections of partial
candidates for solutions, forgetting them only when they become impossible</p>
</li>
<li>
<p align="justify"><b>Probabilistic and randomized algorithms:</b> Algorithms that use any form
of randomization (also called non-deterministic algorithms)</p>
</li>
<li>
<p align="justify"><b>Approximation algorithms:</b> Methods that attempt to cut down on
computation time by making approximations, getting within some factor of the optimal answer
</p>
</li>
<li>
<p align="justify"><b>Multi-threaded algorithms:</b> Algorithms that run on multiple threads to
parallelize work</p>
</li>
<li>
<p align="justify"><b>Linear programming algorithms:</b> Solutions that achieve optimal answers
by using linear relationships of the inputs</p>
</li>
</ul>
</p>
</div>
</div>
<div class="w3-row ">
<div class="w3-twothird w3-container">
<h2 class="w3-text-teal">Designing an Algorithm</h2>
<p align="justify">When designing an algorithm, it is important to remember that computers are not
infinitely fast and that computer memory is not infinitely large. That's why we make algorithms,
after all. So, maybe you're designing an algorithm for a computer that is super fast but doesn't
have much memory. Maybe you'll make some concessions on the computational requirements so that you
can save memory.</p>
<p align="justify">But even if you never had to worry about speed or space, you still need to design a
good algorithm. Why? You need to design a good algorithm because you need to know that the algorithm
will do what you want it to do and that it will stop once it's done. You need to know that it will
be correct.</p>
<p align="justify"><b>Efficacy</b><br>
The efficacy of the algorithm you're designing comes down to time complexity and space complexity.
In an ideal world, the algorithm is efficient in both ways, but there is sometimes a tradeoff
between them. It is up to the designer to weigh their needs appropriately in order to strike a
balance.</p>
<p align="justify">It is also up to the designer to make a good algorithm. Doing so requires an
understanding of algorithms as well as an understanding of existing algorithms to guide your design
process. Otherwise, they might find themselves with a bad algorithm.</p>
</div>
</div>
<div class="w3-row">
<div class="w3-twothird w3-container">
<h2 class="w3-text-teal">Analyzing and Evaluating an Algorithm</h2>
<p align="justify">The analysis and evaluation of an algorithm is a two-step process. In the analysis
portion, the algorithm is studied to learn about its properties: time/space complexity and
correctness. Any method of describing the algorithm, as enumerated above, can be studied. However,
that description must contain enough information about the inner workings of the algorithm to
provide a clear picture of its procedure.</p>
<p align="justify">In general, there are a few ways to describe time complexity. There's the best-case,
the average-case, and the worst-case for the algorithm. As a programmer, it's important to know each
case so that you fully understand how your algorithm will operate. Which case you focus on is up to
you, but the worst-case performance is often used as a benchmark for algorithms.</p>
<p align="justify">The evaluation portion is more qualitative and requires the observer to make
decisions about the efficacy of the algorithm on its own, and as it relates to other similar
algorithms. You might see the algorithm and notice that it is making some critical errors that
increase its runtime. You might also discover that its runtime is drastically different than other
algorithms that accomplish the same thing. In either case, the evaluation result is poor.</p>
<p align="justify">Let's take a look at the pseudo-code for an algorithm and try to analyze its time
complexity. The following pseudo-code is that of insertion sort, a basic sorting algorithm. It takes
as its input an array A, of the number and returns that same array, sorted. Note that this
pseudo-code assumes 1-indexing (the first index in the array is 1, not 0).
</p>
<div class="w3-row">
<div class=" w3-container">
<div align="center" ><button data-tf-popup="fbmGzmQf" data-tf-opacity="100" data-tf-size="100" data-tf-iframe-props="title=Algorithms" data-tf-transitive-search-params data-tf-medium="snippet" style=" align-self: center; all:unset;font-family: Lexend, sans-serif;display:inline-block;max-width:100%;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;background-color:#4CD4CB;color:#000000;font-size:20px;border-radius:25px;padding:0 33px;font-weight:bold;height:50px;cursor:pointer;line-height:50px;text-align:center;margin:0;text-decoration:none;">Click to start the Quiz</button><script src="//embed.typeform.com/next/embed.js"></script>
</div>
</div>
</div>
</div>
</div>
<!-- Pagination -->
<div class="w3-center w3-padding-32">
<div class="w3-bar">
<a class="w3-button w3-black" href="index.html">1</a>
<a class="w3-button w3-hover-black" href="nQueen.html">2</a>
<a class="w3-button w3-hover-black" href="searching\linear.html">3</a>
<a class="w3-button w3-hover-black" href="searching\binary.html">4</a>
<a class="w3-button w3-hover-black" href="sorting\selection.html#">5</a>
<a class="w3-button w3-hover-black" href="LCS\LCS.html">»</a>
</div>
</div>
<!-- END MAIN -->
</div>
<script>
// Get the Sidebar
var mySidebar = document.getElementById("mySidebar");
// Get the DIV with overlay effect
var overlayBg = document.getElementById("myOverlay");
// Toggle between showing and hiding the sidebar, and add overlay effect
function w3_open() {
if (mySidebar.style.display === 'block') {
mySidebar.style.display = 'none';
overlayBg.style.display = "none";
} else {
mySidebar.style.display = 'block';
overlayBg.style.display = "block";
}
}
// Close the sidebar with the close button
function w3_close() {
mySidebar.style.display = "none";
overlayBg.style.display = "none";
}
</script>
<script>
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-FNH0JFN4ZN"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-FNH0JFN4ZN');
</script>
</body>
</html>