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

String Matching Algorithms in C++: KMP Prefix Function Examples

Computer science1.57 KB

C++ String Matching Algorithms

The following programs implement string matching techniques in C++, mainly the KMP prefix function.

1. Pattern Search in a Cyclic String

This program checks whether a pattern appears in a cyclic version of a string, using the prefix function and indices modulo n.

2. Counting Pattern Occurrences

This program counts how many times a pattern s appears in a text t and compares the count with a given value k, printing "YES" or "NO".

3. Finding Cyclic Shifts

This program searches for one string inside the cyclic extension of another and prints the first position where it occurs.

4. Longest Matching Words

This program converts strings to lowercase, computes the prefix function of each word combined with a pattern, and prints...

Continue reading "String Matching Algorithms in C++: KMP Prefix Function Examples" »

Complete Data Structures C++ Implementation Templates

Computer science54.36 KB

Lecture 1 — Introduction to Data Structures

Is lecture mein mostly theory, ADT, data organization, time aur space complexity aati hai. Is mein koi specific data structure implementation template nahi.

Basic program template:

#include <iostream>
using namespace std;

int main()
{
    // Declare variables

    // Take input

    // Perform operation

    // Display output

    return 0;
}

Algorithm likhne ka template:

START
    Input data
    Perform required operation
    Display result
STOP

ADT (Abstract Data Type) ka answer likhne ke liye:

  • Data structure ka naam

  • Data kis tarah store hota hai

  • Available operations

  • Operations ka expected behaviour

Example: Stack ADT mein push, pop, top, isEmpty operations hoti hain.

Lecture 2 — Arrays

High priority

1.

...
Continue reading "Complete Data Structures C++ Implementation Templates" »

Additive Manufacturing: SLA, FFF, DfAM and Design Considerations

Computer science8.11 KB

Define Additive Manufacturing and compare it with conventional CNC machining.

Additive Manufacturing (AM) is a manufacturing process in which a 3D object is created by adding material layer by layer from a digital CAD model. It uses materials such as polymers, metals and ceramics.

Comparison between Additive Manufacturing and CNC Machining

Additive Manufacturing>>

  1. Material is added layer by layer.
  2. Material is added layer by layer.
  3. Produces less material wastage.
  4. Complex shapes can be easily produced.
  5. Suitable for rapid prototyping and customization.
  6. Generally requires less tooling.

CNC Machining>>

  1. Material is removed from the workpiece.
  2. It is a subtractive process.
  3. Produces more material wastage.
  4. Complex shapes require multiple machining operations.
...
Continue reading "Additive Manufacturing: SLA, FFF, DfAM and Design Considerations" »

Active Directory: Estructura, Características e Funcionamento

Computer science2.58 KB

Active Directory

Active Directory é o termo que emprega Microsoft para referirse á súa implementación de servizo de directorio nunha rede distribuída. Permite crear un único inicio de sesión e un repositorio central de información para toda a súa rede, simplificando a administración de usuarios e equipos, e mellorando o acceso aos recursos.

Active Directory é unha implementación de servizo de directorio centralizado nunha rede distribuída que facilita o control, a administración e a consulta de todos os elementos lóxicos dunha rede (como poden ser usuarios, equipos e recursos).

É seguro, distribuído e replicado:

  • Está deseñado para funcionar tanto nun só servidor con algún obxecto como en múltiples servidores e millóns de
...
Continue reading "Active Directory: Estructura, Características e Funcionamento" »

Shell script

Computer science2.47 KB

Ejercicio de descuentos:

#!/bin/bash

read -p "¿Desea el billete también de vuelta? (s/n): " idavuelta

until [ $idavuelta=="s" ] || [ $idavuelta=="n" ]; do

read -p "¿Desea el billete también de vuelta? (s/n): " idavuelta

done

read -p "¿Tiene carnet joven? (s/n): " carnetjoven

until [ $carnetjoven="s" ] || [ $carnetjoven="n" ]; do

read -p "¿Tiene carnet joven? (s/n): " carnetjoven

done

descuento=0 billete=20

if [ $idavuelta="s" ]; then

descuento=20

billete=" expr $billete \* 2'

fi

if [ $carnetjoven="s" ]j then

descuento=30

fi

costefinal=`expr $billete \* \( 100 - $descuento \) / 100`

echo "El precio final del billete es $costefinal"



Ejercicio de medias:

#!/bin/bash

acu=0

cont=0

read -p "Introduce un numero: " num

while [ $num -ne 0 ]; do

acu=`expr $acu + $num`

cont=...

Continue reading "Shell script" »

Refer to the exhibit. A network administrator has segmented the network into two VLANs and configured Router1 for inter-VLAN routing. A test of the network, however, shows that hosts on each VLAN can only access local resources and not resources on t

Computer science20.53 KB

  1.  A network technician is configuring port Security on a LAN switch interface. The security policy requires host MAC Addresses to be learned dynamically, stored in the address table, and Saved to the switch running configuration. Which command does the technician Need to add to the following configuration to implement this Policy? Switch(config)# interface fa0/1 
    Switch(config-if)# switchport mode access 
    Switch(config-if)# switchport port-security

·Switch(config-if)# switchport port-security mac-address sticky

  1. On which switch interface would an Administrator configure an IP address so that the switch can be managed Remotely?

·VLAN 1

  1. Refer to the exhibit. Match the packets with Their destination IP address to the exiting interface on the router.
...
Continue reading "Refer to the exhibit. A network administrator has segmented the network into two VLANs and configured Router1 for inter-VLAN routing. A test of the network, however, shows that hosts on each VLAN can only access local resources and not resources on t" »

OpenSSL Encryption and Decryption Techniques

Computer science109.42 KB

OpenSSL Encryption and Decryption Commands

RC4 Symmetric Encryption

To encrypt the file "fichero.txt" using the RC4 symmetric encryption algorithm:

OpenSSL> rc4 -in c:\cifrado\fichero.txt -out c:\cifrado\cifrado.rc4
enter rc4 encryption password:
Verifying - enter rc4 encryption password:

To decrypt the previously encrypted file:

OpenSSL> rc4 -d -in c:\cifrado\cifrado.rc4 -out c:\cifrado\descifrado.txt
enter rc4 decryption password:

DES Encryption

Encrypting a file:

OpenSSL> des -salt -in c:\csb.log -out c:\csb.bf.txt
enter des-cbc encryption password:
Verifying - enter des-cbc encryption password:

Decrypting a file:

OpenSSL> des -d -in c:\csb.bf.txt -out c:\csb.txt
enter des-cbc decryption password:

Triple DES (DES3) Algorithm

Encrypting...

Continue reading "OpenSSL Encryption and Decryption Techniques" »

Processor and Memory Interface: CPU Datapath, Registers & ALU

Computer science967.85 KB

Processor & Memory Interface

Processor & Memory Interface: The maximum size of the memory that can be used in any computer is determined by the addressing scheme. For example, a computer that generates 16-bit addresses is capable of addressing up to 216 = 65,536 (≈ 64K) memory locations. Machines whose instructions generate 32-bit addresses can utilize a memory that contains up to 232 = 4,294,967,296 (≈ 4G) locations, whereas machines with 64-bit addresses can access up to 264 ≈ 1.84 × 1019 locations. The number of locations represents the size of the address space of the computer.

The connection between the processor and its memory consists of address, data, and control lines. The processor uses the address lines to specify the...

Continue reading "Processor and Memory Interface: CPU Datapath, Registers & ALU" »

The Complete HTTP Request Lifecycle Explained Step-by-Step

Computer science4.45 KB

1. Client Initiation and DNS Lookup

  • The user enters a URL or clicks a link in the browser. The browser parses the URL and extracts the domain (e.g., www.example.com).

  • A **DNS lookup** translates this domain into an IP address—acting like a digital phonebook entry.


2. Establishing the TCP Connection

The browser’s operating system (OS) creates a socket and initiates the **TCP three-way handshake** with the server:

  1. SYN: Client sends a synchronization request to the server.
  2. SYN-ACK: Server acknowledges the request and sends its own synchronization.
  3. ACK: Client acknowledges the server's response.

Once this handshake is complete, a full-duplex TCP connection is open and ready for reliable data exchange.


3. Sending the HTTP Request Message

The client constructs...

Continue reading "The Complete HTTP Request Lifecycle Explained Step-by-Step" »

Essential Python Programming Snippets

Computer science2.76 KB

File Handling

# Basic file reading
file = open("data.txt", "r")
content = file.read()          # Read entire file
lines = file.readlines()       # Read as list of lines
file.close()

# Reading line by line
file = open("data.txt", "r")
for line in file:
    print(line.strip())        # strip() removes \n
file.close()

# Write to file (overwrites)
file = open("output.txt", "w")
file.write("Hello World\n")
file.close()

# Append to file (adds to end)
file = open("output.txt", "a")
file.write("New line\n")
file.close()

Working with Lists

# Creating lists
numbers = [1, 2, 3, 4, 5]
names = ["John", "Maria", "Carlos"]

# Accessing elements
first = numbers[0]            # First element
last = numbers[-1]            # Last element
slice = numbers[1:4]
...
Continue reading "Essential Python Programming Snippets" »