{"@attributes":{"version":"2.0"},"channel":{"title":"Algorithm on Openinx Blog","link":"https:\/\/openinx.github.io\/tags\/algorithm\/","description":"Recent content in Algorithm on Openinx Blog","image":{"title":"Openinx Blog","url":"https:\/\/openinx.github.io\/%3Clink%20or%20path%20of%20image%20for%20opengraph,%20twitter-cards%3E","link":"https:\/\/openinx.github.io\/%3Clink%20or%20path%20of%20image%20for%20opengraph,%20twitter-cards%3E"},"generator":"Hugo -- 0.125.7","language":"en","lastBuildDate":"Tue, 16 Sep 2014 13:27:08 +0800","item":[{"title":"Google 2015 Campus Hiring Written Test \u2014 Round B","link":"https:\/\/openinx.github.io\/posts\/2014-09-16-google-apac-2015-test-round-b\/","pubDate":"Tue, 16 Sep 2014 13:27:08 +0800","guid":"https:\/\/openinx.github.io\/posts\/2014-09-16-google-apac-2015-test-round-b\/","description":"I took Google&rsquo;s online campus hiring written test yesterday. Skip algorithms for a day and your skills slide right back down.\nProblem A. Password Attacker Description How many passwords of length M can be formed from N distinct characters, such that every password uses all N characters at least once?\nSolution 1: Brute Force For each solution to the equation below, add the number of distinct permutations. If one solution is X1, &hellip;, Xn, that group contributes M!"},{"title":"LeetCode 151 Summary","link":"https:\/\/openinx.github.io\/posts\/2014-07-20-leetcode-151-finished\/","pubDate":"Sun, 20 Jul 2014 13:27:08 +0800","guid":"https:\/\/openinx.github.io\/posts\/2014-07-20-leetcode-151-finished\/","description":"After grinding LeetCode for several days, I finally finished. Code is here.\nReverse Words in a String Simulation on strings\nEvaluate Reverse Polish Notation Simulation \u2014 evaluate postfix expressions\nMax Points on a Line Given N points in the plane, find a line that passes through the most points. Enumerate each point as the origin, compute relative coordinates, then compute y\/x and use a hash table to count duplicates and find the maximum."},{"title":"Kazoo, the ZooKeeper Python Client","link":"https:\/\/openinx.github.io\/posts\/2014-06-07-learning-from-kazoo\/","pubDate":"Sat, 07 Jun 2014 13:27:08 +0800","guid":"https:\/\/openinx.github.io\/posts\/2014-06-07-learning-from-kazoo\/","description":"Zookeeper hardly needs an introduction \u2014 it is a distributed coordination service. A few questions I was curious about:\nHow does ZooKeeper implement asynchronous watcher callbacks? (code-level details) How does ZooKeeper implement distributed locks? How do Queue, barrier, and similar recipes work? I read the Python client kazoo and got the general picture.\nA simple client example #!\/usr\/bin\/python import logging from time import sleep from kazoo.client import KazooClient # print log to console logging."},{"title":"The K-th Element in Algorithms","link":"https:\/\/openinx.github.io\/posts\/2014-03-02-the-k-the-number-in-algorithm\/","pubDate":"Sun, 02 Mar 2014 13:27:08 +0800","guid":"https:\/\/openinx.github.io\/posts\/2014-03-02-the-k-the-number-in-algorithm\/","description":"Source code and related articles are available here.\nThis article discusses the K-th largest or K-th smallest element in a sequence. Since the K-th largest can be reduced to finding the (N\u2212K+1)-th smallest (where N is the sequence length), we focus on the K-th smallest element.\nProblems covered in this article:\nGiven an integer sequence, find the K-th smallest element. Given an integer sequence that supports dynamic updates, answer queries for the K-th smallest element."},{"title":"How Redis Implements Its Dictionary","link":"https:\/\/openinx.github.io\/posts\/2014-02-13-the-implement-of-redis-dict\/","pubDate":"Thu, 13 Feb 2014 13:27:08 +0800","guid":"https:\/\/openinx.github.io\/posts\/2014-02-13-the-implement-of-redis-dict\/","description":"Hash Table\nA hash table is an array of size buckets, table[0...size-1]. Hashing an object yields an index; we store the object in table[value]. When a bucket holds multiple objects, they are chained into a linked list. This collision strategy is called separate chaining.\nLoad Factor\nIf a hash table has size buckets and used stored elements, used \/ size is the load factor. When loadFactor &lt;= 1, expected lookup cost is O(1)."},{"title":"Plane Sweep Techniques in ACM Programming Contests","link":"https:\/\/openinx.github.io\/posts\/2013-01-01-plane-sweep-thinking\/","pubDate":"Tue, 01 Jan 2013 13:27:08 +0800","guid":"https:\/\/openinx.github.io\/posts\/2013-01-01-plane-sweep-thinking\/","description":"Abstract: Plane sweep is widely used in computational geometry, computer graphics, grid computing, and related areas. Many classic algorithms use plane sweep to greatly reduce time complexity \u2014 e.g. segment intersection, union of axis-aligned rectangle perimeters, rectangle intersection, spatial collision detection, Voronoi diagram construction, closest pair of points, and more.\nThis article introduces several plane sweep algorithms commonly used in ACM programming contests. By purpose, they fall into:\nData aggregation; Detecting geometric positional relationships; Closest pair of points."}]}}