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

C Programming Algorithms: Coin Change, Knapsack, MST, Shortest Path

Computer science8.06 KB

Problem Statement 16: Coin Change

Given a set of coins and a value, find the minimum number of coins to satisfy the given value.

Test Case 1:

Coins: {25, 20, 10, 5}, Value: 50 cents

Used coin: 25 cents

Used coin: 25 cents

Total number of coins: 2

Test Case 2:

Coins: {25, 20, 10, 5}, Value: 73 cents

Used coin: 25 cents

Used coin: 25 cents

Used coin: 20 cents

Used coin: 3 cents

Total number of coins: 4

Code:

-
#include int main { int amount =
50; int coins[] = {25, 20, 10, 5}; int
numCoins = 0;
printf("Amount: %d cents\n", amount);
for (int i = 0; i while (amount >= coins[i]){
amount -= coins 1;
numCoins++;
printf("Used
coin: %d cents\n", coins[i]);
}
printf("Total number of coins: %din", numCoins); return 0; }

Problem Statement 19: -#include #include int i,j,k,...

Continue reading "C Programming Algorithms: Coin Change, Knapsack, MST, Shortest Path" »

Bisection and Regula Falsi Methods in C Programming

Computer science2.07 KB

Bisection Method Implementation

#include <stdio.h>
#include <math.h>

#define f(x) (cos(x) - (x * exp(x)))

int main() {
    float x0, x1, x2, f0, f1, f2, e;
    int step = 1;

    /* Inputs */
    up:
    printf("\nEnter two initial guesses:\n");
    scanf("%f%f", &x0, &x1);
    printf("Enter tolerable error:\n");
    scanf("%f", &e);

    f0 = f(x0);
    f1 = f(x1);

    if (f0 * f1 > 0.0) {
        printf("Incorrect Initial Guesses. Try again.\n");
        goto up;
    }

    printf("\nStep\t\tx0\t\tx1\t\tx2\t\tf(x2)\n");
    do {
        x2 = (x0 + x1) / 2;
        f2 = f(x2);
        printf("%d\t\t%f\t%f\t%f\t%f\n", step, x0, x1, x2, f2);

        if (f0 * f2 < 0) {
            x1 = x2;
            f1 = f2;
...
Continue reading "Bisection and Regula Falsi Methods in C Programming" »

Software Design Patterns: Principles and Implementation

Computer science4.92 KB

Software Design Patterns and Architecture (CSC3324)


Defining Software Design Patterns

  • A reusable solution to a recurring design problem.

  • It reuses abstract knowledge about problems and solutions.

  • Independent of specific implementations, it acts as a template.

  • It utilizes Object-Oriented Programming (OOP) features such as inheritance and polymorphism.


The Christopher Alexander Definition

“Each pattern describes a problem which occurs over and over again... and then describes the core of the solution... you can use this solution a million times over without doing it the same way twice.”


Architecture vs. Design Patterns

AspectArchitectureDesign Patterns
LevelHigh-levelLower-level (Micro-architecture)
PurposeStructure of the whole applicationSolve subproblems
...
Continue reading "Software Design Patterns: Principles and Implementation" »

Python Fundamentals: Code Examples and Exercises

Computer science10.65 KB

Python Operations and Operators

This section covers fundamental operations and operators in Python, which are symbols used to perform operations on values and variables.

# Examples of different operators
a = 10 // 3  # Floor Division
a = 10 % 3   # Modulo Operator
a = 3        # Assignment
b = 1        # Declaring variables
a == b       # Comparison

Types of Operators

Operators are used for operations between values and variables. The main types are:

  • Assignment Operators: Used to assign values to variables.
  • Logical Operators: Used to combine conditional statements.
  • Comparison Operators: Used to compare two values.
  • Arithmetic Operators: Used with numeric values to perform common mathematical operations.
  • Bitwise Operators: Used to compare binary numbers.
...
Continue reading "Python Fundamentals: Code Examples and Exercises" »

Essential Database Management System Concepts Explained

Computer science3.28 KB

Core Goals of a DBMS

A robust database management system (DBMS) provides software tools for the efficient storage, retrieval, manipulation, security, and administration of data. Key objectives include:

  • Ensuring data integrity and security
  • Supporting concurrent access
  • Providing data abstraction
  • Optimizing query processing

Entity Relationships and Cardinality

Strong vs. Weak Entities

An entity denotes a distinct object, while an entity type defines its category and an entity set aggregates objects belonging to that category. A strong entity has its own primary key, whereas a weak entity lacks its own and depends on a foreign key from a strong entity (e.g., order items for an order).

Cardinality

Cardinality represents the uniqueness and number of elements...

Continue reading "Essential Database Management System Concepts Explained" »

Bitcoin Consensus and Ethereum Smart Contracts

Computer science106.85 KB

Bitcoin Consensus

The Problem: Decentralized Network

  • Bitcoin operates without a central authority; all users must agree on transaction history.
  • It faces the Byzantine Generals Problem; although unknown to each other, participants must establish trust.
  • Trust is established using consensus protocols, incentives, and cryptography.

How It Works

  • The Bitcoin algorithm operates on nodes.
  • Any device (computer) running the full Bitcoin software and connected to the internet acts as a connection point for creating blocks and verifying transactions.
  • When a block is created, nodes communicate to verify the transactions and ensure they follow the algorithm's rules.
  • Each node maintains a complete copy of the Bitcoin blockchain.

Participants in the Ecosystem

  • Full Nodes:
...
Continue reading "Bitcoin Consensus and Ethereum Smart Contracts" »

Jose Andres Gutierrez Vargas: Software Developer Profile

Computer science3.33 KB

Jose Andres Gutierrez Vargas

Email: [email protected]
Phone: [Your Phone Number]

Professional Summary

Results-driven and highly motivated Software Developer with extensive expertise in backend and frontend development, RESTful APIs, and database management. Skilled in SQL and NoSQL databases, with in-depth experience in Node.js for building scalable and high-performance applications. Adept at optimizing system performance, troubleshooting technical issues, and implementing innovative solutions.

Former Frontend Developer at Google, where I contributed to the development of dynamic and interactive web applications, enhancing user experiences through cutting-edge technologies. Passionate about software development, staying updated with the latest...

Continue reading "Jose Andres Gutierrez Vargas: Software Developer Profile" »

PIC18 Microcontroller Architecture and Programming Fundamentals

Computer science2.31 MB

r0aTE1NVXMmzevWL58ebFjx444S5Kkv5dBLEmSJEmSJLWePbEkSZIkSZLUegaxJEmSJEmS1HoGsSRJkiRJktR6BrEkSZIkSZLUegaxJEmSJEmS1HoGsSRJkiRJktR6BrEkSZIkSZLUegaxJEmSJEmS1HoGsSRJkiRJktR6BrEkSZIkSZLUegaxJEmSJEmS1HJF8R8nijdTkdt0NQAAAABJRU5ErkJggg==

jZJ+MjVSDBwAAAABJRU5ErkJggg==

h8ptEUKkg7IZQAAAABJRU5ErkJggg==

DUnON+LR4AAAAASUVORK5CYII=

98afFzAAAAAElFTkSuQmCC

H6qI1ExVJ4g5AAAAAElFTkSuQmCC

X9yKEEEIIfeAQQgghLrJ161Y5fQoWBQr82ebJk0dOlbp8+bI4fvy4uHDhglTsTJw4URQuXFjfk5CUBaxv4IQaTsgVadOmlYrNpk2b6lsIIYQQAgIrcIT4fwcJ5tlvgQpqAAAAAElFTkSuQmCC

nlqAAAAAElFTkSuQmCC

8IHbt2iVOnz4tg8y5cuUSefPmFaVLlxa1a9cW9913n8iRI4f6FBGRGYMWRERERERERORK7IiTiIiIiIiIiFyJQQsiIiIiIiIiciUGLYiIiIiIiIjIlRi0ICIiIiIiIiJXYtCCiIiIiIiIiFyJQQsiIiIiIiIiciUGLYiIiIiIiIjIlRi0ICIiIiIiIiJXYtCCiIiIiIiIiFyJQQsiIiIiIiIiciUGLYiIiIiIiIjIhYT4P77eVJYAUUVEAAAAAElFTkSuQmCC

4f9BI30SufhNkAAAAASUVORK5CYII=

wHkdzvXXrzhLwAAAABJRU5ErkJggg==


1. PIC18 Architecture Details

  • Harvard Architecture

    Features distinct program memory and data memory. Includes the MPU, Program Memory, Data Memory, I/O Ports, and support devices like timers.

  • Microprocessor Unit (MPU)

    • ALU (Arithmetic Logic Unit)

      Performs operations such as addition, subtraction, and logical operations.

    • Registers

      Includes WREG (8-bit accumulator), Program Counter (PC), Stack Pointer (SP), and File Select Registers (FSRs).

    • Memory

      Offers 2 MB of program memory and 4 KB of data memory.

    • Bank Switching

      Data memory is divided into 16 banks, with one 256-byte access bank.

2. Data Formats and Representations

  • Unsigned Integers

    These are 8-bit values, ranging from 0 to 255.

  • Signed Integers

    Represented using 2's complement, with a range from -128 to

...
Continue reading "PIC18 Microcontroller Architecture and Programming Fundamentals" »

Mastering Software Design Principles and SOLID Patterns

Computer science206.57 KB

Core Software Design Principles

  • Abstraction: Removal or masking of detail and complexity.
  • Modularity: Software is divided into separately named and addressable components.
  • Separation of Concerns: Any complex problem can be more easily handled if it is subdivided into pieces.
  • Information Hiding / Encapsulation: Hide implementation details from client components; communicate only via controlled interfaces.
  • High Cohesion: Components provide specific functionality.
  • Low Coupling: Components have as few dependencies as possible so they can change with minimal impact on other components.

SOLID Principles

Single Responsibility Principle

The idea here is simple: Separate the code that supports different actors (i.e., users, stakeholders, or client components)...

Continue reading "Mastering Software Design Principles and SOLID Patterns" »

C Data Structures: Binary Trees, DFS, and Stack Logic

Computer science3.54 KB

7th Experiment: Binary Tree Construction

This experiment demonstrates the construction of a binary tree from an array and its in-order traversal.

#include <stdio.h>
#include <stdlib.h>

struct node {
  struct node* left;
  char data;
  struct node* right;
};

struct node* constructTree(int index);
void inorder(struct node* root);

char array[] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', '\0', '\0', 'H' };
int leftcount[] = { 1, 3, 5, -1, 9, -1, -1, -1, -1, -1 };
int rightcount[] = { 2, 4, 6, -1, -1, -1, -1, -1, -1, -1 };

int main() {
  struct node* root = constructTree(0);
  printf("In-order Traversal: \n");
  inorder(root);
  return 0;
}

struct node* constructTree(int index) {
  struct node* temp = NULL;
  if (index != -1) {
    temp
...
Continue reading "C Data Structures: Binary Trees, DFS, and Stack Logic" »