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

Sort by
Subject
Level

C Programming Examples: Code Snippets and Explanations

Classified in Computers

Written on in English with a size of 3.41 KB

C Programming Examples

Here are several C programming examples:

Vector Operations

#include <stdio.h>

void leVetor (int v [] , int tam );
int prodEscalar (int v1 [] , int v2 [] , int tam );

int main (void) {
    int v1 [ DIM ], int v2 [ DIM ];
    int i;
    int prod ;

    leVetor (v1 , DIM );
    leVetor (v2 , DIM );
    prod = prodEscalar (v1 , v2 , DIM );
    printf ("%d\n", prod );
    return 0;
}

void leVetor (int v [] , int tam ) {
    /* Completar */
}

int prodEscalar (int v1 [] , int v2 [] , int tam ) {
    /* Completar */
}

Random Number Generation

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

#define VEZES 10

int main (void) {
    int i , j , k;
    double r;

    srand ( time ( NULL )); /* inicializa
... Continue reading "C Programming Examples: Code Snippets and Explanations" »

Core Concepts in Artificial Intelligence: Search Algorithms and Knowledge Systems

Classified in Computers

Written on in English with a size of 15.96 KB

Heuristic Search Techniques Explained

Heuristic search techniques use intelligent estimations to find solutions efficiently. These methods help in decision-making by prioritizing the most promising paths.


1. Greedy Best-First Search (GBFS)

  • Always chooses the next step that appears closest to the goal.
  • Ignores the cost already traveled.

Example:

A person finding the exit of a maze by always taking the path that looks shortest.

Risk: May lead to dead ends.


2. A* Search Algorithm

  • Balances actual cost and estimated cost to reach the goal.
  • Ensures the shortest and most efficient path.

Example:

Google Maps finds the best route by considering both distance already covered and the remaining estimated distance.

Optimal and efficient.


3. Hill Climbing Algorithm

  • Moves
... Continue reading "Core Concepts in Artificial Intelligence: Search Algorithms and Knowledge Systems" »

Hehhrhrhr

Posted by Anonymous and classified in Computers

Written on in English with a size of 9.2 KB

Sequential circuits are fundamental components of digital systems, defined by the fact that their output depends not only on the current inputs but also on the past history of inputs (i.E., their current state).
The most basic element of a sequential circuit is the Flip-Flop, which is a 1-bit memory cell.
Here is a detailed explanation of the basic Flip-Flops and their operation:
1. Latches vs. Flip-Flops
Both latches and flip-flops are 1-bit storage elements, but they differ in how they are controlled:
| Feature | Latch | Flip-Flop |
|---|---|---|
| Triggering | Level-triggered (Transparent) | Edge-triggered (Synchronous) |
| Control | Changes state as long as the Enable or Clock is HIGH (or LOW). | Changes state only at the rising edge or falling... Continue reading "Hehhrhrhr" »

Java AWT: Button Events and Arrow Key Shape Movement

Classified in Computers

Written on in English with a size of 3.75 KB

Button Click Action Events

import java.awt.*;

import java.awt.event.*;

public class ButtonClickActionEvents

{

public static void main(String args[])

{

Frame f=new Frame("Button Event");

Label l=new Label("DETAILS OF PARENTS");

l.setFont(new Font("Calibri",Font.BOLD, 16));

Label nl=new Label();

Label dl=new Label();

Label al=new Label();

l.setBounds(20,20,500,50);

nl.setBounds(20,110,500,30);

dl.setBounds(20,150,500,30);

al.setBounds(20,190,500,30);

Button mb=new Button("Mother");

mb.setBounds(20,70,50,30);

mb.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

nl.setText("NAME: " + "Aishwarya");

dl.setText("DESIGNATION: " + "Professor");

al.setText("AGE: " + "42");

}

});

Button fb=new Button("Father");

fb.setBounds(80,70,50,30);

fb.addActionListener(

... Continue reading "Java AWT: Button Events and Arrow Key Shape Movement" »

Mastering Relational Algebra for Database Queries

Classified in Computers

Written on in English with a size of 4.53 KB

Relational Algebra Fundamentals

  • Relational Algebra is a mathematical query language used in databases.
  • The result of any operation is always another relation (table).

Relational Algebra Operations Explained

Unary Relational Operations

SELECT (σ) – Filters Rows

  • Retrieves specific rows from a table based on a condition.
  • Syntax: σ (condition) (Relation)
  • Example: σ (Dept_ID = 4) (EMPLOYEE)

PROJECT (π) – Filters Columns

  • Retrieves specific columns from a table.
  • Syntax: π (column1, column2) (Relation)
  • Example: π (Name, Salary) (EMPLOYEE)

RENAME (ρ) – Changes Table or Column Name

  • Syntax: ρ (NewTable (NewColumn1, NewColumn2), OldTable)
  • Example: ρ (Staff (Emp_ID, FullName), EMPLOYEE)

Set Theory Operations

UNION (∪) – Combines Two Tables

  • Combines tuples
... Continue reading "Mastering Relational Algebra for Database Queries" »

Python Control Flow and Data Structures: Loops, Lists, and Sets

Posted by Anonymous and classified in Computers

Written on in English with a size of 10.27 KB

Python Control Flow: Loops and Branching

Python provides powerful structures for iteration (loops) and flow control (branching statements) that allow you to execute blocks of code repeatedly or conditionally.

Python Loop Statements

Loops are used to execute a block of code multiple times. The main loop types in Python are while and for.

1. The while Loop

The while loop repeatedly executes a block of statements as long as a given condition is True.

  • Syntax:

    while condition:
    # statement(s) to be executed

  • Key Point: You must ensure that the condition eventually becomes False to avoid an infinite loop. This is typically done by modifying a variable within the loop body.

Example:

count = 0
while count < 3:
print(f"Count is {count}")
count += 1

Output:

... Continue reading "Python Control Flow and Data Structures: Loops, Lists, and Sets" »

C Programming: Tokens, Operators, and Logic

Classified in Computers

Written on in English with a size of 2.55 KB

Tokens

In programming, a token is the smallest meaningful element in code. They are the building blocks of a language's syntax. Common token types include:

  • Keywords: Reserved words like if, else, while, and int (for declaring integers).
  • Identifiers: Names given to elements like variables (e.g., sum), functions, and arrays.
  • Constants: Unchanging values during program execution (e.g., 3.14 for pi).
  • Operators: Symbols for mathematical or logical operations (e.g., + for addition).
  • Separators: Punctuation like commas (,), semicolons (;), and braces ({}).

Example: int sum = 10 + 5;

In this line, int is a keyword, sum is an identifier, = is an operator, 10 and 5 are constants, and ; is a separator.

Arithmetic Operators

C has nine arithmetic operators for basic... Continue reading "C Programming: Tokens, Operators, and Logic" »

Python Fundamentals: Variables, Data Types, and Control Flow

Posted by Anonymous and classified in Computers

Written on in English with a size of 14.36 KB

Keywords and identifiers are fundamental elements in programming languages used to define variables, functions, and other constructs, with keywords being reserved words that have special meanings, and identifiers being names given to user-defined entities.

Comments in programming serve the essential purpose of making the source code more understandable and maintainable by providing textual annotations that explain the logic, purpose, or any additional information about the code. They help programmers and collaborators to read, debug, and update the code efficiently without affecting its execution.

There are two main types of comments:
- Single-line comments start with specific symbols like // in languages such as C, Java, and JavaScript, and they... Continue reading "Python Fundamentals: Variables, Data Types, and Control Flow" »

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

Posted by Anonymous and classified in Computers

Written on in English with a size of 422.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" »

Dijkstra's Algorithm in C: Code & Explanation

Classified in Computers

Written on in English with a size of 3.5 KB

Dijkstra's Algorithm in C

This code implements Dijkstra's algorithm to find the shortest path from a source vertex to all other vertices in a graph represented as an adjacency matrix. The program reads graph data from an input.txt file and writes the results to an output.txt file.

Code Implementation


#include <stdio.h>
#include <limits.h>
#include <stdbool.h>

#define MAX_VERTICES 100

// Function to find the vertex with minimum distance
int minDistance(int dist[], bool visited[], int vertices) {
    int min = INT_MAX, min_index;

    for (int v = 0; v < vertices; v++)
        if (!visited[v] && dist[v] <= min) {
            min = dist[v];
            min_index = v;
        }

    return min_index;
}

// Dijkstra'
... Continue reading "Dijkstra's Algorithm in C: Code & Explanation" »