Notes, summaries, assignments, exams, and problems for Computers

Sort by
Subject
Level

C Implementations of Core Sorting Algorithms

Posted by Anonymous and classified in Computers

Written on in English with a size of 3 KB

Fundamental Sorting Algorithms in C

This document provides standard C implementations for three essential comparison-based sorting algorithms: Merge Sort, Quick Sort, and Heap Sort. These examples demonstrate the core logic and structure of each algorithm.

Merge Sort Implementation

Merge Sort is a stable, divide-and-conquer algorithm known for its consistent O(n log n) time complexity.

#include <stdio.h>

void merge(int a[], int l, int m, int r) {
    int i=l, j=m+1, k=0, b[100];
    while(i<=m && j<=r) {
        if(a[i]<a[j]) b[k++]=a[i++];
        else b[k++]=a[j++];
    }
    while(i<=m) b[k++]=a[i++];
    while(j<=r) b[k++]=a[j++];
    for(i=l,k=0;i<=r;i++,k++) a[i]=b[k];
}

void mergesort(int a[], int l, int
... Continue reading "C Implementations of Core Sorting Algorithms" »

Operating System Concepts: Memory, Deadlocks, and I/O

Posted by Anonymous and classified in Computers

Written on in English with a size of 16.84 KB

Memory Models in Operating Systems

  • Model A (MS-DOS):
    • Structure: Large user space at the top, small RAM at the bottom.
    • Performance: Fast execution, long boot time.
    • Protection: No protection.
  • Model B:
    • Structure: Small ROM at the top, small user space at the bottom.
    • Performance: Protected OS but slow (the entire OS must be read).
    • Flexibility: Not flexible.
  • Model C (Windows 11):
    • Structure: Select drivers at the top, large user space in the middle, RAM at the bottom.
    • Performance: Fast and secure (key drivers stored in ROM).

Memory Protection and Management

Core Memory Management Issues

  • Relocation Problem: Without memory abstraction, loading multiple programs causes incorrect memory addresses.
  • Base and Limit Registers:
    • Base: Value added to addresses to find
... Continue reading "Operating System Concepts: Memory, Deadlocks, and I/O" »

Mastering C Pointers, Structures, and Unions

Posted by Anonymous and classified in Computers

Written on in English with a size of 8.51 KB

Pointers in C

A pointer is a variable that stores the memory address of another variable. They are essential in C for dynamic memory allocation, array manipulation, and implementing complex data structures.

1. Declaring and Initializing Pointers

A pointer variable must be declared to hold the address of a specific data type.

A. Declaration

The asterisk (*) is the dereference operator or value-at-address operator. When declaring a pointer, it signifies that the variable is a pointer to a specific type.

data_type *pointer_name;
  • Example: int *ip; // Declares ip as a pointer that can hold the address of an integer variable.

B. Initialization

A pointer is initialized by assigning it the address of a variable using the address-of operator (&).

int num
... Continue reading "Mastering C Pointers, Structures, and Unions" »

Sorting Algorithms and Hashing Techniques

Posted by Anonymous and classified in Computers

Written on in English with a size of 1.17 MB

Sorting

Stable vs In-Place

Stable: The relative order of elements with the same key value is preserved by the algorithm.

If after the first sort, an element is at its final position and subsequent iterations do not change its position, it is considered stable.

In-Place: Requires only a constant amount, i.e., O(1), of extra space during the sorting process.

Assigning a temporary variable takes up a small amount of constant space but is still counted as in-place.

sy6xAAAAABJRU5ErkJggg==

tjMaqeYQAAAABJRU5ErkJggg==

Sorting Explanations

Merge Sort: For arrays, it requires significant space, but for Linked Lists, due to pointer manipulations, it does not require extra space.

Selection Sort: In each iteration, find the smallest element and swap it with the first index. Subsequent iterations process n-1 elements... Continue reading "Sorting Algorithms and Hashing Techniques" »

Key Concepts: Node.js Modules, Express Routing, Body Parser

Classified in Computers

Written on in English with a size of 6.67 KB

Understanding Node.js Modules & Core Functionality

In Node.js, modules are fundamental. They represent reusable blocks of code that can be exported from one file and imported into another, promoting a modular and organized application structure. Node.js features a built-in module system, allowing developers to utilize core modules, create custom modules, or integrate third-party modules.

Core Modules in Node.js

Core modules are pre-packaged with Node.js, offering essential functionalities for common tasks like file system operations, HTTP request handling, and path manipulation.

Some commonly used core modules in Node.js are:

  • fs (File System): For interacting with the file system.
  • http (HTTP): For creating HTTP servers and clients.
  • path (Path)
... Continue reading "Key Concepts: Node.js Modules, Express Routing, Body Parser" »

Python String Methods and Iteration Techniques

Posted by Anonymous and classified in Computers

Written on in English with a size of 4.56 KB

Essential Python String Manipulation Methods

1. strip()

  • Purpose: Removes any leading (start) and trailing (end) whitespace or specified characters from a string.
  • Example: " hello ".strip()"hello"
  • Use Case: Useful for cleaning input data.

2. ljust(width)

  • Purpose: Left-justifies the string in a field of given width, padding with spaces on the right.
  • Example: "Hi".ljust(5)"Hi "
  • Use Case: Formatting output neatly.

3. rindex(substring)

  • Purpose: Returns the last occurrence index of the given substring in the string. Raises an error if the substring is not found.
  • Example: "hello world".rindex("o")7
  • Use Case: Finding positions of characters or words starting from the end of the string.

4. isspace()

  • Purpose: Returns True if the string contains
... Continue reading "Python String Methods and Iteration Techniques" »

IoT Protocols, Communication Models, & Deployment Strategies

Classified in Computers

Written on in English with a size of 1.64 MB

IoT Protocols

Link Layer Protocols

  • 802.3 Ethernet Standards

    A collection of wired Ethernet standards that provide data rates from 10 Mb/s to 40 gigabits per second. The shared medium in Ethernet can be a coaxial cable, twisted-pair wire, or optical fiber. This shared medium carries communication for all devices on the network.

  • 802.11 Wi-Fi Standards

    A collection of wireless Local Area Network (WLAN) communication standards.

Network/Internet Layer

  • Responsible for sending IP datagrams from the source network to the destination network.
  • Handles host addressing and packet routing based on IPv4 or IPv6.
  • Datagrams contain a source and destination address, which are used to route them from the source to the destination across multiple networks.
  • IPv4 uses 32-
... Continue reading "IoT Protocols, Communication Models, & Deployment Strategies" »

Blockchain Cryptography: ECC, Hashing, and Consensus

Posted by Anonymous and classified in Computers

Written on in English with a size of 19.16 KB

Elliptic Curve Cryptography (ECC) in Blockchain

Elliptic Curve Cryptography (ECC) is a public-key cryptography technique based on the mathematics of elliptic curves over finite fields. It is widely used in blockchain systems such as Bitcoin and Ethereum for generating secure public-private key pairs and digital signatures. The main advantage of ECC is that it provides high security with smaller key sizes, making it faster and more efficient.

The Mathematical Equation of ECC

The general equation of an elliptic curve is:

y2 = x3 + ax + b

  • a and b are constants that define the shape of the curve.
  • The curve is defined over a finite field Fₚ (where p is a prime number) for cryptographic applications.
  • To be a valid elliptic curve, it must satisfy the condition:
... Continue reading "Blockchain Cryptography: ECC, Hashing, and Consensus" »

Operating System Memory Management and Deadlock Prevention

Posted by Anonymous and classified in Computers

Written on in English with a size of 6.41 KB

Operating System Memory Management Fundamentals

The Operating System (OS) is responsible for crucial memory decisions: determining which programs reside in memory, where they are placed, how memory is protected, and what actions to take when memory resources are exhausted.

Parkinson's Law Applied to Computing

Parkinson’s Law states that programs expand to fill the memory available to hold them.

Models for Organizing Memory

Three primary models exist for structuring memory:

  • Model A (User on Top, RAM on Bottom):
    • Pros: Fast execution.
    • Cons: No protection (e.g., used in MS-DOS).
  • Model B (ROM on Top, User on Bottom):
    • Pros: OS protected.
    • Cons: Slow and not flexible.
  • Model C (Drivers at Top, User in Middle, RAM at Bottom):
    • Pros: Fast and secure.
    • Cons: Complex
... Continue reading "Operating System Memory Management and Deadlock Prevention" »

Software Engineering Principles and System Design

Classified in Computers

Written on in English with a size of 301.21 KB

Software Engineering and Processes

Agile Manifesto

  • Individuals/Interactions over Processes
  • Working software over documentation
  • Collaboration over negotiation
  • Responding to change over following a plan

Requirements Engineering

Descriptions of the services that a system should provide and the constraints on its operation.

Functional

What the system should do.

Non-functional

Not directly concerned with the specific services delivered by the system to its users.

Quality Attributes

A scenario describing quality attributes typically involves these elements:

  1. Source: Origin of the stimulus.
  2. Stimulus: The event arriving.
  3. Artifact: Where the event arrives.
  4. Environment: Conditions in which the scenario takes place.
  5. Response: The result of the event.
  6. Response Measure: Must
... Continue reading "Software Engineering Principles and System Design" »