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

C# Design Patterns: Essential Reference for Developers

Computer science12.41 KB

C# Design Patterns: Essential Reference

Creational Design Patterns

PatternWhen to UseKey Implementation
SingletonNeed exactly one instance globally accessible.private static Singleton _instance;
public static Singleton Instance => _instance ??= new Singleton();
FactoryCreate objects without specifying concrete classes.public static IProduct Create(string type) => type switch { "A" => new ProductA(), ... }
BuilderConstruct complex objects step-by-step.public class CarBuilder { ... public CarBuilder WithEngine(...) { ... } }
PrototypeClone existing objects instead of creating new ones.public interface IPrototype { IPrototype Clone(); }

Structural Design Patterns

PatternWhen to UseKey Implementation
AdapterMake incompatible interfaces work together.
...
Continue reading "C# Design Patterns: Essential Reference for Developers" »

Core Concepts in AI, Machine Learning, and Industrial Automation Systems

Computer science422.57 KB

Linear Regression Fundamentals

In regression, a set of records containing X and Y values is used to learn a function. This learned function can then be used to predict Y from an unknown X. In regression, we aim to find the value of Y, so a function is required which predicts Y given X. Y is continuous in the case of regression.

Here, Y is called the criterion variable and X is called the predictor variable. There are many types of functions or models which can be used for regression. The linear function is the simplest type of function. Here, X may be a single feature or multiple features representing the problem.

P37C38P9ECJqqvMXffAAAAAElFTkSuQmCC

Applications of Linear Regression in AI

  • Predictive Analysis: Forecasting sales, stock prices, or house prices based on historical data.
...
Continue reading "Core Concepts in AI, Machine Learning, and Industrial Automation Systems" »

Core Digital Electronics: Flip-Flops, Logic Gates, Memory & ADCs

Computer science514.7 KB

Master-Slave Flip-Flop Operation

The working of a Master-Slave flip-flop involves two cascaded flip-flops: a master and a slave. The master is positive level-triggered, and the slave is negative level-triggered, ensuring the master responds before the slave.

When the clock pulse (CP) goes high (1), the slave is isolated, allowing the J and K inputs to affect the master's state. The slave flip-flop remains isolated until the CP goes low (0). When the CP transitions back to low, information is passed from the master flip-flop to the slave, and the output is obtained.

Let's examine the behavior based on J and K inputs:

  • J=0, K=1: The high Q' output of the master goes to the K input of the slave. The negative transition of the clock forces the slave
...
Continue reading "Core Digital Electronics: Flip-Flops, Logic Gates, Memory & ADCs" »

React Hooks & Redux: Essential Concepts for Developers

Computer science10.31 KB

React Hooks and Essential Libraries

useState Hook

Purpose

Purpose: Adds state to functional components.

Import

import { useState } from 'react';

Syntax

const [state, setState] = useState(initialValue);

Update Methods

  • setState(newValue);
  • setState(prevState => ...); (for updates based on previous state)

Example

import React, { useState } from 'react';

function Counter() {
  const [count, setCount] = useState(0);

  return (
    <div>
      <p>Count: {count}</p>
      <button onClick={() => setCount(count + 1)}>Increment</button>
    </div>
  );
}

useEffect Hook

Purpose

Purpose: Performs side effects such as data fetching, subscriptions, or direct DOM manipulations.

Import

import { useEffect } from 'react';

Syntax

useEffect(
...
Continue reading "React Hooks & Redux: Essential Concepts for Developers" »

Discrete Mathematics Foundations: Sets, Logic, Graphs, and Proofs

Computer science880.48 KB

Speaking Mathematically: Core Concepts

The Language of Sets

  • ∀ - Universal quantifier (true for all values of a variable in a set)
  • ∃ - Existential quantifier (true for at least one value of a variable in a set)

Common Set Notations:

  • R - Set of all real numbers
  • Z - Set of all integers
  • Q - Set of all rational numbers
  • N - Set of all positive integers
  • (X)+- - Positive/negative elements for a specific set X

x ∈ S means that x is an element of the set S.

  • Example: x=5, S={1, 2, 3, 4, 5}

A ⊆ B means that A is a subset of the set B.

  • Example: A={a,b}, B={a,b,c}
  • Example: {2} ∈ {1, 2, 3} is false; {2} ∈ {{1}, {2}} is true; 2 ⊆ {1, 2, 3} is false; {2} ⊆ {1, 2, 3} is true
  • Note: {9, 9, 1, 1, 7, 7} has only 3 distinct elements ({1, 7, 9}); {1, {2}} has 2 elements;
...
Continue reading "Discrete Mathematics Foundations: Sets, Logic, Graphs, and Proofs" »

Dafny Verification and Formal Methods Exam Review

Computer science644.93 KB

Dafny Concepts and Preconditions

Preconditions are required; postconditions are ensured.

Methods do not change given parameters unless a modifies clause is present.

Old(E) has the value of E at the start of the method.

Fresh(E) as a postcondition shows that E was created by M.

With if statements, Dafny works normally. With if-case statements, you introduce nondeterminism (hard; you need to prove all options).

Classes have instance variables and methods, which need clear contracts.

A trait is an abstract class, from which classes inherit (like a template in Java). Example: trait A; class B extends A

Class invariants must hold before and after any method. Use ghost predicate Valid().

Behavioral Subtyping: When a class A inherits from another class/trait,...

Continue reading "Dafny Verification and Formal Methods Exam Review" »

Understanding the Spiral Model in Software Development

Computer science2.13 KB

What Is the Spiral Model?

The Spiral Model is a Software Development Life Cycle (SDLC) model that provides a systematic and iterative approach to software development. In its diagrammatic representation, it looks like a spiral with many loops. The exact number of loops is unknown and can vary from project to project. Each loop of the spiral represents a phase of the software development process.

Key Points of the Spiral Model

  • The exact number of phases needed to develop the product can be varied by the project manager depending upon the project risks.
  • As the project manager dynamically determines the number of phases, they have an important role in developing a product using the spiral model.
  • It is based on the idea of a spiral, with each iteration
...
Continue reading "Understanding the Spiral Model in Software Development" »

PHP Programming Essentials and Core Features

Computer science2.95 KB

What is PHP?

PHP (Hypertext Preprocessor) is a widely-used open-source scripting language primarily designed for web development. It runs on the server-side, meaning the code is executed on the web server before the output is sent to the user's browser. PHP is embedded within HTML and supports various databases, making it a powerful tool for creating dynamic and interactive web applications.

Key Features of PHP

PHP has several features that make it a popular choice for web development:

  • Open-Source – PHP is free to use, with a large community of developers providing support and updates.
  • Cross-Platform Compatibility – PHP works on multiple operating systems like Windows, Linux, and macOS.
  • Easy to Learn and Use – Its syntax is simple and similar
...
Continue reading "PHP Programming Essentials and Core Features" »

Master API Testing: Core Concepts and Best Practices

Computer science3.52 KB

API Testing Fundamentals

Definition: API testing involves verifying that APIs meet functionality, performance, reliability, and security requirements.

Types of APIs

  • REST
  • SOAP
  • GraphQL
  • gRPC

Key Components of API Testing

Endpoints

  • URI: Unique resource identifier.
  • Methods: HTTP/HTTPS methods like GET, POST, PUT, and DELETE.

Request Components

  • Headers: Transfer metadata (e.g., Authorization, Content-Type).
  • Body: Data payload for POST or PUT requests, usually in JSON or XML format.
  • Parameters: Path, query, and form parameters used to pass data.

Core Testing Types

  • Functional Testing: Validate API operations and output against requirements.
  • Performance Testing: Assess speed, scalability, and reliability under load.
  • Security Testing: Ensure the API protects data and
...
Continue reading "Master API Testing: Core Concepts and Best Practices" »

Python Fundamentals and Algorithms Explained

Computer science5.17 KB

Algorithms

Algorithms involve inputs, instructions, outputs, and a purpose.

Instruction Types

  • Instruction
  • Decision
  • Loop
  • Variable
  • Function

Python Basics

Comments

Comments explain what code is for, intended for human readers.

Variables

Storing a value in a variable is called assignment. It's best practice not to use generic names.

Calculations (Operators)

  • + : Addition
  • - : Subtraction
  • * : Multiplication
  • / : Division
  • // : Integer Division (e.g., 6 // 4 = 1)
  • % : Remainder / Modulo (e.g., 6 % 4 = 2)
  • ** : Exponentiation

mass_in_kg = 15

weight_in_pounds = mass_in_kg * 2.2

print('the weight in pounds is: ', weight_in_pounds)

user_name = input("enter your user name: ")

print('hello', user_name)

Data Types

  • int: Integer numbers (e.g., -1, 0, 2, 1000)
  • float: Floating-point (real)
...
Continue reading "Python Fundamentals and Algorithms Explained" »