Notes, summaries, assignments, exams, and exercises for Computer science for Other courses

Essential Data Structure Operations and Java Implementations

Computer science3.95 KB

Inserting the First Element into a Tree Structure

Method to add the first element (root) to a Tree Structure:

public void insertFirstNode(Object item)
{
    // If the tree is empty, the new node becomes the root of the tree
    if (theRoot == null)
    {
        Node theNewNode = new Node(item);
        theRoot = theNewNode;
    }
}

Deleting an Element from a Linked List

Method to remove an element at a specific index in a Linked List:

public void remove(int index) {
    // Special case: removing at the head of the list
    if (index == 1) {
        head = head.getNext();
    } else {
        // Find the previous and current node
        setCurrent(index);
        prev.setNext(curr.getNext());
    }
    size = size - 1;
}

Steps for Inserting an Element

...
Continue reading "Essential Data Structure Operations and Java Implementations" »

Networking Fundamentals: OSI Model, MAC Addresses, and Routing

Computer science3.4 KB

Networking Fundamentals Q&A

8. Switch vs. Bridge: Key Differences

Answer: Bridges receive the complete packet before forwarding it to the destination port. In contrast, a switch can start forwarding the packet before it is fully received (known as cut-through switching). This capability is a significant performance improvement.

10. Router Decisions in Packet Routing

Answer: A router must choose the best path (i.e., the fastest and shortest) using routing algorithms and consulting its routing table.

TCP/IP Protocol Stack Fundamentals

1. What is a Protocol?

In computer networks, a protocol is the language (a set of formal rules) that allows computers to communicate with each other. Using a common language prevents compatibility issues.

2. What is

...
Continue reading "Networking Fundamentals: OSI Model, MAC Addresses, and Routing" »

Windows NT Operating System Architecture and Features

Computer science2.5 KB

History of Windows NT

Windows NT was originally developed to be OS/2 3.0 before Microsoft and IBM discontinued their work on OS/2.

  • Unlike Windows 3.1, which was a GUI running on MS-DOS, Windows NT is a standalone operating system.

It is based on a microkernel, supporting up to 4GB of RAM, FAT file systems, NTFS, HPFS, built-in network support, multiprocessor support, and C2 security.

Windows NT Features

  • It is based on variations of the kernel of Mac UNIX. The microkernel architecture supports applications not originally designed for Windows NT.
  • It manages basic operations systems and other layers above them.
  • Supports five subsystems: Windows 32-bit, 16-bit Windows, DOS, POSIX, and OS/2.
  • Functions as a Client-Server in a network environment.
  • Allows development
...
Continue reading "Windows NT Operating System Architecture and Features" »

C Programming: Transaction and Vehicle Structs

Computer science6.92 KB

Section A: Transaction Data Management

Defining the Transaction Structure

A. Create a structure Transaction with the following attributes: ID (integer number), account_number (array of characters), amount (float), and typology (character).

typedef struct {
    char plate_number[PLATELENGTH + 1];
    char brand[NAMELENGTH];
    char model[NAMELENGTH];
    int production_year;
} Vehicle;

Constants for Transaction Typology

A. Define the max length for the attribute "account" to 20, and two constants to determine the typology of the transaction, such as CREDIT or DEBIT (respectively 'c' and 'd').

#define MAX_ACCOUNT_LEN 20
#define CREDIT 'c'
#define DEBIT 'd'

Reading Transaction Data from Input

A. Create a method named readInstance() that reads from the...

Continue reading "C Programming: Transaction and Vehicle Structs" »

JavaScript Evolution: JSONP and 3D Data Structures

Computer science4.27 KB

JavaScript: A Fast-Growing Language

JavaScript is a fast-growing language, with a lot of features being added to every release! These include:

  • JSONP
  • Arrow functions
  • Arguments and call arguments
  • Rest parameters
  • Blob and DOMString
  • A download button
  • apply() vs call()

Understanding JSONP (JSON with Padding)

JSONP (JSON with Padding) was a technique used before modern CORS support to get data from another website. JSONP (JavaScript Object Notation with Padding) is an older technique used to retrieve data from a server when normal AJAX requests using XMLHttpRequest (XHR) or fetch() are blocked by the browser's Same-Origin Policy.

Normally, when a client requests data from a server, the server returns plain JSON, such as { "value": 123 }, which is then parsed...

Continue reading "JavaScript Evolution: JSONP and 3D Data Structures" »

Essential C Programming Algorithms and Data Structures

Computer science3.78 KB

1. Infix to Postfix Conversion

#include <stdio.h>
#include <conio.h>
#include <ctype.h>

char stack[20];
int top = -1;

void push(char x) { stack[++top] = x; }
char pop() { return stack[top--]; }

int priority(char x) {
    if (x == '(') return 0;
    if (x == '+' || x == '-') return 1;
    if (x == '*' || x == '/') return 2;
    if (x == '^') return 3;
    return 0;
}

void main() {
    char exp[20];
    int i;
    char x;
    clrscr();
    printf("Enter Infix Expression: ");
    scanf("%s", exp);
    printf("Postfix Expression: ");
    for (i = 0; exp[i] != '\0'; i++) {
        if (isalnum(exp[i])) printf("%c", exp[i]);
        else if (exp[i] == '(') push(exp[i]);
        else if (exp[i] == ')') {
            while ((x =
...
Continue reading "Essential C Programming Algorithms and Data Structures" »

Essential Unity Game Development Concepts

Computer science2.94 KB

Sound in Unity

Definition: Sound in Unity is used to add audio effects and background music to games.

Components

  • Audio Source: Plays sound
  • Audio Clip: The audio file
  • Audio Listener: Receives sound

Concept and Application

The Audio Source plays the sound, while the Listener receives it. This adds realism to games and is used for both background music and sound effects.

Canvas and UI in Unity

Definition: The Canvas is used to create user interface elements like buttons, text, and menus in Unity.

Components

  • Canvas
  • Button
  • Text

Concept and Application

UI elements are placed inside the Canvas to facilitate user interaction. It is used in all games to display information such as scores, health, and menus.

Artificial Intelligence (AI) in Unity

Definition: AI in Unity...

Continue reading "Essential Unity Game Development Concepts" »

Essential C++ Programming Examples and Code Snippets

Computer science3.19 KB

Palindrome and Digit Sum Calculation

#include <iostream>
using namespace std;
int main() {
    int n, r, rev = 0, sum = 0, t;
    cin >> n; t = n;
    while (n) {
        r = n % 10;
        rev = rev * 10 + r;
        sum += r;
        n /= 10;
    }
    cout << (t == rev ? "Palindrome" : "Not");
    cout << "\nSum=" << sum;
}

Matrix Addition in C++

#include <iostream>
using namespace std;
int main() {
    int a[10][10], b[10][10], c[10][10], r, col;
    cin >> r >> col;
    for (int i = 0; i < r; i++)
        for (int j = 0; j < col; j++) cin >> a[i][j];
    for (int i = 0; i < r; i++)
        for (int j = 0; j < col; j++) cin >> b[i][j];
    for (int i = 0; i < r; i+
...
Continue reading "Essential C++ Programming Examples and Code Snippets" »

Java Programming Examples and User Registration Forms

Computer science2.08 KB

User Registration Form

Name:

Password:

Gender:
Male
Female

Hobbies:
Reading
Music

City:
SuratAhmedabad

Java Programming Examples

1. Simple Interest Calculation

import java.util.Scanner;
class SimpleInterest {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        float p, r, t, si;
        p = sc.nextFloat();
        r = sc.nextFloat();
        t = sc.nextFloat();
        si = (p * r * t) / 100;
        System.out.println("Simple Interest = " + si);
    }
}

2. Call Cost Calculation

import java.util.Scanner;
class CallCost {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int min;
        float rate, cost;
        min = sc.nextInt();
        rate = sc.nextFloat(
...
Continue reading "Java Programming Examples and User Registration Forms" »

Assembly Language Programming: Code Analysis and Solutions

Computer science4.63 KB

Assembly Language Code Analysis and Solutions

Section 1: Instruction Correctness Check

.data

calculate WORD 100
wVal DWORD 2

Instructions:

  1. mov bl, calculate
  2. mov ax, wVal

Question 1: Are the above two instructions correct? If not, justify your claim. [2 marks]

Answer:

Both instructions are incorrect.

  • For the mov operation, the operands must generally be of the same size.
  • In instruction 1, bl is 8 bits (1 byte), but calculate is defined as a WORD (16 bits or 2 bytes). The operand sizes do not match.
  • In instruction 2, ax is 16 bits (2 bytes), but wVal is defined as a DWORD (32 bits or 4 bytes). The operand sizes do not match.

Section 2: Loop Pseudo-code

Question 2: Write the pseudo-code for the loop that calculates the sum of the integers 3 + 2 + 1. [2 marks]

...
Continue reading "Assembly Language Programming: Code Analysis and Solutions" »