LJAI is a personal chatbot hosted in my private server, available on the WeChat platform by searching 爱打滚的玲酱, and now available via the Web platform! What makes LJAI different is the virtual and real mapping of our own cat. Recently, we have acquired over 120 users, and thousands of chat messages. http://veritayuan.com/lingjiang Compared with the…
My Chatbot in WeChat Platform
It is nothing related with AR and VR. But in the era of AI, who wouldn’t want to develop a cute chatbot? Feel free to scan the QR code below to follow our cute pet 🙂 Most of the code is based upon Python. I have developed the following functionalities. AIML matching Dictionary Idiom Wikipedia…
Quicksort, Mergesort, and Bucket sort in C
Quick Sort This is used in research code when builtin qsort does not satisfy the demands.
Quick sort
C++
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 
void qs(int l, int r){ int p, mid, i, j; i = l; j = r; mid = avg[(l + r) >> 1]; do { while (avg[i] < mid) ++i; while (avg[j] > mid) j; if (i <= j){ swap(avg[i], avg[j]); swap(order[i], order[j]); ++i; j; } } while (i < j); if (l < j) qs(l, j); if (i < r) qs(i, r); } 
Kth element Qsort can be used to find the Kth smallest element a[k]:
Find the Kth smallest element in C in O(log N) time via quick sort
1 2 3 4 5 6 7 8 9 10 11 12 13 14 
void Kth(int l,int r,int k) { int i = l,j = r,mid= a [(i + j) >> 1]; while (i <= j) { while (a[i] < mid) ++i; while (a[j] > mid) j; if (i<=j) { int t = a[i]; a[i] = a[j]; a[j] = t; ++i;j; } } if (k >= i && k<= r) Kth(i, r, k); if (k >= l && k<= j) Kth(l, j, k); } 
In Python,
215. Kth Largest Element in an Array
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 
class Solution(object): def kSort(self, a, l, r, k): i, j, p = l, r, a[(l + r) >> 1] while i < j: while a[i] < p: i += 1 while a[j] > p: j = 1 if i <= j: a[i], a[j] = a[j], a[i] i += 1 j = 1 if l < j and k <= j: self.kSort(a, l, j, k) if i < r and k >= i: self.kSort(a, i, r, k) def findKthLargest(self, nums, k): """ :type nums: List[int] :type k: int :rtype: int """ self.kSort(nums, 0, len(nums)  1, len(nums)  k) return nums[len(nums)  k] 
Use partition to sort 0, 0, 0, 1, 1, 2, 2, 2…
Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.
1 2 3 4 5 6 
void Solutions::sortColors(vector<int>& nums) { partition( partition(nums.begin(), nums.end(), bind1st(equal_to<int>(), 0)), nums.end(), bind1st(equal_to<int>(), 1) ); } 
Merge Sort Linked List Version Here…
April 2021 M T W T F S S « Nov 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 Clock
World
Random Posts
Share
Slideshow

Recent Posts
 Wearable Interactions Using Touch without a Touchscreen
 [Talk Summary] HandSight: A TouchBased Wearable System to Increase Information Accessibility for People with Visual Impairments
 [Talk Summary] A largescale analysis of YouTube videos depicting everyday thermal camera use
 [Summary] Google I/O and Microsoft Build 2018
 [Summary] StackGAN: Text to Photorealistic Image Synthesis
Twitter
My TweetsRecent Comments
 CS475 Algorithm Analysis and Design – Course  Ruofei Du on Treap in 45 lines of C++
 MA066 Advanced Algebra I – Course  Ruofei Du on Gradient, Circulation, Laplacian, Divergence, Jacobian, Hessian, and Trace
 Mr Zhu (@834144373zhu) on Tutorial of Ray Casting, Ray Tracing, Path Tracing and Ray Marching
 サンプリングレンダリングの解説記事 – Tech masuk on Tutorial of Ray Casting, Ray Tracing, Path Tracing and Ray Marching
 starea on Estimated Cost of Per Atom Function in Realtime Shaders on the GPU
Archives
 November 2018
 August 2018
 May 2018
 April 2018
 March 2018
 November 2017
 October 2017
 August 2017
 July 2017
 April 2017
 March 2017
 February 2017
 January 2017
 December 2016
 November 2016
 October 2016
 September 2016
 June 2016
 April 2016
 March 2016
 February 2016
 December 2015
 November 2015
 October 2015
 September 2015
 August 2015
 July 2015
 June 2015
 May 2015
 September 2014
 September 2012
 October 2010
 May 2010
 July 2008
Categories
Meta