Ace The Basics Final
Ace The Basics Final
Operations on stack
push- To add an element at the top.
pop- To remove an element form the top.
Top- Top most element on the stack.
isEmpty- To checkif Stack is empty or not.
REAL WORLD EXAMPLE
CONSIDER A BOX OF PRINGLES
(FAMOUS CHIPS BRAND) YOU
WILL TAKE OF CAP AND WILL
TAKE ALL CHIPS ONE BY ONE
FROM THE TOP, AND IF YOU
CANNOT EAT, YOU WILL PUT IT
BACK ON TOP.
TECHNICAL EXAMPLE
You all have used Undo and Redo in
Computer it is nothing but implementation
of stack.
https://leetcode.com/problems/valid-parentheses/description/
https://leetcode.com/problems/reverse-words-in-a-string/
https://leetcode.com/problems/remove-all-adjacent-duplicates-in-string/description/?envType=problem-list-
v2&envId=stack&status=SOLVED
LINKED LIST
A Linked list is a linear data structure where elements(nodes) are stored at
non-contiguous memory locations. Each node contains data and a reference(or
pointer) to the next node.
NODE STRUCTURE
Data: The value or data the node
holds.
Pointer/Reference: Points to the next node in the
sequence.
TYPES OF LINKED LISTS:
Singly Linked List: Each node points to the next node in
the sequence. The last node points to null or None.
Doubly Linked List: Each node points to both the next
and the previous nodes, allowing traversal in both
directions.
Circular Linked List: The last node points back to the
first node, forming a circle.
BASIC OPERATIONS
Insertion: Adding a new node to the list
(beginning, end, or any position).
Deletion: Removing a node from the list
(beginning, end, or any position).
Traversal: Visiting all nodes in the list to access
or manipulate data.
Searching: Finding a node with a specific value.
1 2 3
Advantages Disadvantages
https://leetcode.com/problems/merge-nodes-in-between-zeros/description/?envType=problem-list-
v2&envId=linked-list
Intersection of two Linked List
https://leetcode.com/problems/intersection-of-two-linked-lists/description/?envType=problem-list-
v2&envId=linked-list
QUEUE
Defination
A queue is a type of data structure in which elements are
added at one end, called the rear, and removed from the other
end, called the front.
1.push_back(value)
2.pop_back()
3.size()
4.capacity()
5.resize(size)
6.at(index)
7.clear()
8.empty()
9.insert()
1 2 3 4 5 10.erase()
ITERATORS
Iterators are abstract pointers used to access and
traverse the elements of a data structure, such as
vectors, maps, sets, etc. in a consistent and controlled
manner.
Example
Declaration of vector iterator: - vector<int>::iterator;
Declaration of map iterator: - map<int,int>::iterator;
vec.begin() {Points to first element} and vec.end() {Points to
non-existent element which is next to last} are some of the
iterators known to us.
Iterate through the container:
for (auto it = v.begin() ; it != v.end() ; it++)
Questions
Numbers of recent calls
https://leetcode.com/problems/number-of-recent-calls/description/
front middle back queue
https://leetcode.com/problems/design-front-middle-back-queue/description/?envType=problem-
list-v2&envId=queue&difficulty=MEDIUM
Number of students unable to eat lunch
https://leetcode.com/problems/number-of-students-unable-to-eat-lunch/description/?
envType=problem-list-v2&envId=queue&difficulty=EASY
BINARY SEARCH
Binary search is a search algorithm used
to find the position on of a target value
within a sorted array.
https://leetcode.com/problems/find-the-smallest-divisor-given-a-threshold/description/
THANK
YOU