-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdsa.html
771 lines (660 loc) · 32.3 KB
/
dsa.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
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>DSA</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous" />
<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=Potta+One&display=swap" rel="stylesheet" />
<link rel="stylesheet" href="style.css" />
<script src="prism.js"></script>
<link rel="stylesheet" href="prism.css" />
</head>
<body>
<nav>
<span class="logo"><img
src="https://w7.pngwing.com/pngs/592/864/png-transparent-computer-icons-icon-design-cut-copy-and-paste-taobao-clothing-promotional-copy-text-rectangle-emoticon.png"
alt="logo" /></span>
<!-- Change your heading below according to your topic and technoloy you are working with -->
<div class="content center">DSA Cheat Codes (in Python) </div>
</nav>
<!-- for html replace < this with < and > > -->
<div class="container">
<ol>
<!-- Put your code below in li section -->
<!-- || || || -*-*-*-*-* Linked List -*-*-*-*-* || || ||-->
<li>
Linked List <br>
A linked list is a sequence of data structures, which are connected together via links. Linked List is a
sequence of links which contains items. Each link contains a connection to another link. Linked list is
the
second most-used data structure after array.<br>
<div class="accordion" id="accordionPanelsStayOpenExample">
<div class="accordion-item">
<h2 class="accordion-header" id="panelsStayOpen-headingOne">
<button class="accordion-button" type="button" data-bs-toggle="collapse"
data-bs-target="#panelsStayOpen-collapseOne" aria-expanded="true"
aria-controls="panelsStayOpen-collapseOne">
Design of the Template
</button>
</h2>
<div id="panelsStayOpen-collapseOne" class="accordion-collapse collapse show"
aria-labelledby="panelsStayOpen-headingOne">
<div class="accordion-body">
<strong>The following code is designed as follows :</strong><br><br>
1. Class "Node" to declare pointers.<br><br>
<strong>2. Class "Linked List" to design methods which will help user to perform desired
operation over
their Linked List data structure.</strong><br><br>
3. Sample Driver Code to demonstrate the functioning of the template.<br>
</div>
</div>
</div>
</div>
<pre class="language-python"><code>
class Node:
def __init__(self, data=None, next=None):
self.data = data
self.next = next
class LinkedList:
def __init__(self):
self.head = None
def print(self):
if self.head is None:
print("Linked is empty")
return
# itr = current node, itr.next = next node of current node
itr = self.head
llstr = ''
while itr is not None:
llstr += str(itr.data) + '---->'
itr = itr.next
print(llstr)
def insert_at_begining(self, data):
node = Node(data, self.head)
self.head = node
def insert_at_end(self, data):
if self.head is None:
self.head = Node(data, None)
return
itr = self.head
while itr.next:
itr = itr.next
itr.next = Node(data, None)
def insert_values(self, data_list):
self.head = None
for data in data_list:
self.insert_at_end(data)
def count_nodes(self):
counter = 0
itr = self.head
while itr:
counter += 1
itr = itr.next
return counter
def remove_node(self, index):
if index < 0 or index > self.count_nodes():
raise Exception(" Out of bound index")
if index == 0:
self.head = self.head.next
return
counter = 0
itr = self.head
while itr:
if counter == index - 1:
itr.next = itr.next.next
break
itr = itr.next
counter += 1
def insert_value_at(self, index, data):
if index < 0 or index > self.count_nodes():
raise Exception(" Out of bound index")
if index == 0:
self.insert_at_begining(data)
return
count = 0
itr = self.head
while itr:
if count == index - 1:
node = Node(data, itr.next)
itr.next = node
break
itr = itr.next
count += 1
if __name__ == "__main__":
llist = LinkedList()
llist.insert_values(["vadapav", "samosa", "chutney", "dosa", "chowmin"])
llist.print()
llist.count_nodes()
print("Total nodes = ", llist.count_nodes())
</code>
</pre>
</li>
<!-- write description below-->
<div class="accordion" id="accordionPanelsStayOpenExample">
<div class="accordion-item">
<h2 class="accordion-header" id="panelsStayOpen-headingOne">
<button class="accordion-button" type="button" data-bs-toggle="collapse"
data-bs-target="#panelsStayOpen-collapseOne" aria-expanded="true"
aria-controls="panelsStayOpen-collapseOne">
Explanation <\>
</button>
</h2>
<div id="panelsStayOpen-collapseOne" class="accordion-collapse collapse show"
aria-labelledby="panelsStayOpen-headingOne">
<div class="accordion-body">
<strong>A linked list is a linear data structure, in which the elements are not stored at
contiguous
memory locations. The elements in a linked list are linked using pointers as shown in
the below
image:</strong> <br>
<img src="https://media.geeksforgeeks.org/wp-content/cdn-uploads/gq/2013/03/Linkedlist.png"
alt="Linked List">
<br>
Major differences between array and linked-list are listed below:<br> <br>
<ul>
<li><u>Size</u> : Since data can only be stored in contiguous blocks of memory in an
array, its size
cannot be
altered
at runtime due to the risk of overwriting other data.
However, in a linked list, each node points to the next one such that data can exist
at scattered
(non-contiguous) addresses; this allows for a dynamic size that can change at
runtime.</li> <br>
<li>
<u>Memory allocation</u>: For arrays at compile time and at runtime for linked
lists. but, a
dynamically
allocated array also allocates memory at runtime.
</li> <br>
<li><u>Memory efficiency</u> : For the same number of elements, linked lists use more
memory as a
reference to
the
next node is also stored along with the data. However, size flexibility in linked
lists may make them
use
less memory overall; this is useful when there is uncertainty about size or there
are large variations
in
the size of data elements;
Memory equivalent to the upper limit on the size has to be allocated (even if not
all of it is being
used)
while using arrays, whereas linked lists can increase their sizes step-by-step
proportionately to the
amount of data.</li> <br>
<li><u>Execution Time</u> : Any element in an array can be directly accessed with its
index. However, in
the
case
of a
linked list, all the previous elements must be traversed to reach any element.
Also, better cache locality in arrays (due to contiguous memory allocation) can
significantly improve
performance. As a result, some operations (such as modifying a certain element) are
faster in arrays,
while others (such as inserting/deleting an element in the data) are faster in
linked lists.</li> <br>
<li><u>Insertion</u> : In an array, insertion operation takes more time but in a linked
list these
operations
are
fast. For example, if we want to insert an element in the array at the end position
in the array and
the
array is full then we copy the array into another array and then we can add an
element whereas if the
linked list is full then we find the last node and make it next to the new node
Dependency: In an array, values are independent of each other but
In the case of linked list nodes are dependent on each other. one node is dependent
on its previous
node.
If the previous node is lost then we can’t find its next subsequent nodes.</li> <br>
</ul> <br>
</div>
</div>
</div>
</div>
<!-- || || || -*-*-*-*-* Doubly Linked List -*-*-*-*-* || || ||-->
<!-- Put your code below in li section -->
<li>
Doubly Linked List <br>
A Doubly Linked List (DLL) contains an extra pointer, typically called previous pointer, together with
next pointer and data which are there in singly linked list.<br>
<div class="accordion" id="accordionPanelsStayOpenExample">
<div class="accordion-item">
<h2 class="accordion-header" id="panelsStayOpen-headingOne">
<button class="accordion-button" type="button" data-bs-toggle="collapse"
data-bs-target="#panelsStayOpen-collapseOne" aria-expanded="true"
aria-controls="panelsStayOpen-collapseOne">
Design of the Template
</button>
</h2>
<div id="panelsStayOpen-collapseOne" class="accordion-collapse collapse show"
aria-labelledby="panelsStayOpen-headingOne">
<div class="accordion-body">
<strong>The following code is designed as follows :</strong><br><br>
1. Class "Node" to declare pointers. This Node class is as same as Singly Linked List
but with extra pointer i.e "prev" which is precious pointer.<br><br>
<strong>2. Class "Doubly Linked List" to design methods which will help user to perform
desired
operation over
their Doubly Linked List data structure.</strong><br><br>
3. Sample Driver Code to demonstrate the functioning of the template.<br>
</div>
</div>
</div>
</div>
<pre class="language-python"><code>
class Node:
def __init__(self, data=None, next=None, prev=None):
self.data = data
self.next = next
self.prev = prev
class DoublyLinkedList:
def __init__(self):
self.head = None
def print_forward(self):
if self.head is None:
print("Linked list is empty")
return
itr = self.head
llstr = ''
while itr:
llstr += str(itr.data)+' --> ' if itr.next else str(itr.data)
itr = itr.next
print(llstr)
def print_backward(self):
if self.head is None:
print("Linked list is empty")
return
last_node = self.get_last_node()
itr = last_node
llstr = ''
while itr:
llstr += itr.data + '-->'
itr = itr.prev
print("Link list in reverse: ", llstr)
def get_last_node(self):
itr = self.head
while itr.next:
itr = itr.next
return itr
def get_length(self):
count = 0
itr = self.head
while itr:
count += 1
itr = itr.next
return count
def insert_at_begining(self, data):
node = Node(data, self.head)
self.head = node
def insert_at_end(self, data):
if self.head is None:
self.head = Node(data, None)
return
itr = self.head
while itr.next:
itr = itr.next
itr.next = Node(data, None)
def insert_at(self, index, data):
if index < 0 or index > self.get_length():
raise Exception("Invalid Index")
if index == 0:
self.insert_at_begining(data)
return
count = 0
itr = self.head
while itr:
if count == index - 1:
node = Node(data, itr.next)
itr.next = node
break
itr = itr.next
count += 1
def remove_at(self, index):
if index < 0 or index >= self.get_length():
raise Exception("Invalid Index")
if index == 0:
self.head = self.head.next
return
count = 0
itr = self.head
while itr:
if count == index - 1:
itr.next = itr.next.next
break
itr = itr.next
count += 1
def insert_values(self, data_list):
self.head = None
for data in data_list:
self.insert_at_end(data)
def insert_after_value(self, data_after, data_to_insert):
# Search for first occurance of data_after value in linked list
# Now insert data_to_insert after data_after node
itr = self.head
while itr:
if data_after == itr.data:
node = Node(data_to_insert, itr.next)
itr.next = node
break
itr = itr.next
def remove_by_value(self, data):
if self.head is None:
return
if self.head.data == data:
self.head = self.head.next
return
itr = self.head
while itr.next:
if itr.next.data == data:
itr.next = itr.next.next
break
itr = itr.next
if __name__ == '__main__':
ll = DoublyLinkedList()
ll.insert_values(["banana", "mango", "grapes", "orange"])
ll.get_last_node()
ll.print_backward()
</code>
</pre>
</li>
<!-- write description below-->
<div class="accordion" id="accordionPanelsStayOpenExample">
<div class="accordion-item">
<h2 class="accordion-header" id="panelsStayOpen-headingOne">
<button class="accordion-button" type="button" data-bs-toggle="collapse"
data-bs-target="#panelsStayOpen-collapseOne" aria-expanded="true"
aria-controls="panelsStayOpen-collapseOne">
Explanation <\>
</button>
</h2>
<div id="panelsStayOpen-collapseOne" class="accordion-collapse collapse show"
aria-labelledby="panelsStayOpen-headingOne">
<div class="accordion-body">
<strong>A Doubly Linked List (DLL) contains an extra pointer, typically called the previous
pointer, together with the next pointer and data which are there in the singly linked
list.</strong> <br>
<img src="https://media.geeksforgeeks.org/wp-content/cdn-uploads/gq/2014/03/DLL1.png"
alt="Doubly Linked List">
<br>
<strong>Advantages of DLL over the singly linked list:</strong><br> <br>
<ul>
<li>DLL can be traversed in both forward and backward directions.</li> <br>
<li>The delete operation in DLL is more efficient if pointer to the node to be deleted
is given.</li> <br>
<li>We can quickly insert a new node before a given node.</li> <br>
<li>In a singly linked list, to delete a node, a pointer to the previous node is needed.
To get this previous node, sometimes the list is traversed. In DLL, we can get the
previous node using the previous pointer.</li> <br>
</ul> <br>
<strong>Disadvantages of DLL over the singly linked list:</strong><br> <br>
<ul>
<li>Every node of DLL Requires extra space for a previous pointer. It is possible to
implement DLL with a single pointer though </li> <br>
<li>All operations require an extra pointer previous to be maintained. For example, in
insertion, we need to modify previous pointers together with the next pointers. For
example in the following functions for insertions at different positions, we need 1
or 2 extra steps to set the previous pointer.</li> <br>
</ul> <br>
<strong>Applications of Doubly Linked List:</strong> <br>
<ul>
<li>For implementation of undo functionality at many places like editors, photoshop.
</li>
<li>In file systems.</li>
<li>In Undo stacks.</li>
<li>In both forward and backward traversal of a list.</li>
</ul>
</ul> <br>
</div>
</div>
</div>
</div>
<!-- || || || -*-*-*-*-* Stack using Linked List -*-*-*-*-* || || ||-->
<!-- Put your code below in li section -->
<li>
Stack - - -> (using Linked List) <br>
A stack is a linear data structure that stores items in a Last-In/First-Out (LIFO) or First-In/Last-Out
(FILO) manner. In stack, a new element is added at one end and an element is removed from that end only.
The insert and delete operations are often called push and pop.<br>
<div class="accordion" id="accordionPanelsStayOpenExample">
<div class="accordion-item">
<h2 class="accordion-header" id="panelsStayOpen-headingOne">
<button class="accordion-button" type="button" data-bs-toggle="collapse"
data-bs-target="#panelsStayOpen-collapseOne" aria-expanded="true"
aria-controls="panelsStayOpen-collapseOne">
Design of the Template
</button>
</h2>
<div id="panelsStayOpen-collapseOne" class="accordion-collapse collapse show"
aria-labelledby="panelsStayOpen-headingOne">
<div class="accordion-body">
<strong>The following code is designed as follows :</strong><br><br>
1. Class "Element" to declare pointers..<br><br>
<strong>2. Class "Linked List" to design methods which will help user to perform
desired
operation over
their Stack data structure.</strong><br><br>
3. Class Stack to create basic stack operations i.e push and pop<br>
</div>
</div>
</div>
</div>
<pre class="language-python"><code>
class Element(object):
def __init__(self, value):
self.value = value
self.next = None
class LinkedList(object):
def __init__(self, head=None):
self.head = head
def append(self, new_element):
current = self.head
if self.head:
while current.next:
current = current.next
current.next = new_element
else:
self.head = new_element
def insert_first(self, new_element):
"Insert new element as the head of the LinkedList"
new_element.next = self.head
self.head = new_element
def delete_first(self):
"Delete the first (head) element in the LinkedList as return it"
if self.head:
deleted_element = self.head
temp = self.head.next
self.head = temp
return deleted_element
else:
return None
class Stack(object):
def __init__(self, top=None):
self.ll = LinkedList(top)
def push(self, new_element):
"Push (add) a new element onto the top of the stack"
self.ll.insert_first(new_element)
def pop(self):
"Pop (remove) the first element off the top of the stack and return it"
return self.ll.delete_first()
# Test cases
# Set up some Elements
e1 = Element(1)
e2 = Element(2)
e3 = Element(3)
e4 = Element(4)
# Start setting up a Stack
stack = Stack(e1)
# Test stack functionality
stack.push(e2)
stack.push(e3)
print(stack.pop().value)
print(stack.pop().value)
print(stack.pop().value)
print(stack.pop())
stack.push(e4)
print(stack.pop().value)
</code>
</pre>
</li>
<!-- write description below-->
<div class="accordion" id="accordionPanelsStayOpenExample">
<div class="accordion-item">
<h2 class="accordion-header" id="panelsStayOpen-headingOne">
<button class="accordion-button" type="button" data-bs-toggle="collapse"
data-bs-target="#panelsStayOpen-collapseOne" aria-expanded="true"
aria-controls="panelsStayOpen-collapseOne">
Explanation <\>
</button>
</h2>
<div id="panelsStayOpen-collapseOne" class="accordion-collapse collapse show"
aria-labelledby="panelsStayOpen-headingOne">
<div class="accordion-body">
<strong>Stack is a linear data structure which follows a particular order in which the
operations are performed. The order may be LIFO(Last In First Out) or FILO(First In Last
Out).</strong> <br>
<img src="https://media.geeksforgeeks.org/wp-content/cdn-uploads/gq/2013/03/stack.png"
alt="Stack (using Linked List)">
<br>
There are many real-life examples of a stack. Consider an example of plates stacked over one
another in the canteen. The plate which is at the top is the first one to be removed, i.e.
the plate which has been placed at the bottommost position remains in the stack for the
longest period of time. So, it can be simply seen to follow LIFO(Last In First
Out)/FILO(First In Last Out) order. <br>
</div>
</div>
</div>
</div>
<!-- || || || -*-*-*-*-* Queue using Linked List -*-*-*-*-* || || ||-->
<!-- Put your code below in li section -->
<li>
Queue - - -> (using Linked List) <br>
Like stack, queue is a linear data structure that stores items in First In First Out (FIFO) manner. With
a queue the least recently added item is removed first. A good example of queue is any queue of
consumers for a resource where the consumer that came first is served first.<br>
<div class="accordion" id="accordionPanelsStayOpenExample">
<div class="accordion-item">
<h2 class="accordion-header" id="panelsStayOpen-headingOne">
<button class="accordion-button" type="button" data-bs-toggle="collapse"
data-bs-target="#panelsStayOpen-collapseOne" aria-expanded="true"
aria-controls="panelsStayOpen-collapseOne">
Design of the Template
</button>
</h2>
<div id="panelsStayOpen-collapseOne" class="accordion-collapse collapse show"
aria-labelledby="panelsStayOpen-headingOne">
<div class="accordion-body">
<strong>The following code is designed as follows :</strong><br><br>
1. Imported"deque" from collections.<br><br>
<strong>2. Class "Queue" to perform enqueue, dequeue and peek operation</strong><br><br>
3. Driver code to demonstrate the queue operation.<br>
</div>
</div>
</div>
</div>
<pre class="language-python"><code>
from collections import deque
class Queue:
def __init__(self, head=None):
self.storage = [head]
def enqueue(self, new_element):
self.storage.append(new_element)
def peek(self):
return self.storage[0]
def dequeue(self):
return self.storage.pop(0)
# Setup
q = Queue(1)
q.enqueue(2)
q.enqueue(3)
# Test peek
# Should be 1
print(q.peek())
# Test dequeue
# Should be 1
print(q.dequeue())
# Test enqueue
q.enqueue(4)
# Should be 2
print(q.dequeue())
# Should be 3
print(q.dequeue())
# Should be 4
print(q.dequeue())
q.enqueue(5)
# Should be 5
print(q.peek())
</code>
</pre>
</li>
<!-- write description below-->
<div class="accordion" id="accordionPanelsStayOpenExample">
<div class="accordion-item">
<h2 class="accordion-header" id="panelsStayOpen-headingOne">
<button class="accordion-button" type="button" data-bs-toggle="collapse"
data-bs-target="#panelsStayOpen-collapseOne" aria-expanded="true"
aria-controls="panelsStayOpen-collapseOne">
Explanation <\>
</button>
</h2>
<div id="panelsStayOpen-collapseOne" class="accordion-collapse collapse show"
aria-labelledby="panelsStayOpen-headingOne">
<div class="accordion-body">
<strong>A queue is defined as a linear data structure that is open at both ends and the
operations are performed in First In First Out (FIFO) order.</strong> <br>
<img src="https://media.geeksforgeeks.org/wp-content/uploads/20220805131014/fifo.png"
alt="Stack (using Linked List)">
<br>
FIFO Principle of Queue:
<ul>
<li>A Queue is like a line waiting to purchase tickets, where the first person in line
is
the first person served. (i.e. First come first serve).</li><br>
<li>A Queue is like a line waiting to purchase tickets, where the first person in line
is
the first person served. (i.e. First come first serve).</li><br>
</ul><br>
<strong>Operations on Queue:</strong><br>
<ul>
<li>Enqueue: Adds an item to the queue. If the queue is full, then it is said to be an
Overflow condition.</li> <br>
<li>Dequeue: Removes an item from the queue. The items are popped in the same order in
which they are pushed. If the queue is empty, then it is said to be an Underflow
condition.</li> <br>
<li>Front: Get the front item from queue.</li> <br>
<li>Rear: Get the last item from queue.</li> <br>
</ul>
Characteristics of Queue: <br>
<ul>
<li>-Queue can handle multiple data.</li> <br>
<li>-We can access both ends.</li> <br>
<li>-They are fast and flexible.</li> <br>
</ul>
Queue Representation: <br>
Like stacks, Queues can also be represented in an array: In this representation, the Queue
is implemented using the array. Variables used in this case are <br>
<ul>
<li>Queue: the name of the array storing queue elements.</li> <br>
<li>front: the index of the front element of the queue.</li> <br>
<li>rear: the index of the rear element of the queue.</li> <br>
<li>size: the size of the queue.</li> <br>
</ul>
</div>
</div>
</div>
</div>
</ol>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"
integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM"
crossorigin="anonymous"></script>
</body>
</html>