What is a Stack in Data Structure? A stack is a linear data structure that follows the Last In, First Out (LIFO) principle. This means the last element added to the stack is the first one to be removed. Imagine a stack of plates; you add a plate on top and remove the top plate first. CRead more
What is a Stack in Data Structure?
A stack is a linear data structure that follows the Last In, First Out (LIFO) principle. This means the last element added to the stack is the first one to be removed. Imagine a stack of plates; you add a plate on top and remove the top plate first.
Components of a Stack
1. Elements:
The items stored in the stack. These can be of any data type such as integers, characters, or objects.
2. Top:
A pointer or index that keeps track of the last added element in the stack. It helps in both adding (pushing) and removing (popping) elements.
3. Size (or Capacity):
The maximum number of elements the stack can hold. In dynamic implementations, the size can change, but in static implementations (like arrays), it is fixed.
4. Push Operation:
Adds an element to the top of the stack. Before pushing, it’s important to check if the stack is full to avoid overflow.
5. Pop Operation:
Removes the element from the top of the stack. Before popping, it’s important to check if the stack is empty to avoid underflow.
6. Peek (or Top) Operation:
Returns the top element of the stack without removing it. It’s useful when you want to see the top element but keep it in the stack.
7. isEmpty Operation:
Checks if the stack has no elements. This helps in preventing underflow during pop operations.
8. isFull Operation:
Checks if the stack is at its maximum capacity. This helps in preventing overflow during push operations.
Basic Stack Operations:-
1. def push(stack, element, size):
if len(stack) < size:
stack.append(element)
else:
print(“Stack Overflow”)
See less
SQL Injection: Arises when an attacker controls SQL queries by injecting malicious input. Mitigation Strategy: Use parameterized queries/prepared statements to ensure user inputs are treated as data rather than code Utilize stored procedures and ORM frameworks Cross-Site Scripting (XSS): It happensRead more
SQL Injection:
Arises when an attacker controls SQL queries by injecting malicious input.
Mitigation Strategy:
Cross-Site Scripting (XSS):
It happens when an attacker injects malicious scripts, leading to session hijacking, data theft and defacement of websites.
Mitigation Strategy:
Security Misconfiguration:
This threat results from Improper configuration of web servers, databases, and applications.
Mitigation Strategy:
Broken Authentication and Session Management:
Anomalies in authentication and session management can lead to unauthorized access to the database and data leakage.
Mitigation Strategy:
Man-in-the-Middle (MitM) Attack :
Occurs when attackers alter communications between clients and servers.
Mitigation Strategy:
Phishing:
Occurs when attackers cheat users providing sensitive data by impersonating legitimate websites or communications
Mitigation Strategy:
See less