Data Structure Notes 1ST Sem
Data Structure Notes 1ST Sem
• size()- returns the size of the queue. • IsEmpty - Check if the queue is
Binabalik nya lang yung suze ng queue empty.
natin, ilan yung lamang ng pila natin as
of the moments. • IsFull -Check if the queue is full
• The methods of the Queue interface THE TWO MAIN QUEUE OPERATION
from the java.util package are used to
implement queues in Java. Since Method in Java:
• offer() Queue queue = new
LinkedList(); Functions Java Python
• Example: queue = deque([]) if not FI-LO (FIRST IN, LAST OUT) – kung
queue: print("Queue is empty.") ano yung unang pumasok, sya ang
huling lalabas
OTHER QUEUE METHODS
STACK OPERATION
• Java methods offer(), poll(), and peek() Push()- Inserts data on top of the stack
do not throw exceptions. The methods – magdadagdag ng data sa top ng stack
add(), remove(), and element() perform nagpataong lang
the same tasks but throw exceptions. Pop()- Removes data on top of the stack
– nag dedelete tayo ng data sa taas ng
• Other methods that can be used for stack, aalsin lang natin yung data sa
both queues and lists are the following: pinakataas
isEmpty() – Checks if stack is empty – - Push - adds an item to the top of
chinecheck nya lang kung walang the stack
laman. Pag negative 1 ang top index - Pop - removes an item from the
meaning walang laman top of the stack
- Peek - looks at the item at the top
isFull() – checks if stacks is full – of the stack without removing it
chinecheck lang if puno na yung stack. from the stack.
Nasa pinakataas ng index natin
Stack Applications
Peek () – returns the data at the top of
the stack. Kung anong data yung nasa Finding palindromes:
taas ng stack natin currently irereturn
yun. ◦A palindrome is a string that reads the
same in either direction.
Size() – returns the size of the stacks.
Ilan ang value na nasa loob ng stack. ◦ Ex. level, radar, civic Evaluating a
postfix expression:
PPT NOTES:
◦A normal expression is in infix notation.
Fundamentals
◦In a postfix expression, the operands
•During program execution, the stack (variable or number) precede the
can be used to store information about operators (symbol).
the parameters and return points for all
the methods that are currently INFIX example: (yung maayos na
executing. expression)
- A+B
•Stacks are used by compilers to store - A+B*C
information while evaluating
POSTFIX example : (hindi nakaayos yung
expressions.
expression)
- AB+
•The methods of the Stack class from - ABC*+
the java.util package are used to
implement stacks in Java.
Rules of INFIX:
The list methods are used to implement Algorithm:
stacks in Python.
1. Classify the token (operand or operator).
The two (2) main stack operations are 2. If token is an operand, push it to the stack.
the following:
5. Repeat Steps 1 to 4 until the last
3. If token is an operator, perform two (2) pop token.
operations.
3. If token is an operator,
NODES
• The following are the different traversal • Other Java methods used in retrieving
types: values from a tree are:
• Depth-First
Programming Trees
• To create a tree with identified root • Max Heap – The value of each parent
node: node is greater than or equal to the
- JTree tree = new JTree(root); values of its child nodes.
• Collections.addAll(minHeap, 1, 7, 6, 8, EXTRACT-MAX/MIN
9); • Explanation: The root node is
always at index 0. Its child nodes are •Extract-Max returns the node with
always at index 1 and index 2. Indices 3, maximum value after removing it from a
4, 5, and 6 can store the child nodes of Max Heap whereas Extract-Min returns
those two (2) nodes and so on. the node with minimum after removing it
from Min Heap
HEAPS
PRIORTY QUEUES
•To determine the root node, use the
get() method. • A priority queue is a special type of
queue where elements are processed
•Example: based on their order (natural or custom).
System.out.print(minHeap.get(0));
• Priority queues can be implemented in
HEAPS OPERATIONS Java using the PriorityQueue class from
the java.util package.
•Heapify – PAG SSWAP
•Insert Element into Heap • Example:
PriorityQueue printer = new
•Delete Element from Heap PriorityQueue<>();
•Peek (Find max/min)
▪ A set is a collection of elements where
each element is unique.
BROCODE YT
▪ Common set operations:
▪ containsALL – return true if the set ▪ Each key can map to only one
contains all the elements of the
specified collection
Maps Interfaces
▪ hashCODE() – hash the code value
▪ Sorted Map
▪ Concurrent Map