# Zero-Sum Game

## Definition

The utility functions of both players sum up to 0

## Equilibrium

#### Unique Equilibrium

• If the utility function of each player has concavity, then there exist a unique equilibrium.

# [Leetcode] Unique Path II

## Problem

Follow up for “Unique Paths”:
Now consider if some obstacles are added to the grids. How many unique paths would there be?
An obstacle and empty space is marked as `1` and `0` respectively in the grid.
For example,
There is one obstacle in the middle of a 3×3 grid as illustrated below.
`[  [0,0,0],  [0,1,0],  [0,0,0]]`
The total number of unique paths is `2`.
Note: m and n will be at most 100.

## Analysis

• Similar to Unique Path except that we need to decide whether a position has obstacle or not
• If yes, the number of ways to it is 0

# [Leetcode] Unique Path

## Problem

A robot is located at the top-left corner of a m x n grid (marked ‘Start’ in the diagram below).
The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked ‘Finish’ in the diagram below).
How many possible unique paths are there?

## Analysis

• 对于每一格，有两种到达它的方式，即从左边，或者从上边
• 所以 count[i][j] = count[i-1][j] + count[i][j-1]
• Time: O(n^2)
• Space: O(n^2)
• Space可以进行优化为O(n), 因为计算count每一行的值的时候只需要上一行的信息

# How to come up with new ideas in security domain

The followings are my own experience in finding research ideas in security domain.

## Ideas from Security Threat

• What the defenders can do to improve security?
• How to detect attackers?
• How to defend against attackers?

For the cloud computing problem, the defenders can be further divided into two categories: (1) Cloud provider (2) Cloud benign users

• What the attackers can do to increase damage?

## Ideas from Existing Work

• Improve
• Scalability of their mechanism
• Combine
• Can we combine other mechanisms with their mechanism
• New Problem
• Can we use the proposed mechanism to solve a different problem
• New Mechanism
• Can we solve the problem with a better mechanism

# Naming

## Naming Entities

• A name in a distributed system is a string of bits or characters that is used to refer to an entity
• Type of names
• The name of an access point of an entity
• Identifiers
• A name that uniquely identifies an entity
• Location-independent name
• A name that is independent from its addresses

## Name Resolution

• A naming system maintains a name-to-address binding for resources
• Main problem in naming
• How to do name resolution in a distributed systems in a scalable way
• Approaches for name resolution closely tied to naming scheme
• Flat vs Structure naming
• In a flat name space, identifiers are random bit strings
• No information on location embedded in name

## Name Resolution in a Flat Name Space

• Simple solutions that work in a LAN environment
• Broadcasting & Multicasting
• Message containing identifier of the entity is boardcast
• Machine with access point for the entity replies with the address of the access point
• ARP protocol for finding the data-link address of a machine given the IP address
• When network grows, multicast is more efficient
• Forwarding pointers
• When an entity moves from A to B, it leaves behind a reference to its new location at B
• Home-based Approaches
• Home agent keeps track of current location of mobile entity
• Hierarchical Approaches
• Similar to DNS

## What is a DHT

• Distributed Hash Table
• key = hash(data)
• lookup(key) -> IP address
• send-RPC(IP address, PUT, key, value)
• Send-RPC(IP address, GET, key)  -> value
• Chord

## Structure Naming Systems

• Names are organized into name spaces
• A name space can be represented as a labeled, directed graph wit two types of nodes
• Leaf nodes and directory nodes
• Absolute vs relative path names
• Local names vs global names
• Name resolution: the process of looking up a name
• Closure mechanism
• Knowing where and how to start name resolution
• Unix File Name Spaces

## Implementing Name Spaces

• Naming service
• A service that allows users and processes to add, remove, and lookup names
• Name spaces for large-scale widely distributed systems are typically organized hierarchically
• Three layers used to implement such distributed name spaces
• Global layer
• root node and its children
• Directory nodes within a single organization
• Managerial layer
• Example: DNS name space

## Iterative vs Recursive Resolution

### Recursive

• puts a higher performance demand on each name server
• cons
• Too high for global layer name servers
• Pros
• Caching is more effective
• Communication costs may be reduces
• Example

## Attribute-based Naming

• An entity is described in terms of (attribute, value) pairs
• Each entity can have several attributes
• Attribute-based naming service are called directory services
• LDAP (Lightweight directory access protocol) defacto industry standard
• Based on OSI X.500 directory service
• Another example: UDDI for web services

# Cloud Virtual Machine Allocation

## Concerns

When a user request for a virtual machine in the cloud, the cloud provider needs to allocate a VM for the user.

There are three concerns a cloud provider needs to take into account when doing the VM allocation.

• Power Consumption
• Security
• For security, we aim to avoid the cloud covert channel attacks in which an attacker seeks to be co-locate with the target VM in order to extract private information from the victims.

## Popular VM Allocation Policies

The following table [1] shows the popular VM allocation policies.

Reference
[1] Using Virtual Machine Allocation Policies to Defend against Co-resident Attacks in Cloud Computing, by Yi Han et al, in Transactions on Dependable and Secure Computing

# Vickrey-Clarke-Groves (VCG) Mechanism

## Introduction

• VCG can maximize the social welfare given the individuals are all “selfish”

## Model

• Players
• There are game players,
• Actions
• The actions of the players are denoted as
• Payoff
• Real demand
• Cost
• for its action
• Utility

## Definition

Following Nisan’s work, the terms “mechanisms” and “incentive compatible” are defined as

### Mechanism

• Given a set of n players, and a set of outcomes, A, let be the set of possible valuation functions of the form which player could have for an outcome . A mechanism is a function . Given the evaluations claimed by the players, f selects an outcome, and n payment functions, , where .

The above defines Action and Reward.

### Incentive Compatible

• For every player , every , , , , and every , where and , then
• , then the mechanism is incentive compatible.
Specifically, among those incentive compatible mechanisms, the Vickrey-Clarke-Groves (VCG) mechanism is the mostly used one.
The VCG generally seeks to maximize the social welfare of all players in one game, where the social welfare is calculated as . So the goal function of VCG is
The VCG mechanism and the rule to design VCG mechanisms are defined as follows.

### VCG Mechanism

• A mechanism, consisting of payment functions and a function , for a game with outcome set , is a Vickrey-Clarke-Groves mechanism if ( f maximizes the social walfare) for some functions , where (h_i does not depend on )
• , .

My understanding

• For user , its reward is depended on others, and not related to its action
• But why in the payment function, it deducts other users’ true value?

### Clarke Pivot Rule

• The choice is called the Clark pivot payment. Under this rule the payment of player is
• where .

My understanding

• I didn’t understand it yet.

# [Leetcode] Best Time to Buy and Sell Stock II

## Problem

Say you have an array for which the ith element is the price of a given stock on day i.
Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy one and sell one share of the stock multiple times). However, you may not engage in multiple transactions at the same time (ie, you must sell the stock before you buy again).

## Analysis

• Sum up all possible increase
• Time; O(n)
• Space; O(1)

Reference

# [Leetcode] Best Time to Buy and Sell Stock III

## Problem

Say you have an array for which the ith element is the price of a given stock on day i.
Design an algorithm to find the maximum profit. You may complete at most two transactions.

## Analysis

• 用一个数组pre记录在第i天或之前完成一个transaction的左右收益
• 用一个数组back记录从第i天或之后开始完成一个transaction的最大收益
• 则完成两个transactions的最大收益为 max(pre[i], back[i])

Reference

# [Leetcode] Best Time to Buy and Sell Stock

## Problem

Say you have an array for which the ith element is the price of a given stock on day i.
If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock), design an algorithm to find the maximum profit.

## Analysis

• 遍历数组，记录当前最小值，记录当前最大profit
• 当前profit = 当前值 – 当前最小值
• 时间复杂度: O(n)
• 空间复杂度: O(1)