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

Core Data Transmission and Processing Concepts

Computer science2.75 KB

Packet Switching Fundamentals

Packet switching is a method used in computer networks to transmit data efficiently by breaking it into smaller units called packets. Each packet travels independently across the network and may take different routes to reach the destination. Once all packets arrive, they’re reassembled into the original message.

How Packet Switching Works

  1. Segmentation: The original message is divided into packets.
  2. Header Information: Each packet receives a header with source, destination, and sequencing information.
  3. Independent Routing: Packets are sent through the network, possibly via different paths.
  4. Reassembly: At the destination, packets are reordered and combined to form the original message.

Advantages of Packet Switching

  • Efficient
...
Continue reading "Core Data Transmission and Processing Concepts" »

Compiler Design: SDTS, LR Parsing, and Code Optimization

Computer science232.62 KB

Syntax-Directed Translation Schemes (SDTS)

A possible Syntax-Directed Translation Scheme (SDTS) uses the attribute val to store the value of each non-terminal.

  • E → E1 + T { E.val = E1.val + T.val }
  • E → T { E.val = T.val }
  • T → T1 * F { T.val = T1.val * F.val }
  • T → F { T.val = F.val }
  • F → num { F.val = num.value }

Bottom-Up Evaluation of 3 + 2 * 4

Evaluation using SDTS (bottom-up):

  • F → num(4): F.val = 4
  • F → num(2): F.val = 2
  • F → num(3): F.val = 3
  • T → F (for num(2)): T.val = F.val = 2
  • T → T * F: T.val = T.val (from num(2)) * F.val (from num(4)) = 2 * 4 = 8
  • T → F (for num(3)): T.val = F.val = 3
  • E → T (for num(3)): E.val = T.val = 3
  • E → E + T: E.val = E.val (from num(3)) + T.val (from 2 * 4) = 3 + 8 = 11

Therefore, the result of the computation...

Continue reading "Compiler Design: SDTS, LR Parsing, and Code Optimization" »

Java Implementations: Dijkstra, Balanced BST, and Hash Table

Computer science5.54 KB

Java Implementations of Dijkstra's Algorithm, a Balanced Binary Tree, and a Hash Table

Dijkstra's Shortest Path Algorithm

The following class implements Dijkstra's algorithm to compute the shortest distances from a source node to all other nodes in a weighted graph.

import java.util.*;

class Dijkstra {
static class Edge {
int dst, weight;

Edge(int dst, int weight) {
this.dst = dst;
this.weight = weight;
}
}

public static Map<Integer, Integer> shortestPath(int source, Map<Integer, List<Edge>> graph) {
Map<Integer, Integer> distances = new HashMap<>();
PriorityQueue<int[]> pq = new PriorityQueue<>(Comparator.comparingInt(a -> a[1]));

for (int node : graph.keySet()) {
distances.put(node, Integer.MAX_VALUE);
}
distances....

Continue reading "Java Implementations: Dijkstra, Balanced BST, and Hash Table" »

Deep Learning Analysis and Data Management Systems

Computer science3.25 KB

DeepBase: Deep Inspection of Neural Networks

Introduction

  • Neural networks (NNs) are revolutionizing a wide range of machine intelligence tasks.
  • However, it remains unclear how and why neural networks are so effective.
  • One approach to understanding how NNs work is studying how and when neurons activate for test data; this class of analysis is called Deep Neural Inspection (DNI).

Deep Neural Inspection (DNI)

Given user-provided hypothesis logic (e.g., “detects nouns”, “detects keywords”), DNI seeks to quantify the extent that the behavior of hidden units (e.g., the magnitude or the derivative of their output) is similar to the hypothesis logic when running the model over a test set. This quantification is performed using statistical measures....

Continue reading "Deep Learning Analysis and Data Management Systems" »

Understanding HashMaps in Python: A Practical Example

Computer science7.43 KB

Understanding HashMaps in Python

Introduction

This document demonstrates a simple implementation of a HashMap in Python. A HashMap, also known as a hash table, is a data structure that implements an associative array abstract data type, a structure that can map keys to values. A hash function is used to compute an index into an array of buckets or slots, from which the desired value can be found.

Code Implementation

The following code provides a basic HashMap class in Python:

from random import *

class HashMap:
DEFAULT_SIZE = 4096
class item:
def __init__(self,k,v):
self.key = k
self.value = v

def __init__(self):
self.table = [None] * self.DEFAULT_SIZE
self.size = 0

def __eq__(self,
...
Continue reading "Understanding HashMaps in Python: A Practical Example" »

Java Servlet Bookstore: Cart and Checkout Logic with Hibernate

Computer science10.02 KB

LibreriaServlet: Java Servlet for an Online Bookstore


public class LibreriaServlet extends HttpServlet {


    protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {


        HttpSession session = request.getSession(false);
        Almacen almacen = new Almacen();
        List<Libro> librosDisponibles = new ArrayList<Libro>();
        try {
            librosDisponibles = almacen.consultaLibrosDisponibles();
        } catch (Exception e) {
            PrintWriter out = response.getWriter();
            out.print("ERROR: " + e.getMessage());
            out.close();
        }


        if (session != null) {


            String accion = request.getParameter("Accion");


...
Continue reading "Java Servlet Bookstore: Cart and Checkout Logic with Hibernate" »

Essential MIPS Assembly Programming Practice Problems

Computer science2.83 KB

1. MIPS Addition of Four Variables

Code in MIPS to add the 4 integer variables: a, b, c, d.

add $e, $a, $b
add $e, $e, $c
add $e, $e, $d

2. MIPS Implementation of f = (g + h) - (i + j)

Mapping f, g, h, i, j to $s0, $s1, $s2, $s3, $s4:

add $t0, $s1, $s2
add $t1, $s3, $s4
sub $s0, $t0, $t1

3. Why is a MIPS Register 32 Bits?

32 bits occur frequently and thus in MIPS, it has a special name: ‘word’. A size of 32 aligns well with the MIPS instruction format.

4. Understanding Big Endian in MIPS

‘MIPS is Big Endian’ means the most significant byte is stored at the least address of a word.

5. Purpose of lw and sw Instructions

These are MIPS data transfer instructions used to access specific memory locations:

  • lw (load word): Transfer data from memory to
...
Continue reading "Essential MIPS Assembly Programming Practice Problems" »

VHDL Implementations for Digital Logic Components

Computer science7.52 KB

VHDL Flip-Flop Implementations

This section demonstrates various VHDL implementations of flip-flops and latches, showcasing different clocking, clear, preset, and load mechanisms.


entity reginf is
    port (
        d, clk, clr, pre, load, data : in  std_logic;
        q1, q2, q3, q4, q5, q6, q7   : out std_logic
    );
end reginf;

architecture rtl of reginf is
begin

Active High Clock D-Latch

A simple D-latch sensitive to the rising edge of the clock.


    -- D-latch with active high clock
    process
    begin
        wait until clk='1';
        q1 <= d;
    end process;

Active Low Clock D-Latch

A D-latch sensitive to the falling edge of the clock.


    -- D-latch with active low clock
    process
    begin
        wait until clk='0';
...
Continue reading "VHDL Implementations for Digital Logic Components" »

Database Architecture Fundamentals: Models and Components

Computer science2.54 KB

Client Module Functions

The Client Module usually runs on a workstation or personal computer. Normally, application programs and user interfaces that access the database run on the client module.

Server Module Responsibilities

The Server Module typically manages storage, access, data mining, and other essential database functions.

Understanding the Data Model

A fundamental characteristic of the database approach is that it provides some level of data abstraction by hiding storage details that most users do not need to know. A Data Model is:

  • A collection of concepts used to describe the structure of a database.
  • The means to achieve data abstraction.

Database Structure Components

The structure of a database refers to the data types, relationships, and...

Continue reading "Database Architecture Fundamentals: Models and Components" »

Understanding Computer Hardware, Software, and Core Concepts

Computer science3.22 KB

PC Hardware: Essential Components

Hardware refers to the set of physical elements, machinery, and components (such as the microprocessor, monitor, and keyboard) that constitute a personal computer (PC).

Software, on the other hand, consists of programs or applications, along with the data or information they process and store.

Understanding Data and Information

Data serves as the raw material input that computers transform into information. Processed data, or information, is the result, distinguished by its usefulness.

Key Characteristics of Useful Information:

  • Relevant: The information is applicable to the current situation.
  • Current: Information is updated and available precisely when needed.
  • Accurate: Data entered into a computer and the resulting
...
Continue reading "Understanding Computer Hardware, Software, and Core Concepts" »