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

Java Backtracking Algorithms: Sudoku, Knapsack, and Tasks

Computer science2.25 KB

Sudoku Solver Implementation

private boolean isValid(int r, int c, int n) {
  boolean valid = true;
  int sr, sc, fr, fc;
  for (int i = 0; i < 9 && valid; i++) {
    if (i != r) if (grid[i][c] == n) valid = false;
    if (i != c) if (grid[r][i] == n) valid = false;
  }
  if (valid) {
    sr = (r / 3) * 3; fr = sr + 3; sc = (c / 3) * 3; fc = sc + 3;
    for (int i = sr; i < fr && valid; i++) {
      for (int j = sc; j < fc && valid; j++) {
        if (grid[i][j] == n) valid = false;
      }
    }
  }
  return valid;
}

private boolean solveRec(int row, int col) {
  boolean solved = false;
  if (row == 9) solved = true;
  else {
    if (grid[row][col] == 0) {
      for (int i = 1; i < 10; i++) {
        if
...
Continue reading "Java Backtracking Algorithms: Sudoku, Knapsack, and Tasks" »

Implementing Cloud-Native Security Best Practices

Computer science2.79 KB

Objective

To implement robust cloud-native security controls, including Encryption, Access Management, and Network Security.


Core Security Principles

  • Encryption: Protects data at rest (stored) and in transit (moving).
  • Access Management (IAM): Ensures the Principle of Least Privilege by managing user roles and Multi-Factor Authentication (MFA).
  • Network Security: Uses VPCs, Firewalls, and DDoS protection to isolate resources and filter malicious traffic.

Implementation Procedure

1. Data Encryption

  • At Rest: Use services like AWS KMS, Google KMS, or Azure Key Vault to manage cryptographic keys. Enable encryption on storage buckets (S3/Blob) and use Transparent Data Encryption (TDE) for databases.
  • In Transit: Force HTTPS/TLS protocols for all web traffic.
...
Continue reading "Implementing Cloud-Native Security Best Practices" »

I is correct ii is correct

Computer science52.48 KB

1. Number Systems & Data Types

Question 1: What is the decimal equivalent of 0xBEEF?

  • 48879

Question 2: What is the decimal number equivalent of the octal value 0465?

  • 309

Question 3: What is the binary equivalent of decimal 135?

  • 0b10000111

Question 4: What is the octal equivalent of 0x5EED?

  • 057355

Question 5: What is the binary equivalent of 0xBEAD?

  • 0b1011111010101101

Question 6: What is the range of an unsigned byte?

  • 0 to 255

Question 7: What is the range of a signed word?

  • 0x80000000 to 0x7FFFFFFF

[Exam 1] Question 8: What is the two's complement representation of -128 expressed as a signed half word?

  • 0b1111111110000000

[Exam 1] Question 9: What is the Octal equivalent of Hex 0xDEAF?

  • 0157257

[Exam 1] Question 10: Convert 0xA1A to decimal:

  • 2586

[Exam 1] Question

...
Continue reading "I is correct ii is correct" »

Essential Java Programming Examples for Beginners

Computer science3.61 KB

Java Programming Examples

This collection provides fundamental Java code snippets demonstrating core concepts such as classes, arrays, interfaces, and data structures.

1. Employee Salary Management

This example demonstrates how to manage employee data using an array of objects and basic arithmetic calculations.

import java.util.Scanner;

class Emp {
    private int id;
    private String name;
    private double sal, pf, hra;

    void set(int i, String n, double s, double p, double h) {
        id = i; name = n; sal = s; pf = p; hra = h;
    }

    void display() {
        double total = sal + hra - pf;
        System.out.println(id + " " + name + " Total: " + total);
    }
}

public class Main {
    public static void main(String[] args) {
...
Continue reading "Essential Java Programming Examples for Beginners" »

Flutter Employee Management App: Add, Show, Search, Update & Delete

Computer science14.65 KB

Flutter Employee Management App

This Flutter project demonstrates a simple employee management system with login, navigation, and full CRUD operations (Add, Show, Search, Update, and Delete).

HomePage with Tabs

The first HomePage uses a DefaultTabController with five tabs: Add, Show, Search, Update, and Delete.

class HomePage extends StatelessWidget {
  const HomePage({super.key});

  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
      length: 5,
      child: Scaffold(
        appBar: AppBar(
          title: const Text("Employee Management"),
          bottom: const TabBar(
            isScrollable: true,
            tabs: [
              Tab(text: "Add"),
              Tab(text: "Show"),
              Tab(text:
...
Continue reading "Flutter Employee Management App: Add, Show, Search, Update & Delete" »

Java Memory Management and Inheritance Principles

Computer science521.39 KB

Memory Management: Stack vs. Heap

The memory in Java is divided into two main areas:

  • Stack: Used for local primitive variables, local reference variables, and method calls.
  • Heap: Used for newly created objects.

Common Errors:

  • StackOverflowError: Occurs when the stack is overused.
  • OutOfMemoryError: Occurs when the heap is too full.

Access Control and Class Structure

Standard practices for class design include:

  • Public: Classes and constructors.
  • Private: Instance variables.
  • Public: Getters and setters to control access to class members.

Instance vs. Static:

  • Instance: Belongs to a particular object.
  • Static: Belongs to the class itself and is shared by all objects.

Variables and Data Types

Local variables must be initialized before use. When using arrays, they...

Continue reading "Java Memory Management and Inheritance Principles" »

Banker's Algorithm Implementation in C

Computer science3.52 KB

This program demonstrates the Banker's Algorithm, a classic deadlock avoidance strategy used in operating systems to manage resource allocation safely.

C Source Code

#include <stdio.h>

int n, m;
int alloc[10][10], max[10][10], need[10][10];
int avail[10], work[10], finish[10];

// Safety Algorithm
int checkSafety() {
    int seq[10], count = 0;

    for (int i = 0; i < n; i++) finish[i] = 0;
    for (int i = 0; i < m; i++) work[i] = avail[i];

    while (count < n) {
        int found = 0;
        for (int i = 0; i < n; i++) {
            if (!finish[i]) {
                int j;
                for (j = 0; j < m; j++) {
                    if (need[i][j] > work[j]) break;
                }
                if (j == m)
...
Continue reading "Banker's Algorithm Implementation in C" »

Mastering Python Functions: Arguments, Scope, and Returns

Computer science2.65 KB

Keyword Arguments

Arguments are passed using parameter names, meaning the order does not matter.

Example

def func(name, age):
    return f"Hello {name}, you are {age} years old!"

result = func(age=18, name="John")
print(result)

Output: Hello John, you are 18 years old!


Default Arguments

Default values are assigned to parameters directly in the function definition.

Example

def func(name, greeting="Hello"):
    return f"{greeting}, {name}"

print(func("John"))
print(func("Nik", "Hi"))

Output:
Hello, John
Hi, Nik


Arbitrary Arguments

Used when the number of arguments passed to a function is unknown.

*args – Non-keyword variable length arguments

def sum_numbers(*args):
    return sum(args)

print(sum_numbers(1, 5, 10, 15))

Output: 31


**kwargs – Keyword variable

...
Continue reading "Mastering Python Functions: Arguments, Scope, and Returns" »

Digital Business, Programming, and Software Essentials

Computer science5.55 KB

Digital Entrepreneurship

Digital entrepreneurship refers to the process of creating a business on the internet and selling products online. This model eliminates the need for physical business operations. Examples include online courses, e-commerce, blogs, and YouTube channels.

Search Engine Optimization (SEO)

SEO is the process of increasing a website's visibility on the internet when users search for products or services related to the business on Google or other search engines.

Business Planning

A business plan is a document that describes the company's objectives, operations, marketing goals, and financial projections. Key components include:

  • Executive Summary: A brief explanation of the business idea.
  • Business Description and Structure: Details
...
Continue reading "Digital Business, Programming, and Software Essentials" »

Bootstrap Components: Navigation Tabs, Tables, and Forms

Computer science2.78 KB

Corrected Exam

<!DOCTYPE html>

Images and Table with Nav Tabs

Lorem ipsum dolor sit amet consectetur adipisicing elit. Ducimus deserunt natus est et, incidunt id quasi ex veniam tenetur quibusdam optio dolor rem dicta officia voluptate nemo rerum quod amet.

Data Table

#NameAgeCountry
1Alice25USA
2Bob30UK
3Charlie28Canada

Alert Notification

Hello! This is an alert that can be closed by clicking on the "X" button.

<!DOCTYPE html>

Document

Form Section

Text Input
Select Option Choose... Option 1 Option 2 Option 3 Option 4
Accept Terms

Send

Grid

Lorem ipsum, dolor sit amet consectetur adipisicing elit. Assumenda autem culpa dolorum dolorem voluptatum quisquam ipsam quia quae libero rerum aut pariatur saepe quaerat doloribus...

Continue reading "Bootstrap Components: Navigation Tabs, Tables, and Forms" »