Java Code Examples: Backpack & Maximum Subarray
Backpack Problem Implementation in Java
This code implements a solution to the Backpack problem using a depth-first search approach. The Alforja
class represents the backpack and its contents.
public class Alforja implements Solution {
private ArrayList<Integer> pesos;
private ArrayList<Integer> valors;
private ArrayList<Integer> alforja;
public static int MAXPES = 0;
public Alforja() {
pesos = new ArrayList<>();
valors = new ArrayList&
Read More
Satellite Communication and Radio Wave Fundamentals
Iridium Satellite Constellation
Iridium is the name of a constellation of 66 communications satellites orbiting the Earth in 6 low Earth orbits (LEO), each consisting of 11 evenly spaced satellites. Its name comes from the element Iridium, which has an atomic number of 77, equivalent to the number of satellites in the constellation, including its original design.
Radio Wave Fundamentals
Frequency
Frequency is a measure that is generally used to indicate the number of repetitions of any phenomenon or
Read MoreMarket Entry and Game Theory: Incumbent vs. New Entrant
Market Entry and Strategic Interaction: A Game Theory Perspective
**a) Payoffs with c=0**
There are three possible outcomes of the game, depending on the choices of the new entrant (entry vs. no entry) and of the incumbent firm (aggressive vs. passive behavior). In case of no entry, the incumbent will set the monopolist level of output. Let i be the incumbent label and e the new firm label. The monopolist quantity is qmi = 1/2 and the payoffs are Πmi = 1/4 and Πme = 0.
If the new firm enters the
Read MoreNetwork Simulation and Data Security: Practical Implementations
1. Implementing a Three-Node Point-to-Point Network
This section demonstrates a three-node point-to-point network with duplex links. We will set the queue size, vary the bandwidth, and determine the number of packets dropped.
TCL Script
set ns [new Simulator] set nf [open lab1.nam w] $ns namtrace-all $nf set tf [open lab1.tr w] $ns trace-all $tf proc finish { } { global ns nf tf $ns flush-trace close $nf close $tf exec nam lab1.nam & exit 0 } set n0 [$ns node] set n1 [$ns node] set n2 [$ns node]Read More
Strategic Analysis of Coloring, Network Formation, and Information Gathering Games
Coloring Game
Best Response in Polynomial Time
Definition of Best Response:
BR(s−i) = {ai ∈ Ai | ui(s−i , ai) = max (a’i∈Ai) (ui(s−i , a’i )} where:
- Ai is the set of actions for player i.
- ui(s−i , ai) is the utility for player i if all players except i play s−i and i plays ai.
In this game, the utility of a player p is equal to the number of neighbors of p that have the same color as p. A strategy profile s−p fixes the strategies of all other players. This means that their colors are fixed.
Read MoreEssential Bash Commands and C++ Fundamentals
Essential Bash Commands
- Use which -a to find the path to the Bash shell.
- Use echo -n to avoid trailing newlines.
- ls -l lists the content in long format.
- ls -a lists all content, including hidden files.
- ls -la combines both.
- pwd prints the current directory.
- Use man x to view the manual of command x.
- Use ~ to navigate to the home directory.
- mkdir creates directories.
- Multiple directories can be created at once by typing them in the same line.
- rmdir deletes an empty directory.
- rm -rf deletes a non-empty directory.