Emre Kalaycı

Emre Kalaycı

Data Engineer

Home1Writing2Notes3Substack4Bookmarks5Gallery6
Online
X (Twitter)GitHubLinkedinGoodreadsGoodreadsLetterboxdLetterboxdInstagramResume
Notes
RSS feed
Deneme 1February 02, 2025 Deneme2February 02, 2025 Deneme3February 02, 2025
Loading...
Deneme2

Deneme2

February 02, 2025

1- chatbot-component

User Profile Picture

Explain the primal-dual method to someone completely new to algorithms and graph theory.

ChatGPT Profile Picture

Alright! Let's start with a simple analogy before diving into the specifics of the primal-dual method:

Analogy: Shopping on a Budget

Imagine you are shopping for fruits with a limited budget. You want to buy as much fruit as possible without exceeding your budget. On the other side, the shopkeeper wants to sell the fruits at a price where he can earn the most profit without losing customers. In this situation:

  • Your goal of maximizing the amount of fruit represents the "primal" problem.
  • The shopkeeper's goal of pricing the fruits represents the "dual" problem.

In an ideal world, the amount you are willing to pay for each fruit (based on your budget and desire) would match exactly with the prices the shopkeeper sets, resulting in the most efficient shopping transaction for both of you.

Now, translating this analogy to the realm of algorithms:

Primal-Dual Method

The primal-dual method is an approach used primarily in optimization problems. In many of these problems, you have a primary (or "primal") problem that you want to solve, but there's also a related "dual" problem that offers a different perspective. Often, by solving the dual problem, we can gain insights into the primal problem or vice versa.

  1. Primal Problem: This is the original problem you want to solve. For example, it might be about finding the shortest path in a graph or maximizing some kind of profit.

  2. Dual Problem: This is a related problem that is derived from the primal problem. The solution to the dual problem often gives a bound or limit to the solution of the primal problem. If the solutions to the primal and dual problems are the same, we have an optimal solution.

The primal-dual method involves:

  • Starting with an initial feasible solution to the dual problem.
  • Using this solution to guide the search for a feasible solution to the primal problem.
  • Repeatedly updating both solutions until they converge to an optimal solution.

Why is it useful?

The power of the primal-dual method lies in the fact that while the primal problem might be hard to solve directly, its dual problem might be easier. Or, solving the dual can give us insights, bounds, or approximations to the primal solution.

Connection to Graph Theory: In graph theory, there are many problems (like network flow problems) where the primal might represent a flow configuration on the graph, and the dual might represent some sort of cost or capacity constraint. The primal-dual method can be applied to get efficient solutions for such problems.

Conclusion: Just like in our shopping analogy, where both you and the shopkeeper are trying to optimize your outcomes (with buying fruits and pricing them), in algorithms, the primal and dual problems offer two sides of the same coin. Solving or approximating one can give us valuable information about the other!


2- boxs

Warning: Discrete math, graph theory, and combinatorial optimization ahead! If you're unfamiliar with the mathematical symbols used in this writeup, reference this dropdown:

Complicated Math Symbols
  • ∑\sum∑ - Summation
  • ∈\in∈ - Element of
  • ∉\notin∈/ - Not an element of
  • ⊂\subset⊂ - Proper subset of
  • ⊆\subseteq⊆ - Subset of
  • ∅\emptyset∅ - Empty set
  • ∀\forall∀ - For all
  • ∃\exists∃ - There exists
  • ∄\nexists∄ - There does not exist
  • ∈\in∈ - Element of
  • ∉\notin∈/ - Not an element of
  • ∋\ni∋ - Contains as member
  • ∌\not\ni∋ - Does not contain as member
  • ∖\setminus∖ - Set minus (drop)
  • ⊕\oplus⊕ - Direct sum
  • ∪\cup∪ - Union
  • ∩\cap∩ - Intersection
  • x′x'x′ - Prime

Definition: A set of edges EEE is defined as E⊂(x,y) ∣ (x,y)∈V2 and x≠yE \subset \\{(x, y)\ |\ (x, y) \in V^2 \textrm{ and } x \neq y\\}E⊂(x,y) ∣ (x,y)∈V2 and x=y. By this definition, xxx and yyy are the vertices that are connected to the edge eee, called the endpoints. It can also be said that eee is incident to xxx and yyy.

info: A set of edges EEE is defined as E⊂(x,y) ∣ (x,y)∈V2 and x≠yE \subset \\{(x, y)\ |\ (x, y) \in V^2 \textrm{ and } x \neq y\\}E⊂(x,y) ∣ (x,y)∈V2 and x=y. By this definition, xxx and yyy are the vertices that are connected to the edge eee, called the endpoints. It can also be said that eee is incident to xxx and yyy.

Definition: A set of edges EEE is defined as E⊂(x,y) ∣ (x,y)∈V2 and x≠yE \subset \\{(x, y)\ |\ (x, y) \in V^2 \textrm{ and } x \neq y\\}E⊂(x,y) ∣ (x,y)∈V2 and x=y. By this definition, xxx and yyy are the vertices that are connected to the edge eee, called the endpoints. It can also be said that eee is incident to xxx and yyy.

theorem: A set of edges EEE is defined as E⊂(x,y) ∣ (x,y)∈V2 and x≠yE \subset \\{(x, y)\ |\ (x, y) \in V^2 \textrm{ and } x \neq y\\}E⊂(x,y) ∣ (x,y)∈V2 and x=y. By this definition, xxx and yyy are the vertices that are connected to the edge eee, called the endpoints. It can also be said that eee is incident to xxx and yyy.

flag: A set of edges EEE is defined as E⊂(x,y) ∣ (x,y)∈V2 and x≠yE \subset \\{(x, y)\ |\ (x, y) \in V^2 \textrm{ and } x \neq y\\}E⊂(x,y) ∣ (x,y)∈V2 and x=y. By this definition, xxx and yyy are the vertices that are connected to the edge eee, called the endpoints. It can also be said that eee is incident to xxx and yyy.

default: A set of edges EEE is defined as E⊂(x,y) ∣ (x,y)∈V2 and x≠yE \subset \\{(x, y)\ |\ (x, y) \in V^2 \textrm{ and } x \neq y\\}E⊂(x,y) ∣ (x,y)∈V2 and x=y. By this definition, xxx and yyy are the vertices that are connected to the edge eee, called the endpoints. It can also be said that eee is incident to xxx and yyy.



4- #code patterns

#include <iostream>

int main() {
    int i = 1;
    while (i <= 100) {
        std::cout << i << std::endl;
        i++;
    }
    return 0;
}
Terminal
yarn create next-app nextjs-mdx-blog
JavaScript
lib/mdx.js
import path from 'path'

const POSTS_PATH = path.join(root, 'data', 'blog')
// Output: A:\nextjs-mdx-blog\data\blog => Command line example
React
pages/bookmarks.tsx
import { categories } from '@/config/bookmarks'
import Sidebar from '@/components/sidebar'
import BookmarkCard from '@/components/unorder-card'

const BookmarksPage: React.FC = () => {
    const [activeCategory, setActiveCategory] = useState<string | null>(categories[0]?.name || null)
    const [currentPage, setCurrentPage] = useState(1)
    const [searchTerm, setSearchTerm] = useState('')
    const [isContentVisible, setIsContentVisible] = useState(false)
    const [isSidebarVisible, setIsSidebarVisible] = useState(false)
    const [isClient, setIsClient] = useState(false)
Python
handsonMl/09_unsupervised_learning.ipynb
def plot_data(X):
    plt.plot(X[:, 0], X[:, 1], 'k.', markersize=2)

def plot_centroids(centroids, weights=None, circle_color='w', cross_color='k'):
    if weights is not None:
        centroids = centroids[weights > weights.max() / 10]
    plt.scatter(centroids[:, 0], centroids[:, 1],
                marker='o', s=35, linewidths=8,
                color=circle_color, zorder=10, alpha=0.9)
    plt.scatter(centroids[:, 0], centroids[:, 1],
                marker='x', s=2, linewidths=12,
                color=cross_color, zorder=11, alpha=1)
components
Layout.js
data
blog
markdown.mdx
nextjs.mdx
react.mdx
lib
formatDate.js
mdx.js
pages
blog
[slug].js

6 tweetcard

7 challenge

Murder Mystery
Solvers
undefined's avatar
,
undefined's avatar
Category
osint
Points
499

While searching for secrets of the past, you find a scrap of paper that contains the following information: ```text 01101110011100100110100001110000011010- 01011001000100110001001011110100001111 June 29, 1902 ``` Because you're great at OSINT, you trace this information back to a famous inscription. What is that inscription? **Flag**: `byuctf{inscription_with_underscores}` **Note**: the flag will not include the name or dates found in the inscription.

gcd-query-v1
Authors
Category
algo
Points
475
Solves
43

I wonder if this program leaks enough information for you to get the flag with less than 2048 queries... It probably does. I'm sure you can figure out how. `nc amt.rs 31692`

7- country

ImageCountry of OriginPopulationFlag
1.pngtr Turkey84,680,273 (2021)T
2.pngec Ecuador18,145,568 (2023)E
3.pnges Spain47,615,034 (2022)S
4.pngth Thailand66,883,467 (2023)T
5.pngva Vatican City825 (2019)_
6.pngfi Finland5,528,796 (2022)f
7.pnglt Lithuania2,839,020 (2022)l
8.pngar Argentina47,327,407 (2022)A
9.pngge Georgia3,688,600 (2022)g
Previous PostDeneme 1
Next PostDeneme3