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

Sort by
Subject
Level

Efficient AVL Tree Implementation in C++

Posted by Anonymous and classified in Computers

Written on in English with a size of 4.53 KB

Node Class Structure

The Node class defines the structure for each element in the AVL tree, storing a key, its corresponding meaning, and pointers to child nodes.

class Node {
public:
    string key, meaning;
    Node *lft, *right;
    int h8;
    Node(string k, string m) {
        key = k;
        meaning = m;
        lft = right = NULL;
        h8 = 1;
    }
};

AVL Tree Class Definition

The AVL class contains the logic for maintaining a self-balancing binary search tree.

Helper Functions for Balancing

These utility functions manage node height (h8), calculate the balance factor, and determine the maximum of two values.

class AVL {
    Node* root;
    int h(Node* n) { if (n == NULL) return 0; return n->h8; }
    int bal(Node* n) { if (n == NULL)
... Continue reading "Efficient AVL Tree Implementation in C++" »

John Doe — Software Engineer Resume | JavaScript & React

Classified in Computers

Written on in English with a size of 1.43 KB

John Doe

Software Engineer

Contact Information

Email: [email protected]

Phone: (123) 456-7890

LinkedIn: linkedin.com/in/johndoe

GitHub: github.com/johndoe

Experience

Software Engineer at XYZ Corp

Jan 2020 - Present

  • Developed and maintained web applications using JavaScript, HTML, and CSS.
  • Collaborated with cross-functional teams to define, design, and ship new features.
  • Wrote unit and integration tests to ensure code quality.

Junior Developer at ABC Inc.

Jul 2018 - Dec 2019

  • Assisted in the development of web applications using React and Node.js.
  • Participated in code reviews and provided constructive feedback.
  • Contributed to the maintenance and improvement of existing codebases.

Education

Bachelor of Science in Computer Science

University of Somewhere, 2014 -

... Continue reading "John Doe — Software Engineer Resume | JavaScript & React" »

Android Development Concepts: UI Components and Architecture

Posted by Anonymous and classified in Computers

Written on in English with a size of 11.09 KB

1. ListView vs RecyclerView Comparison

ListView

ListView is an older Android UI component used to display a scrollable list of items vertically. Each item is displayed one below another.

  • Uses Adapter to bind data.
  • Uses convertView for view reuse.
  • Only supports vertical scrolling.
  • Less efficient for large datasets.
  • No built-in animations.
  • ViewHolder pattern is optional.
  • Simple to use.
  • Suitable for small lists.

Example:

ListView listView = findViewById(R.id.listview); 
// ArrayAdapter<String> adapter = 
// new ArrayAdapter<>(this, 
// android.R.layout.simple_list_item_1, data); 
///listView.setAdapter(adapter);

RecyclerView

RecyclerView is an advanced and flexible version of ListView, introduced in Android.

  • Uses ViewHolder pattern by default.
  • Highly
... Continue reading "Android Development Concepts: UI Components and Architecture" »

Prolog Implementation of Traveling Salesperson Problem

Posted by Anonymous and classified in Computers

Written on in English with a size of 4.75 KB

This document presents two distinct approaches to solving the Traveling Salesperson Problem (TSP) using Prolog: an exact, brute-force method and a heuristic-based Nearest Neighbor algorithm. Both implementations are demonstrated with code and sample queries.

Exact Solver: Brute-Force TSP Algorithm

This section details a Prolog program that finds the optimal (shortest) path for the Traveling Salesperson Problem by generating and evaluating all possible tours. This method guarantees the optimal solution but can be computationally intensive for larger sets of cities.

Defining City Distances in Prolog

The distances between cities are defined using dist/3 facts. The predicate is made symmetric to ensure that dist(X,Y,D) implies dist(Y,X,D).

dist(a,b,
... Continue reading "Prolog Implementation of Traveling Salesperson Problem" »

LEGv8 Architecture and Assembly Language: Key Concepts

Classified in Computers

Written on in English with a size of 239.58 KB

Performance Metrics

  • Elapsed Time: Represents overall system performance. It is the total time taken to complete a task.
  • User CPU Time: Indicates CPU performance. It is the time the task actively runs on the CPU, excluding idle time.
  • CPU Time: The time the CPU spends executing instructions, either from the task or the operating system, excluding idle time.
  • Clock Speed: 1 MHz equals 1 million clock cycles per second. 1 GHz equals 1 billion clock cycles per second.
  • Response Time: Equivalent to execution time.
  • Throughput: Equivalent to bandwidth.
  • Performance Comparison: (PerfA) / (PerfB) = (ExecTimeB) / (ExecTimeA) = n

Impact of Processor Upgrades

  • Replacing a processor with a faster one decreases response time and increases throughput.
  • Adding an additional
... Continue reading "LEGv8 Architecture and Assembly Language: Key Concepts" »

Implementando 4x4 Matriz Transposta em Linguagem C

Classified in Computers

Written on in English with a size of 2.66 KB

Implementação da Transposição de Matriz 4x4 em C

Este programa em C demonstra como calcular e exibir a matriz transposta (B) de uma matriz quadrada de ordem 4 (A). A transposição é realizada trocando as linhas pelas colunas, ou seja, o elemento na posição A[i][j] é copiado para B[j][i].

Código Fonte em C para Transposição de Matriz

O código utiliza as bibliotecas padrão stdio.h para entrada/saída e conio.h (comum em ambientes legados) para controle de console.

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

int main()
{
    int i, j, A[4][4], B[4][4];

    // 1. Entrada de Dados
    printf("Insira os elementos da Matriz A (4x4):\n");
    for(i = 0; i < 4; i++)
    {
        for(j = 0; j < 4; j++)
        {
            printf(
... Continue reading "Implementando 4x4 Matriz Transposta em Linguagem C" »

Java AWT GUI Development and OOP Inheritance

Posted by Anonymous and classified in Computers

Written on in English with a size of 7.41 KB

Building Java GUI Applications with AWT

Creating GUI applications using Abstract Window Toolkit (AWT) involves setting up a top-level container, adding components, arranging them with a Layout Manager, and making the container visible.

Steps to Create an AWT Application

1. Choose a Top-Level Container

The application needs a primary window to hold all components. The most common choice is the Frame class, which provides a title bar, borders, and window controls.

import java.awt.*;

// Class extends Frame to be the application window itself
public class AWTExample extends Frame {
    // Constructor and other methods
}

2. Initialize the Container (The Frame)

Inside the constructor, you set up the basic properties of the window:

  • Title: Set the window
... Continue reading "Java AWT GUI Development and OOP Inheritance" »

Database Fundamentals: SQL Queries and Relational Concepts

Posted by Anonymous and classified in Computers

Written on in English with a size of 99.31 KB

Core Database Concepts and Relational Algebra

Question 1: Cartesian Product Size

Question 1: S is a relation instance. If S has 6 tuples, how many tuples are there in the result of the following SQL query?

SELECT * FROM S S1, S S2;

Answer: 36 (Calculated as 6 * 6, representing the Cartesian product of S with itself.)

Question 2: Maximum Tuples and Primary Keys

Question 2: Let R(A, B, C, D) be a relation, where (A, B, C) is the Primary Key (PK) of R, and attribute D cannot be NULL. Assume A's domain has 5 different values, B's domain has 2, C has 4, and D has 3. What is the maximum number of tuples that can be in an instance of R?

Answer: 40 (Calculated as 5 * 2 * 4. The maximum number of tuples is determined by the product of the domain sizes of the... Continue reading "Database Fundamentals: SQL Queries and Relational Concepts" »

Essential Java Programming Concepts and Design Patterns

Posted by Anonymous and classified in Computers

Written on in English with a size of 237.87 KB

Java File Copy Program

This simple Java program demonstrates how to read data from one file and write it to another.

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class FileCopy {
    public static void main(String[] args) {
        String sourceFile = "input.txt";
        String destinationFile = "output.txt";
        try {
            FileReader fr = new FileReader(sourceFile);
            FileWriter fw = new FileWriter(destinationFile);
            int character;
            while ((character = fr.read()) != -1) {
                fw.write(character);
            }
            fr.close();
            fw.close();
            System.out.println("File copied successfully.");
        } catch (IOException
... Continue reading "Essential Java Programming Concepts and Design Patterns" »

C++ & C Programming Solutions: Algorithms & Patterns

Classified in Computers

Written on in English with a size of 5.13 KB

1. Anagram Detection: C++ String Comparison

This C++ program determines if two input strings are anagrams of each other. It achieves this by converting both strings to lowercase, sorting their characters alphabetically, and then comparing the sorted strings. If they are identical, the original strings are considered anagrams.


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

int main(){
    string s2,s1;
    cin>>s1>>s2;
    transform(s1.begin(),s1.end(),s1.begin(),::tolower);
    transform(s2.begin(),s2.end(),s2.begin(),::tolower);
    sort(s1.begin(),s1.end());
    sort(s2.begin(),s2.end());
    cout<< (s2==s1);
}

2. Array Subarray: C++ Sliding Window Minimum

This C++ program attempts to find the maximum of minimums within... Continue reading "C++ & C Programming Solutions: Algorithms & Patterns" »