Notes, summaries, assignments, exams, and exercises for Computer science for Baccalaureate

Prolog Compiler: Dictionary Lookup and Code Generation

Computer science3.6 KB

Dictionary Lookup

lookup(Nom,dic(Nom,Value,_,_),Value):-!.
lookup(Nom,dic(X,_,L,_),Value):-Nom@<X,lookup(Nom,L,Value).
lookup(Nom,dic(X,_,_,R),Value):-Nom@>X,lookup(Nom,R,Value).

Operator Mappings

Constant Operators

opc(+,addc).
opc(-,subc).
opc(*,mulc).
opc(/,divc).

Expression Operators

opx(+,add).
opx(-,sub).
opx(*,mul).
opx(/,div).

Jump Operators

opj(=,jumpne).
opj(<,jumpge).
opj(>,jumplt).

Expression Encoding

encodeexpr(const(X),_,instr(loadc,X)).
encodeexpr(name(X),D,instr(load,Adress)):-lookup(X,D,Adress).

encodeexpr(expr(Op,Ex,const(Y)),D,(Ins;instr(Type,Y))):-
encodeexpr(Ex,D,Ins),
opc(Op,Type).

encodeexpr(expr(Op,Ex,name(Y)),D,(Ins;instr(Type,Adress))):-
encodeexpr(Ex,D,Ins),
opx(Op,Type),
lookup(Y,D,Adress).

Test Encoding

encodetest(test(OpJ,Arg1,Arg2)
...
Continue reading "Prolog Compiler: Dictionary Lookup and Code Generation" »

Fundamental Concepts of Internet and Web 2.0 Technologies

Computer science3.17 KB

Network Fundamentals

The Internet: History and Evolution

The Internet was born in the U.S. in the early 1970s from a network created by the U.S. Army called ARPANET. (Sources: http://www.isoc.org/internet/history/; http://wiki.startup2.eu/index.php/Main_Page).

The Internet is not controlled or maintained by any single entity, which provides both its main advantages and disadvantages. Every person connecting is free to set the tone or ideology that will be used. While we previously focused on the Internet generally, the current discussion centers on Web 2.0 and the Social Web, driven by the continuous emergence of new services.

Web 1.0 vs. Web 2.0

The characteristics of Web 1.0 involved a server sending information to clients, determining which clients...

Continue reading "Fundamental Concepts of Internet and Web 2.0 Technologies" »

Binary Tree Traversals and Expression Evaluation in C

Computer science3.47 KB

Binary Tree Traversals and Expression Evaluation in C

This document contains formatted C code snippets for expression tree evaluation and binary tree traversals (preorder, inorder and postorder). Comments and strings are corrected for clarity while preserving original content.

Expression Tree Evaluation Function

 int evaluate (NodeB n, btree T)
 (
   char ident;

   EtiquetaArbolB (& c, n, T);
   switch (c) (
     case '+':
       return evaluate (HijoIzqdaB (n, T), G) + evaluate (HijoDrchaB (n, T), T);
       break;
     case '-':
       return evaluate (HijoIzqdaB (n, T), T)-Evaluation (HijoDrchaB (n, T), T);
       break;
     case '*':
       return evaluate (HijoIzqdaB (n, T), T) * Evaluation (HijoDrchaB (n, T), T);
       break;
...
Continue reading "Binary Tree Traversals and Expression Evaluation in C" »

Inter-VLAN Routing and Wireless LAN Fundamentals

Computer science2.74 KB

Inter-VLAN Routing

Inter-VLAN routing is the process of forwarding network traffic from one VLAN to another via a router. As shown in the figure, traffic from PC1 in VLAN10 is routed through the router to reach PC3 in VLAN30.

Traditional Routing

Traditionally, routing the LAN using routers involves multiple interfaces. You must connect each interface to a separate network and configure it to a different subnet.

Router-on-a-Stick Configuration

"Router-on-a-stick" is a configuration where a single physical interface routes traffic between multiple VLANs on a network.

Subinterfaces

Subinterfaces are multiple virtual interfaces associated with a single physical interface. These software interfaces are configured on a router independently with an IP address...

Continue reading "Inter-VLAN Routing and Wireless LAN Fundamentals" »

C++ and Python Solutions: Binary Search, Grid Lookup, and Range Counting Algorithms

Computer science3.62 KB

C++ and Python Solutions for Algorithmic Problems

#include <bits/stdc++.h>
using namespace std;

bool check(const vector<long long>& a, int k, long long maxs) {
int block = 1;
long long sum = 0;

for (long long x : a) {
if (sum + x > maxs) {
block++;
sum = x;
}
else {
sum += x;
}
}

return block <= k;
}

int main() {
int n, k;

if (!(cin >> n >> k)) {
return 0;
}

vector<long long> a(n);

long long maxval = 0;
long long sumval = 0;

for (int i = 0; i < n; i++) {
cin >> a[i];

maxval = max(maxval, a[i]);
sumval += a[i];
}

long long l = maxval;
long long r = sumval;
long long...

Continue reading "C++ and Python Solutions: Binary Search, Grid Lookup, and Range Counting Algorithms" »

Advanced Java Programs: Collections, Strings, Swing, Servlets and Cookies

Computer science11.85 KB

Advanced Java Programs

This collection of Java programs demonstrates core and advanced concepts, including collections, string handling, GUI development with Swing, servlets, and cookie management.

1. ArrayList Operations

The following program shows how to add, remove, sort, and convert an ArrayList to an array.

package Advanced_java;
import java.util.ArrayList;
import java.util.Collections;

public class Program1 {
    public static void main(String[] args) {
        ArrayList<Integer> arrayList = new ArrayList<>();
        arrayList.add(5);
        arrayList.add(3);
        arrayList.add(8);
        arrayList.add(1);
        System.out.println("ArrayList after adding elements: " + arrayList);
        arrayList.remove(2);
        System.
...
Continue reading "Advanced Java Programs: Collections, Strings, Swing, Servlets and Cookies" »

Predicting Boston House Prices and Ionosphere Data Analysis with Machine Learning

Computer science5.24 KB

Boston Housing Data Analysis

library(mlbench)
install.packages("dplyr")
library(dplyr)
library(ggplot2)
library(reshape2)
data("BostonHousing")
housing <- BostonHousing
str(housing)

housing %>%   ggplot(aes(x = medv)) +
  stat_density() +
  labs(x = "Median Value ($1000s)", y = "Density", title = "Density Plot of Median Value House Price in Boston") +
  theme_minimal()

summary(housing$medv)

housing %>%   select(c(crim, rm, age, rad, tax, lstat, medv)) %>%   melt( id.vars = "medv") %>%   ggplot(aes(x = value, y = medv, colour = variable)) +
  geom_point(alpha = 0.7) +
  stat_smooth(aes(colour = "black")) +
  facet_wrap(~variable, scales = "free", ncol = 2) +
  labs(x = "Variable Value", y = "Median House Price ($1000s)") +
  theme_minimal(

...
Continue reading "Predicting Boston House Prices and Ionosphere Data Analysis with Machine Learning" »

Sistema de Inventario de Libros en PHP

Computer science2.01 KB

Lectura del Inventario

$fich = fopen("inventario.txt", "r");
$aver = fgets($fich);
while (!feof($fich)) {
    $array = explode("-", $aver);
    echo "Título: " . $array[0] . "<br>Autor: " . $array[1] . "<br>Código: " . $array[2] . "<br>Precio: " . $array[3] . "<br>Cantidad: " . $array[4] . "<br>****************************<br>";
    $aver = fgets($fich);
}
fclose($fich);
?>

Busque su libro por título o por código

Buscar por...

CódigoTítulo
if (isset($_POST['enviar'])) {
    $busqueda = $_POST['opcion'];
    $buscar = $_POST['buscar'];
    if ($busqueda == "titulo") {
        $f1 = fopen("inventario.txt", "r");
        $linea = fgets($f1);
        $encontrado = false;
        while (!feof($f1)) {
...
Continue reading "Sistema de Inventario de Libros en PHP" »

Internet Fundamentals and Digital Communication Technologies

Computer science3.9 KB

Digital Communication and Internet Fundamentals

Electronic Presentations

Electronic presentations are information expositions combining the use of visual and auditory content.

Common programs include Microsoft Office and OpenOffice.org.

Benefits of Electronic Presentations

  • Guides the speaker during an exhibition.
  • Allows programmed animation effects.
  • Easy for the audience to follow and understand.

Applications of Electronic Presentations

  • Exposing class issues or educational topics.
  • Creating reports (business and general).
  • Submitting proposals.
  • Visually supporting a conference.

Core Internet Services and Applications

The Internet

The Internet is formed by a set of interconnected local and global networks.

Website and Hyperlinks

A Website is a collection of related...

Continue reading "Internet Fundamentals and Digital Communication Technologies" »

Particle Photon IoT Labs: LEDs, Buttons, Interrupts and Cloud Projects

Computer science17.61 KB

🔹 LAB 1a — LED blink
#define LED0 D7
void setup(){pinMode(LED0,OUTPUT);}
void loop(){digitalWrite(LED0,HIGH);delay(1000);digitalWrite(LED0,LOW);delay(1000);}

🔹 LAB 1b — LED0 + LED1 blink
#define LED0 D7
#define LED1 D0
void setup(){pinMode(LED0,OUTPUT);pinMode(LED1,OUTPUT);}
void loop(){digitalWrite(LED0,HIGH);digitalWrite(LED1,HIGH);delay(200);digitalWrite(LED0,LOW);digitalWrite(LED1,LOW);delay(200);}

🔹 LAB 1c — Button controls flashing (while pressed)
#define LED0 D7
#define LED1 D0
#define BTN1 A1
int flashEnabled=0;
void setup(){pinMode(LED0,OUTPUT);pinMode(LED1,OUTPUT);pinMode(BTN1,INPUT_PULLDOWN);}
void loop(){flashEnabled=digitalRead(BTN1);
if(flashEnabled==HIGH){digitalWrite(LED0,HIGH);digitalWrite(LED1,HIGH);delay(200);digitalWrite(...

Continue reading "Particle Photon IoT Labs: LEDs, Buttons, Interrupts and Cloud Projects" »