Notes, summaries, assignments, exams, and problems for Computer science

Essential Computer Hardware and Software Components Explained

Computer science2.23 KB

Understanding Computer Hardware and Software

Hardware refers to the physical, electronic components of a computer that you can touch. Software is the general term used to describe all programs that run on computer hardware.

Core Hardware Components

  • Power Supply Unit (PSU): Supplies power to the computer by converting AC current to DC current. It also regulates voltage to eliminate spikes and surges.
  • Motherboard: The main printed circuit board in the computer, designed to connect all internal components together.
  • Microprocessor (CPU): An electronic circuit that processes programs, stores information, and performs calculations.
  • Chipset: A group of microcircuits that orchestrate data flow between key components, including the CPU, main memory, secondary
...
Continue reading "Essential Computer Hardware and Software Components Explained" »

SOA, Cloud Architecture and Computing Paradigms Explained

Computer science9.75 KB

Explain How Service-Oriented Architecture (SOA) Acts as a Technological Driver for Cloud Computing (10 Marks)

Service-Oriented Architecture (SOA) is a software design approach in which applications are built using independent, reusable services that communicate through standard interfaces.

Main Components of SOA

  • Service Provider: Creates and offers a service.

  • Service Consumer: Requests and uses the service.

  • Service Registry: Stores information about available services.

  • Service Contract: Defines the interface, rules, and communication requirements of a service.

  • Communication Protocol: Enables services to exchange information using technologies such as HTTP and web APIs.

SOA Architecture

Service Consumer
Requests a service

Service Interface / Communication

Service...

Continue reading "SOA, Cloud Architecture and Computing Paradigms Explained" »

Heap Sort Algorithms in Python: Examples and Implementations

Computer science4.58 KB

a = ['z', 'y', 'x', 'w', 'v', 't', 's', 'r', 'q', 'p', 'n', 'm', 'l', 'k', 'j', 'h', 'g', 'f', 'd', 'c', 'b', 'u', 'o', 'i', 'e', 'a']

n = int(input())
h = []
for i in input():
h.append(a.index(i))

def heapify(heap, i, n):
l = 2*i + 1
r = 2*i + 2
minid = i
if l < n and heap[l] < heap[minid]:
minid = l
if r < n and heap[r] < heap[minid]:
minid = r
if minid != i:
heap[i], heap[minid] = heap[minid], heap[i]
heapify(heap, minid, n)

def hs(heap):
n = len(heap)
for i in range(n // 2 - 1, -1, -1):
heapify(heap, i, n)
for i in range(n - 1, 0, -1):
heap[0], heap[i] = heap[i], heap[0]
heapify(heap, 0, i)

hs(h)
print(''.join(a[i] for i in h))


import sys

def solve():
data...

Continue reading "Heap Sort Algorithms in Python: Examples and Implementations" »

Computer Hardware, Operating Systems and Databases: Key Concepts Explained

Computer science2.69 MB

 System Hardware & Software Architecture

1.1.1 Computer Hardware: Internal Components and the Input–Process–Output Model

A computer can be understood as an Input → Process → Output (I-P-O) system: it accepts raw data, works on it, and produces a result.

  • Input Unit: devices that feed data and instructions into the computer, e.g. keyboard, mouse, scanner.
  • Central Processing Unit (CPU): the “brain” of the computer; it fetches, decodes and executes instructions. It has three main parts — the Control Unit, the Arithmetic Logic Unit and the Registers.
    • Control Unit (CU): directs and coordinates the activities of all other units; it does not process data itself.
    • Arithmetic Logic Unit (ALU): performs arithmetic operations (+, −, ×, ÷)
...
Continue reading "Computer Hardware, Operating Systems and Databases: Key Concepts Explained" »

C++ Priority Queue Solutions: Greedy Algorithms and Heap Examples

Computer science4.6 KB

C++ Priority Queue Examples

The following code samples demonstrate how to use the priority_queue container from the C++ Standard Template Library (STL) to solve common greedy and heap-based problems.

1. Minimum Cost to Merge Ropes (Huffman-style)

This program repeatedly merges the two smallest values using a min-heap and accumulates the total cost.

#include <iostream>
#include <queue>
#include <vector>
using namespace std;

int main() {
int n;
cin >> n;

priority_queue<long long, vector<long long>, greater<long long>> q;
for (int i = 0; i < n; i++) {
long long x;
cin >> x;
q.push(x);
}

long long ans = 0;
while (q.size() > 1) {
long long a = q.top();...

Continue reading "C++ Priority Queue Solutions: Greedy Algorithms and Heap Examples" »

Operating System Concepts: Functions, Types, and Processes

Computer science117.7 KB

What is an Operating System?

An Operating System (OS) is system software that acts as an interface between the user and computer hardware. It manages the hardware and software resources of a computer and provides an environment for running application programs.

Examples: Windows, Linux, macOS, Android, and Unix.

Basic Structure of an OS

        User
          ↓
   Application Programs
          ↓
    Operating System
          ↓
       Hardware

Major Functions of an Operating System

  1. Process Management: The OS manages the creation, execution, scheduling, and termination of processes.
  2. Memory Management: It manages the main memory (RAM) and allocates or deallocates memory to different processes.
  3. File Management: It manages files and directories,
...
Continue reading "Operating System Concepts: Functions, Types, and Processes" »

Essential C Programming Exam Questions and Solutions

Computer science37.36 KB

x4jbIeyLsADAAAAAElFTkSuQmCC

Store Fibonacci Series in an Array

Exam Source: 2024 Q6(b)

Note: fib[0]=0, fib[1]=1, fib[i] = fib[i-1] + fib[i-2] for i >= 2.

#include <stdio.h>

int main() {
    int n, i;
    printf("How many terms? ");
    scanf("%d", &n);
    int fib[n];
    fib[0] = 0;
    if (n > 1) fib[1] = 1;
    for (i = 2; i < n; i++)
        fib[i] = fib[i-1] + fib[i-2];
    printf("Fibonacci series: ");
    for (i = 0; i < n; i++)
        printf("%d ", fib[i]);
    return 0;
}

Dynamic Memory Allocation and Average Calculation

Exam Source: 2024 Q7(c) / 2025 Q6(a) — Repeated both years!

Note: malloc returns void*, cast to int*. Always free() after use. If malloc returns NULL, memory allocation failed.

#include <stdio.h>
#include <stdlib.h&
...
Continue reading "Essential C Programming Exam Questions and Solutions" »

Essential Web Development: JavaScript, jQuery, and CSS Tips

Computer science4.31 KB

Use of Alert Box

An alert box is a JavaScript popup dialog box used to display messages or warnings to the user.

Uses of Alert Box

  • To display information messages
  • To show warning messages
  • To show error messages in form validation
  • To notify users about system events
  • Used for debugging purposes

JavaScript Program using RegExp Object

Definition: A Regular Expression (RegExp) is an object used to define a search pattern and perform matching operations on strings.

let text = "My email is [email protected]";
let pattern = /[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/;
let result = text.match(pattern);
if(result) { alert("Email found: " + result); } else { alert("No email found"); }

HTML and JavaScript Prompt Demo

<!DOCTYPE html>
<html>
<head&
...
Continue reading "Essential Web Development: JavaScript, jQuery, and CSS Tips" »

JavaScript Regular Expressions and Type Conversion

Computer science7.08 KB

Introduction to Regular Expressions

A Regular Expression (often abbreviated as RegExp or regex) is a sequence of characters that forms a search pattern. This pattern can be used for text search, text replace, and data validation operations.

In JavaScript, regular expressions are objects. You can create a RegExp object in two ways:

  • Using a RegExp Literal (Recommended): The pattern is enclosed between forward slashes.
    const regex = /pattern/modifiers;
  • Using the RegExp Constructor:
    const regex = new RegExp('pattern', 'modifiers');
    

RegExp Modifiers and Flags

Modifiers change how a regular expression searches text. They are appended to the end of the regex literal (e.g., /abc/g) or passed as the second argument to the constructor.

ModifierDescription
iCase-
...
Continue reading "JavaScript Regular Expressions and Type Conversion" »

Efficient AVL Tree Implementation in C++

Computer science4.53 KB

Node Class Structure

The Node class defines the structure for each element in the AVL tree, storing a key, its corresponding meaning, and pointers to child nodes.

class Node {
public:
    string key, meaning;
    Node *lft, *right;
    int h8;
    Node(string k, string m) {
        key = k;
        meaning = m;
        lft = right = NULL;
        h8 = 1;
    }
};

AVL Tree Class Definition

The AVL class contains the logic for maintaining a self-balancing binary search tree.

Helper Functions for Balancing

These utility functions manage node height (h8), calculate the balance factor, and determine the maximum of two values.

class AVL {
    Node* root;
    int h(Node* n) { if (n == NULL) return 0; return n->h8; }
    int bal(Node* n) { if (n == NULL)
...
Continue reading "Efficient AVL Tree Implementation in C++" »