CUET Computer notes
CUET Computer notes
Introduction to Database Concepts
● Domain: Defines the set of possible values for an attribute. Example: A "Date of
Birth" field has a domain of valid date values.
● Tuple: A single entry in a table, representing a record with multiple attributes.
● Relation: A table storing structured data, with each column representing an
attribute.
Additional Concepts
Introduction to SQL
● High Speed: SQL allows quick access and manipulation of large datasets.
● Ease of Use: Simple syntax makes learning and usage accessible.
● Data Integrity: Ensures accuracy and consistency with constraints like PRIMARY
KEY, FOREIGN KEY.
● Security: Supports authentication, access control, and encryption.
● Scalability: Works efficiently across small to enterprise-level databases.
Introduction to MySQL
●
Dropping a Table:
sql
DROP TABLE employees;
●
Altering a Table:
sql
ALTER TABLE employees ADD COLUMN age INT;
●
●
Filtering Data:
sql
SELECT * FROM employees WHERE age > 30;
●
●
Updating Data:
sql
UPDATE employees SET salary = 70000 WHERE id = 1;
●
Deleting Records:
sql
DELETE FROM employees WHERE id = 1;
●
Mathematical Functions
Text Functions
● Case Conversion:
○ UCASE() / UPPER() → Converts text to uppercase.
○ LCASE() / LOWER() → Converts text to lowercase.
● Substring Manipulation:
○ MID(str, start, length) / SUBSTRING(str, start,
length) → Extracts a portion of a string.
● Length and Position:
○ LENGTH(str) → Returns number of characters in a string.
○ LEFT(str, n) → Extracts first n characters.
○ RIGHT(str, n) → Extracts last n characters.
○ INSTR(str, sub_str) → Finds position of substring in string.
● Trimming Spaces:
○ LTRIM(str) → Removes leading spaces.
○ RTRIM(str) → Removes trailing spaces.
○ TRIM(str) → Removes both leading and trailing spaces.
SQL provides several functions to handle date and time values efficiently:
●
●
●
●
YEAR() → Extracts the year from a date.
sql
SELECT YEAR('2025-05-13'); -- Output: 2025
●
●
●
Aggregate functions perform calculations on a set of values and return a single value:
●
●
●
SUM() → Computes the total sum.
sql
SELECT SUM(salary) FROM employees;
●
●
GROUP BY
Used to group records that have the same values in specified columns:
sql
SELECT department, AVG(salary) FROM employees GROUP BY department;
HAVING
sql
SELECT department, AVG(salary) FROM employees
GROUP BY department
HAVING AVG(salary) > 50000;
ORDER BY
sql
SELECT name, salary FROM employees ORDER BY salary DESC;
Operations on Relations
Union
sql
SELECT name FROM employees
UNION
SELECT name FROM managers;
Intersection (Not natively supported in MySQL, but can be simulated using INNER
JOIN)
sql
SELECT name FROM employees
INNER JOIN managers USING(name);
Minus (Difference) (Not directly supported in MySQL, but can be simulated using
NOT IN)
sql
SELECT name FROM employees
WHERE name NOT IN (SELECT name FROM managers);
Cartesian Product
sql
SELECT * FROM employees, departments;
JOIN Operations
●
LEFT JOIN → Returns all records from the left table and matching records from the right
table.
sql
SELECT employees.name, departments.dept_name
FROM employees
LEFT JOIN departments ON employees.dept_id = departments.dept_id;
●
RIGHT JOIN → Returns all records from the right table and matching records from the
left table.
sql
SELECT employees.name, departments.dept_name
FROM employees
RIGHT JOIN departments ON employees.dept_id = departments.dept_id;
●
FULL JOIN (Not supported in MySQL, but can be simulated using UNION)
sql
SELECT employees.name, departments.dept_name
FROM employees LEFT JOIN departments ON employees.dept_id =
departments.dept_id
UNION
SELECT employees.name, departments.dept_name
FROM employees RIGHT JOIN departments ON employees.dept_id =
departments.dept_id;
A computer network is a system that allows computers and other devices to communicate
and share resources. Over time, networking has evolved from simple direct connections
to complex global structures like the internet.
Network Types
● LAN (Local Area Network): Small-scale, limited to a single location like homes,
offices, or schools.
● WAN (Wide Area Network): Large-scale network covering vast geographical
areas, e.g., the internet.
● MAN (Metropolitan Area Network): Covers a city or large campus, bigger
than LAN but smaller than WAN.
Network Devices
● Modem: Converts digital signals to analog for transmission over phone lines.
● Ethernet Card: Also called a network interface card (NIC), enables
communication between computers.
● Repeater: Boosts signals for long-distance transmission.
● Hub: Connects multiple devices in a network but doesn’t filter data.
● Switch: Similar to a hub but smarter, as it directs data efficiently.
● Router: Connects different networks, including home networks to the internet.
● Gateway: Allows communication between networks using different protocols.
Network Topologies
1. Standalone Computers: Early computers were isolated and used for specific
tasks.
2. Local Networks (LANs): Computers in offices, schools, and businesses were
connected to share data.
3. Wide Networks (WANs): Organizations with multiple locations established
interconnected systems.
4. The Internet: A global network connecting millions of computers worldwide.
5. Wireless & Mobile Networks: The rise of Wi-Fi, cellular networks, and
cloud-based services made networking more accessible.
Types of Networks
1. Modem:
○ Converts digital signals into analog for communication over telephone
lines.
○ Required for broadband internet services.
2. Ethernet Card (NIC - Network Interface Card):
○ Enables communication between computers and networks.
○ Available as wired (Ethernet) and wireless (Wi-Fi) versions.
3. Repeater:
○ Boosts signal strength to extend network coverage.
○ Used in long-distance communications.
4. Hub:
○ Simple device that connects multiple devices in a network.
○ Broadcasts data to all connected devices (less efficient than a switch).
5. Switch:
○ Smarter than a hub; directs data to the intended recipient.
○ Improves network performance and reduces congestion.
6. Router:
○ Connects different networks, such as a home LAN to the internet.
○ Routes data based on IP addresses.
7. Gateway:
○ Allows communication between networks using different protocols.
○ Functions like a bridge between incompatible systems.
Network Topologies
MAC and IP addresses help identify devices in a network but serve different purposes:
Key Difference:
● MAC Address remains constant, while IP Address can change based on the
network.
Although often used interchangeably, the Internet and Web are distinct:
1. Internet:
○ The vast global network connecting millions of devices.
○ Provides infrastructure for services like email, cloud computing, and social
media.
2. Web (World Wide Web):
○ A service that runs on the internet, providing websites and online
applications.
○ Uses protocols like HTTP/HTTPS to access information.
● Syntax Errors: Occur due to incorrect Python syntax. The interpreter halts
execution.
Example:
python
print("Hello" # Missing closing parenthesis → SyntaxError
○
● Exceptions: Errors that occur during execution, disrupting program flow.
Example:
python
result = 10 / 0 # ZeroDivisionError
○
Handling Exceptions
python
try:
num = int(input("Enter a number: "))
result = 10 / num
except ZeroDivisionError:
print("Cannot divide by zero!")
except ValueError:
print("Invalid input! Enter a number.")
python
try:
num = int(input("Enter a number: "))
result = 10 / num
except ZeroDivisionError:
print("Cannot divide by zero!")
else:
print(f"Result: {result}")
python
try:
file = open("data.txt", "r")
content = file.read()
finally:
file.close() # File is closed regardless of errors
User-Defined Exceptions
python
class MyException(Exception):
pass
try:
raise MyException("This is a custom exception")
except MyException as e:
print(e)
Types of Files
python
file = open("example.txt", "r") # Open in read mode
file.close() # Close the file
Modes:
●
Reading from a file:
python
with open("data.txt", "r") as file:
content = file.read()
print(content)
●
●
●
A Stack is a linear data structure that follows the LIFO (Last In, First Out) principle,
meaning the last element added is the first one to be removed.
Characteristics of Stack:
python
stack = [] # Initialize an empty stack
stack.append(10) # Push operation
stack.append(20)
print(stack) # Output: [10, 20]
python
stack.pop() # Removes 20
print(stack) # Output: [10]
●
●
python
class Stack:
def __init__(self):
self.stack = [] # Using a list as a stack
def pop(self):
if not self.is_empty():
return self.stack.pop() # Removes top item
return "Stack is empty!"
def peek(self):
if not self.is_empty():
return self.stack[-1] # Returns top item
return "Stack is empty!"
def is_empty(self):
return len(self.stack) == 0
def display(self):
print(self.stack)
# Example usage
s = Stack()
s.push(5)
s.push(10)
print(s.peek()) # Output: 10
s.pop()
s.display() # Output: [5]
Expression Notations
The Postfix notation is ideal for stack-based evaluation because operations can be
directly processed without needing parentheses.
Example: Evaluating 2 3 + 5 *
Steps:
1. Push 2, push 3 → Stack: [2, 3]
2. Encounter +, pop 2 and 3, compute 2+3=5, push 5 → Stack: [5]
3. Push 5 → Stack: [5, 5]
4. Encounter *, pop 5 and 5, compute 5*5=25, push 25 → Stack: [25]
5. Final result: 25
Python Implementation:
python
def evaluate_postfix(expression):
stack = []
for char in expression.split():
if char.isdigit(): # If operand, push onto stack
stack.append(int(char))
else: # If operator, pop two operands and apply operation
b = stack.pop()
a = stack.pop()
if char == '+':
stack.append(a + b)
elif char == '-':
stack.append(a - b)
elif char == '*':
stack.append(a * b)
elif char == '/':
stack.append(a / b)
return stack.pop() # Final result
# Example usage
expression = "2 3 + 5 *"
print(evaluate_postfix(expression)) # Output: 25
Steps:
Python Implementation:
python
def infix_to_postfix(expression):
precedence = {'+': 1, '-': 1, '*': 2, '/': 2}
output = []
stack = []
while stack:
output.append(stack.pop())
# Example usage
expression = "(A + B) * C"
print(infix_to_postfix(expression)) # Output: "A B + C *"
Conclusion
● Stacks are useful for handling expressions and implementing LIFO operations.
● Postfix notation simplifies arithmetic evaluation.
● Infix to postfix conversion uses stack-based precedence rules.
A Queue is a linear data structure that follows the FIFO (First In, First Out) principle,
meaning the first element added to the queue is the first one to be removed.
Characteristics of Queue:
Operations on Queue
1. INSERT (Enqueue)
python
queue = [] # Initialize an empty queue
queue.append(10) # Enqueue operation
queue.append(20)
print(queue) # Output: [10, 20]
2. DELETE (Dequeue)
python
queue.pop(0) # Dequeue operation, removes 10
print(queue) # Output: [20]
Peek (Front Element): View the front element without removing it.
python
front_element = queue[0] # Access first element
print(front_element)
●
Check if Queue is Empty:
python
if not queue:
print("Queue is empty!")
●
Python provides a built-in list structure that can be used to implement queues efficiently.
python
class Queue:
def __init__(self):
self.queue = [] # Using a list as a queue
def dequeue(self):
if not self.is_empty():
return self.queue.pop(0) # Removes first item
return "Queue is empty!"
def peek(self):
if not self.is_empty():
return self.queue[0] # Returns first item
return "Queue is empty!"
def is_empty(self):
return len(self.queue) == 0
def display(self):
print(self.queue)
# Example usage
q = Queue()
q.enqueue(5)
q.enqueue(10)
print(q.peek()) # Output: 5
q.dequeue()
q.display() # Output: [10]
A Deque (Double-Ended Queue) is a more flexible data structure where elements can
be added or removed from both ends.
Operations in Deque
python
from collections import deque
# Initialize deque
dq = deque()
# Inserting elements
dq.append(10) # Insert at rear
dq.appendleft(5) # Insert at front
print(dq) # Output: deque([5, 10])
# Removing elements
dq.pop() # Remove from rear
dq.popleft() # Remove from front
print(dq) # Output: deque([])
Conclusion
Introduction to Searching
Searching is the process of finding an element within a collection of data. It is one of the
fundamental operations in computer science and is used in various applications like
databases, information retrieval, and artificial intelligence.
Each algorithm has different time complexities, which determine their efficiency based
on data size.
Sequential search checks each element in a list one by one until the desired element is
found or the list ends.
Algorithm:
Python Implementation:
python
def linear_search(arr, target):
for index, value in enumerate(arr):
if value == target:
return index # Return the position of the target
return -1 # Target not found
# Example Usage
arr = [10, 20, 30, 40, 50]
target = 30
print(linear_search(arr, target)) # Output: 2
Linear search is inefficient for large datasets, but useful for unsorted data.
2. Binary Search
Binary search is a faster algorithm but requires a sorted list. It repeatedly divides the
search space in half until the target element is found.
Algorithm:
1. Set the left and right pointers to the first and last elements.
2. Compute the middle index.
3. Compare the middle element with the target.
4. If the middle element matches the target, return the index.
5. If the target is less than the middle element, search the left half.
6. If the target is greater, search the right half.
7. Repeat until the target is found or the search space is empty.
Python Implementation:
python
def binary_search(arr, target):
left, right = 0, len(arr) - 1
# Example Usage
arr = [10, 20, 30, 40, 50]
target = 30
print(binary_search(arr, target)) # Output: 2
Binary search is much faster than linear search, especially for large datasets.
Sequential Search:
Worst Case for Binary Search (Searching for 5 in [10, 20, 30, 40, 50]):
Sorting Algorithms
Sorting helps organize data in a structured manner, making operations like searching
more efficient. Let's explore the sorting techniques in greater detail.
Step-by-Step Explanation:
Initial [5, 3, 8, 1, 2]
Time Complexity:
Intuition: Imagine selecting the smallest element and placing it at the beginning
repeatedly.
Step-by-Step Explanation:
Initial [5, 3, 8, 1, 2]
Selection Sort always performs O(n²) swaps, even if the array is sorted.
Intuition: Think of sorting playing cards in your hand—placing each card in the right
position one by one.
Step-by-Step Explanation:
Initial [5, 3, 8, 1, 2]
Insert [3, 5, 8, 1, 2] (shift 5, insert 3)
3
Time Complexity:
Bubble Sort and Selection Sort are slow (O(n²)), whereas Insertion Sort works well for
small lists or nearly sorted lists.
Hash Functions
A hash function converts an input (like a name) into a unique numeric index.
Example:
python
hash_value = hash("Alice") % 10
print(hash_value) # Returns an index between 0-9
1. Open Addressing: Store the new element in the next available slot.
2. Chaining: Use a linked list at each index to store multiple elements.
# Retrieve values
print(hash_table["name"]) # Output: Alice
Final Thoughts
Sorting techniques like Bubble, Selection, and Insertion Sort organize data
efficiently. Meanwhile, hashing enables fast searches.
1. What is Data?
Data is raw information that can be collected, stored, and analyzed to extract meaningful
insights. It exists in various forms:
Purpose of Data
Data serves multiple roles: ✔ Decision Making – Businesses use data for strategic
planning. ✔ Scientific Analysis – Researchers use data for experiments. ✔
Prediction & Forecasting – AI models predict trends using historical data.
Organizing Data
Mean (Average)
mean= 5+10+15/3
Formula:
Example: For [2, 4, 6, 8], standard deviation will show variation from the mean.
Variance quantifies how far numbers are from the mean. Formula:
Variance=(Standard Deviation)^2
4. Data Interpretation
Data interpretation involves analyzing patterns, trends, and anomalies.
The relational model organizes data into tables (relations). It was introduced by E. F.
Codd in 1970.
Key Terms in the Relational Model
Primary Key The selected candidate key (must be unique and not
NULL)
Alternate Key Candidate keys that are not selected as primary keys
Foreign Key A column that references the primary key of another table
●
Student_ID is the Primary Key (PK) → Unique for each student.
● Course_ID is a Foreign Key (FK) → Links to another table.
4. Relational Algebra
Structured Query Language (SQL) is widely used for managing relational databases. Key
benefits include:
2. SQL Classification
sql
CREATE DATABASE SchoolDB;
USE SchoolDB;
Creating a Table
sql
CREATE TABLE Students (
StudentID INT PRIMARY KEY,
Name VARCHAR(50),
Age INT,
Course VARCHAR(50)
);
Data Types in MySQL
Data Description
Type
Math Functions
sql
SELECT POWER(2,3), ROUND(15.678,2), MOD(10,3);
● POWER(2,3) → 2³ = 8
● ROUND(15.678,2) → 15.68
● MOD(10,3) → 1 (remainder when 10 ÷ 3)
Text Functions
sql
SELECT UCASE('hello'), LCASE('WORLD'), SUBSTRING('database', 3, 4);
● UCASE('hello') → HELLO
● LCASE('WORLD') → world
● SUBSTRING('database', 3, 4) → taba (Extracts from position 3 for 4
characters)
Date Functions
sql
SELECT NOW(), MONTHNAME('2025-05-13'), YEAR('2024-12-01');
5. Aggregate Functions
sql
SELECT MAX(Age), MIN(Age), AVG(Age), SUM(Age), COUNT(*) FROM Students;
7. Operations on Relations
Union
sql
SELECT Name FROM Students
UNION
SELECT Name FROM Alumni;
Intersection
sql
SELECT Name FROM Students
INTERSECT
SELECT Name FROM Alumni;
Minus (Difference)
sql
SELECT Name FROM Students
EXCEPT
SELECT Name FROM Alumni;
Cartesian Product
JOIN
sql
SELECT Students.Name, Courses.CourseName
FROM Students
JOIN Courses ON Students.CourseID = Courses.CourseID;
Final Thoughts
Evolution of Networking
LAN (Local Area Network) Small-scale (home, office, Wi-Fi networks in homes
school)
3. Network Devices
Device Function
4. Network Topologies
Ring Devices form a circular Easy to install Failure at one point affects
path the network
Definitio A global network connecting millions A service that runs on the internet
n of computers
Function Provides infrastructure for data Enables websites, browsing, and
transmission online services
Example Email, online gaming, cloud storage Websites, search engines, social
s media
1. Concept of Communication
Data communication refers to the transfer of digital information between two or more
devices. It is essential for networking, internet functionality, and wireless systems.
2. Switching Techniques
3. Communication Media
Wired Technologies
Technology Description
Wireless Technologies
Technology Description
5. Network Protocols
A protocol is a set of rules that governs communication between devices.
Common Protocols
Channel
Bandwidth
Final Thoughts
Various threats can compromise computer security. Here’s an overview of the most
common ones and how to prevent them:
Viruses
● What? A virus is malicious software that attaches to files and spreads when
executed.
● Prevention: Use antivirus software, avoid suspicious downloads, and regularly
update your system.
Worms
● What? Worms replicate themselves across networks without needing user action.
● Prevention: Enable firewalls, regularly scan for threats, and block unauthorized
access.
Trojan Horse
● What? A Trojan horse disguises itself as legitimate software but contains harmful
code.
● Prevention: Verify downloads, avoid pirated software, and use antimalware
tools.
Spam
Cookies
● What? Small files stored on your computer that track browsing data.
● Prevention: Manage cookies in browser settings, use private browsing, and
delete unnecessary cookies.
Adware
● What? Software that shows excessive advertisements, often bundled with free
programs.
● Prevention: Use ad blockers, avoid clicking on intrusive ads, and scan software
before installation.
Firewall
● What? A security barrier that filters network traffic to protect against threats.
● Prevention: Activate firewall settings, configure inbound and outbound rules
carefully.
HTTP vs HTTPS
Firewall
What is Antivirus?
How It Works
Intrusion Problems
Eavesdropping
Final Thoughts