Questions and Verified Answers |
Already Graded A+
List - 🧠 ANSWER ✔✔unordered collection of items, not necessarily distinct
(other ADT outside of SET and BAG)
Types of List - 🧠 ANSWER ✔✔1. stacks
2. queue
How to search a List - 🧠 ANSWER ✔✔-indexing
-name/id/key
-position
Stack - 🧠 ANSWER ✔✔-linear list with all additions and deletions restricted
to one end (top)
,-insert: push
-remove/delete: pop
-obeys last in first out (LIFO)
-uses an array
When to Use Stack - 🧠 ANSWER ✔✔Where we need to remember a bunch
of things and go back to the most recent:
-stack of plates
-back button on browser
-undo button
Stack (Push) - 🧠 ANSWER ✔✔- n is the number of elements
- m is the length of the array
assert (n<m);
a[n] = x;
n++;
runtime: O(1)
,Stack (Pop) - 🧠 ANSWER ✔✔- n is the number of elements
- m is the length of the array
assert (n>0);
x = a[n-1];
n--;
return x; //deleted value
runtime: O(1)
Queue - 🧠 ANSWER ✔✔-linear list in which data can only be inserted at
one end (rear) and deleted from other end (front)
-obeys first-in and first-out (FIFO)
-removes oldest item to ensure fairness
-implementation through an array
Enqueue - 🧠 ANSWER ✔✔-insertion
1. add at end
2. remove from the front (always keep front of queue at index 0)
COPYRIGHT©PROFFKERRYMARTIN 2025/2026. YEAR PUBLISHED 2025. COMPANY REGISTRATION NUMBER: 619652435. TERMS OF USE.
PRIVACY STATEMENT. ALL RIGHTS RESERVED
, assert (n<m);
a[n]=x;
n++;
Runtime: O(1)
Dequeue (stagnant index) - 🧠 ANSWER ✔✔-deletion
assert (n>0);
x=a[0];
n--;
for (i=0;i<n-1;i=i+2)
a[i]=a[i+1];
return x;
Runtime: O(n-1) = O(n) //without moving front of array
When to Use Queues - 🧠 ANSWER ✔✔-Grocery shopping line
-Youtube playlist
-Office hours