Showing posts sorted by relevance for query quicksort. Sort by date Show all posts
Showing posts sorted by relevance for query quicksort. Sort by date Show all posts

Tuesday, February 2, 2016

quicksort: a practice makes difference

February 2, 2016

Introduction


Julia likes to work on basic things on algorithm problem solving, like brute force solution, recursive function design, divide and conquer solution, partitioning; So, she can write code everyday on algorithm.

Review the quicksort algorithm, and then, practice using C# programming language. So many times Julia went through the review of quick sort algorithm, but to write it in less than 10 minutes, without a bug, without stress, takes more dedicated effort - maybe write a blog to share will help.   

Julia likes to rewrite the above paragraph in April 9, 2018.

Quicksort warmup


First review the blog - the quick algorithm written in Java programming language. Julia must like the idea of choosing pivot value - "// simple version - pick the right most value as the pivot ". As a sports programmer, Julia knows that the power of using a simple test case, she likes to do it here. 


Let us describe how quick sort works: - explain it using 5 minutes - 10 minutes to write the code 
1. First, using partition, and then, divide and conquer, use recursive function calls to solve the problem.
Most important technique, is to design a partition - 2-way partition, how to design the partition, choose pivot point, and how to do partition step by step.

Let us work on a simple example and have discussion, show the procedure of partition.
Let us say that array 1, 2, 3, 4, 5, 6, sorted, and then we like to derive the above sorted array using this one, 1, 3, 2, 5, 4, 6.

One of ideas to choose pivot position, is to choose last number in the array.  For the example, choose last one in the array, 6, the position of pivot point, left side <= 6, right side > 6. So, do you see the problem, 6 is not ideal case. No swap, second partition with 0 values; in other words, all values go to first partition. 

Two way partition


Let us work on another order: 1, 6, 2, 5, 4, 3, 

1. Choose pivot value - last element in the array, value 3
2. Work on partition the array, left partition <= 3, right partition > 3
3. Two partitions are 1, 2, 6, 5, 4, 3
4. Put the pivot point in-between, 1, 2, 3,  6, 5, 4
5. Divide and conquer, solve two small subproblems, use recursive call. 

Use a diagram to show progress:      
Scan the array once from left to right, and then keep track of the start position of right partition. Anything less than 3 will be in left partition.  

The easy way to remember is to find right partition's start position. 

Two way partition - test case

1, 2, 6, 5, 4, 3  -> move pivot value 3 between two partitions
1, 2, 3,  6, 5, 4

Step by step, 
first, after partitioning, the array is the following:
1, 2, 6, 5, 4, 3 
so right side partition starting from array's index value 2 to 4, values are highlighted in background color of green. 

Left side partition:
1  2
left partition, array's index is from 0 to 1. 

Right side partition -  start and end position. 
6 5 4 
right partition, array's index is from 2 to 4. 

And then the pivot value 3 is inserted in-between left partition and right partition. 
1, 2, 3,  6, 5, 4

Let us recap what we practice here, go over a simple test case, and then choose a pivot value, and then partition, divide and conquer, go to solve two small problems using recursive calls. 

Julia's practice:
Quick sort algorithm writing in C# - less than 20 minutes (18 minutes to write the code with comments)


Quicksort Lecture Study


Julia, spend one hours to read the webpage, and enjoy the great lecture. Reading is much important than coding. And then, work on some questions in the lecture.

princeton lecture notes

Questions and Answers


February 3, 2016

After reading her favourite lecture notes, Julia likes to respond something to entertain quicksort algorithm practice, put something together with her own thinking based on discussion from reading material:

Fact 1:
Q1. Quick sort algorithm will work even in worst case, no dead loop. Why? 
Arguments:
1. Each recursive function, at least one value is resolved, no more work for the value. That is pivot point. So, at most, each recursive call solves one value, n recursive call will solve all n values in the array. Is it fun to design the algorithm? Yes.

Q2. Quicksort function design - only solve one value to position correctly, in the whole array. This is not efficient? 
Arguments:
1. This is the fact. And it works fine. And if you remember that, you can write a quick sort algorithm in less than 5 minutes. 
2. So, position one value, partition array into two sections. 

Q3. Partition can use different strategies, only important and should work on more is to find one, work out as fast as you can. And make it easy to remember. What is your advice? 
Advice:
  Choose last one in the array as a pivot point, and then, find the partition - swap and maintain a partition (each value in the partition  >  pivot value) just on right side of array. Use two pointers to find the partition two values - start, end position. 

Q4. Is this algorithm using in-place without extra space? 
Answer: 
Yes, the answer is staying in the original array, no extra space (O(1), not O(n)). So, array is used to store result, only swap two nodes' value if need. 

Facts: at most how many swap?     it depends. O(n^2)
           How many recursive calls?  n 

Because it is using in-place, the quicksort function design takes 3 input arguments, original array, start, end. 

If you cannot come out best design using in-place, you may need extra time. 

Feb. 4, 2016 Q5. Work on Leetcode - partition list
86. Partition list
http://www.cnblogs.com/springfor/p/3862392.html

328. Odd Even Linked List


Follow up after 9 months


Nov. 24, 2016
Review the code review about quick sort. 
Answer the question, link is here.  


Follow up after 13 months


March 14, 2017
1. Read all algorithms in the blog, the blogger got Google and Linkedin offer. The algorithms may be a good study material for Julia.

2. Practice one more time, C# code. Add test case for partition method and quicksort method. 

Saturday, March 25, 2017

Code Review: Quicksort

March 25, 2017

Introduction

Sorting is the most important things in a programmer's life. Julia was so excited to know her first review of quicksort algorithm was chosen as the answer. But she has to keep up learning and makes a wise investment on learning quicksort.

Code review


Integer quicksort in Java



Thursday, October 20, 2016

Tech events in 2016

Oct. 20, 2016

Introduction


Julia loves to attend tech events and meet people in the city of Vancouver and also in the city of Seattle in 2016. So far in 2016, she has attended more than 6 tech events. Two hosted by Microsoft, SQL server in Seattle (March 31, Microsoft Database Systems Engineering Open House), Vancouver Tech Woman in Vancouver (Sept.); Two hosted by Amazon (May 3, Amazon web service talk; June 23, RDS talk); One by Arista Network; One by Tableau, algorithm/ data structure interview workshop.

Seattle two day vacation - tech event trip

Such a beautiful season with tour of Seattle, so many good memories and good laughs with friends.

Microsoft:
In March of 2016, she took 2 days vacation and drove to the city of Seattle to attend Microsoft SQL server tech event, and visited her FAU classmates in Seattle.

And then, she visited the headquarter of Amazon, near union lake.

Tech events are fun
She had such great time to watch the video and learned a few things on Oct. 19, 2016

Grace Hopper Celebration of Women in Computing

https://www.facebook.com/gracehoppercelebration/



Entertainment episodes in tech event:

1. Episode 1

Personal coding blog is such an entertainment topic in tech event:

A senior principle programmer (A) and Julia's conversation:

A's Questions: Who can tell quicksort best performance or worst performance?

Julia:
I can tell, the worst of quicksort is linear. Because I just wrote a blog about quicksort.

A's question: where is the blog? Show me on my cellular phone?

Julia:

"Julia coding blog" search Google.com
"quick sort" search blog

2. Episode 2

A senior principle programmer (A) and Julia's conversation:

A's question: why do you write she instead of I?

Julia:
It is more close to reader, instead of I, I, I, too self-center; I choose to write as she likes; it is a style. More picky, close to reader instead using "I".

A's question: where is the code? Show me your code.

Julia:

...


2010 - 2015 five years


Julia attended more than 5 social events in the city of Vancouver (from 2010 to 2015) hosted by facebook. And almost every time, she asked around how to improve algorithm problem solving, being competitive on algorithm problem solving.

She learned a lot, but she wanted to be a competitive programmer.

After 5 years full time job as a software programmer, she knows how weak her thinking muscle on algorithm. So, she decided to change, journal her practice through her personal coding blog in the city of Vancouver.

2015 - Now


She decided to take some risk, and take algorithm problem solving as a highest priority in her life; she works on goals she has more control, like HackerRank contest performance improvement.

Writing is most challenging for her, so she started to write more through her coding blog, and also log her practice very honestly.

Best learning is by doing, not just reading other people's work; Best learning is also a sharing, willing to take some risk to make mistakes, share the pain, struggling to make a little progress every time, and get connected to more people, motivate others to work hard as well.

Share my favorite quote about practice - when to stop?

Monday, May 9, 2016

HackerRank: Algorithms > Sorting

May 9, 2016

Work on Sorting Challenges:

Value the easy question. Write your own code, and then, study other's submission. Rewrite the code again and again, learn how to stay focus, and avoid common mistakes in writing.

1. Insertion Sort - Part 1 (Easy)

2. Insertion Sort - Part 2 (Easy)

3. Correctness and the Loop Invariant

4. Running Time of Algorithms

5. Quicksort 1 - Partition

6. Quicksort 2 - Sorting

7. Quicksort In-Place


Monday, March 13, 2017

Quick Search - Julia's first answer on code review

March 13, 2017

Julia got a big surprise today, her first day work on code review to answer a question on quick search was selected as the answer today, after more than 3 months, she noticed that she got 25 reputation.

The code review link is here. She has to celebrate a little bit, it was a long time she tried to find some activities to help others while she is struggling to invent herself, keep up with others in this computer science technology world.

Julia searched her blog using quicksort, and then she found somethings to review related to quicksort.

Make it more memorable, Julia uses an image and music to celebrate her good working spirit.


Jessica Simpson - Take my breath away

When  Julia read this news, she was so excited, take my breath away, a little exaggerated, reminded her a song - the old lovely song, feels good to help others and make her own mark. One step a time, ...

Actionable Items


1. Read all algorithms in the blog, the blogger got Google and Linkedin offer. The algorithms may be a good study material for Julia.

2. Review the C# implementation of quicksort, write a new one.


Friday, September 2, 2016

Book reading: competitive programming

Sept. 2, 2016

Plan to spend 30 minutes a time, up to 10 hours to read a short book - 152 pages first.

Competitive programming course:

Free download - version 1


Julia spent more than 1 hour to look into lead board of HackerRank, and then, she found the book to read:

https://algo.is/
competitive programming course

https://sites.google.com/site/stevenhalim/

Free download - version 1

Competition course


Julia is looking for a book talking about suffix array etc. advanced data structure. She found one today.

Write down some great ideas after reading. 

1. 10 terms Julia's favorite from the book:
1. Simple array that is pre-preprocessed with Dynamic Programming - Data Structure term (page 7)
2. Page 11, a form of Hash Table - ‘Direct Addressing Table’ (DAT) 

2. Page 8 Question:
2. Given a list of integers L of size up to 1M items, determine whether a value v exists in L?

(More details in Section 2.2.1).

Page 16 - Balanced Binary Search Tree (BST): C++ STL <map>/<set> 
Java TreeMap/TreeSet 
argument: implement a bug-free balanced BST like AVL Tree or Red-Black (RB) Tree is tedious and hard to do under time constrained contest environment. 

3. Look into those typical problems, first, remember the terms - Page 17 - Page 18 
Spend 30 minutes for each problem - warmup, and get traditional problems into daily routine - talk, warmup, and study some implementation using C# as well. (9/11/2016 - 1:21pm)

Programming exercises to practice using basic data structures and algorithms (with libraries):
• Static array, C++ STL <vector>, <bitset>, Direct Addressing Table
1. UVa 482 - Permutation Arrays (simple array manipulation)
2. UVa 594 - One Two Three Little Endian (manipulate bit string easily with <bitset>)
3. UVa 11340 - Newspaper (Direct Addressing Table)

• C++ STL <algorithm>
1. UVa 146 - ID Codes (use next permutation)
2. UVa 10194 - Football a.k.a. Soccer (multi-fields sorting, use sort)
3. UVa 10258 - Contest Scoreboard (multi-fields sorting, use sort)

• Sorting-related problems
1. UVa 299 - Train Swapping (inversion index3 problem solvable with bubble sort)
2. UVa 612 - DNA Sorting (inversion index + stable sort)
3. UVa 10810 - Ultra Quicksort (inversion index - requires O(n log n) merge sort)
4. UVa 11462 - Age Sort (counting sort problem, see [4])
5. UVa 11495 - Bubbles and Buckets (inversion index - requires O(n log n) merge sort)

• C++ STL <stack>
1. UVa 127 - “Accordian” Patience (shuffling <stack>)
2. UVa 514 - Rails (use <stack> to simulate the process)
3. UVa 673 - Parentheses Balance (classical problem)
4. UVa 727 - Equation (Infix to Postfix conversion)

• C++ STL <queue>
1. UVa 336 - A Node Too Far (<queue> used inside BFS, Section 4.3)
2. UVa 10901 - Ferry Loading III (simulation with <queue>)
3. UVa 11034 - Ferry Loading IV (simulation with <queue>)

• C++ STL <map>/<set>
1. UVa 10226 - Hardwood Species (use <map>)
2. UVa 11239 - Open Source (use <map> and <set> to check previous strings efficiently)
3. UVa 11308 - Bankrupt Baker (use <map> and <set> to help managing the data)
4. UVa 11136 - Hoax or what (use multiset in <set>)

• C++ STL priority queue in <queue>
1. UVa 908 - Re-connecting Computer Sites (priority queue in Kruskal’s, Section 4.4)
2. UVa 11492 - Babel (priority queue in Dijkstra’s, Section 4.5)
3. LA 3135 - Argus (Beijing04)

Find a website about Ultra quicksort:

https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1751


Nov. 24, 2016
C# book reading:


Tuesday, July 19, 2016

Leetcode 23: Merge K Sorted Lists

July 19, 2016

 Problem statement:

Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.
 Julia's first two practices in 2015:
1. Naive solution:
https://github.com/jianminchen/Leetcode_C-/blob/master/MergeKSortedLists_A_No23.cs


2. Implementation using merge sort: August 12, 2015
https://github.com/jianminchen/Leetcode_C-/blob/master/MargeKSortedLists_B_No23.cs

Come back to work on this problem in 2016, July 19:

Study those blogs:
1. Most favorite one:
http://bangbingsyb.blogspot.ca/2014/11/leetcode-merge-k-sorted-lists.html

Specially, the third discussion using divide and conquer, the conclusion that the merge solution is same time efficiency using heap solution Nklog(k), k is the number of arrays, and N is the length of the array, assuming that each array has same length.

1. http://www.cnblogs.com/TenosDoIt/p/3673188.html




7. Excellent article - Julia, share your personal story as well.
http://codeganker.blogspot.ca/2014/08/leetcode_26.html

Read the article: 

Julia's question and answer: 
1. Ideas to improve practice?
Answer:
  Ideas to construct the practice:
   1. Need to work on blog 7 - 3 solutions using C#, apply to "merge k sorted array".

Learn bottom-up merge sort, and know the time complexity as well.

C# solution - merge k sorted array - using bottom-up implementation merge sort
https://gist.github.com/jianminchen/d5fab2036647d380f20c908e91a81132

   2. Write down the proof of "divide and conquer" time complexity comparison using heap, O(nk logk)
       Show some simple example to help understand the time complexity.
   3. Warm up the code practice a few times, aiming to write 20 minutes for a solution
   4. Need to figure out master theorem quickly.

2. Can you work on a small example to illustrate some analysis?
Copy the image from Princeton's lecture note:

3. Can you write some C# code this time to make your own mark?

Actionable items:

Read the article, and write down questions - prepare a further reading list. (30 minutes reading )
https://en.wikipedia.org/wiki/Merge_sort
Notes:

keywords:  (remember 14 keywords)
average and worst-case performance
Bitonic Mergesort
Bottom-up implementation
comparison-based sorting algorithm
external merge sort - disk/ tape drives

external merge sort
master theorem
merge sort - not inplace - must be allocated for the sorted output to be stored in
parallel mergesort
polyphase merge sort
natural merge sort - similar to a bottom up merge sort

stable sort, 
TimSort, 
tiled merge sort algorithm
Top-down implementation

Variants:
  1. reducing the space complexity
  2. cost of copying

locality of reference

memory hierarchies
cache-aware version of merge sort algorithm
tiled merge sort algorithm

Parallel merge sort

Merge sort parallelizes well due to use of the divide-and-conquer method.

-
Comparison with other sort algorithms

heapsort   vs merge sort

O(1) auxiliary space instead of merge sort's O(n).

efficient quicksot implementations generally outperform mergesort for sorting RAM-based arrays - ?

merge sort is a stable sort and is more efficient at handling slow-to-access sequential media.

Merge sort is often the best choice for sorting a linked list.

the slow random-access performance of a linked list makes some other algorithms (such as quicksort) perform poorly, and others(such as heapsort) completely impossible.

Java, Array.sort() methods use merge sort or a tuned quicksort depending on the datatypes and for implementation efficicency switch to insertion sort when fewer than seven array elements are being sorted.

Python uses Timsort, another tuned hybrid of merge sort and insertion sort.

--
More reading:
30 minutes to review:
http://algs4.cs.princeton.edu/lectures/22Mergesort.pdf


5 minutes reading:
http://infolab.stanford.edu/~ullman/fcscnotes/notes9.pdf

20 minutes reading - plan to read - parallel merge sort
http://stanford.edu/~rezab/dao/notes/Lecture04/cme323_lec4.pdf

Read 10 minutes a time - get lost and enjoy reading ...


http://web.archive.org/web/20150120063131/https://android.googlesource.com/platform/libcore/+/jb-mr2-release/luni/src/main/java/java/util/TimSort.java

Will come back very soon.

Monday, March 27, 2017

45 minutes workout on a coding blog

March 27, 2017

Introduction


Julia did know the idea how to do a 45 minutes workout based on powerful search feature of Google. She searched her own blogs using keywords one by one, each one she spends 5 - 10 minutes to read.

Here is her tip to search.
Merge Sort, quicksort, hash function, tree, binary tree, binary search tree, stack, queue, BFS, graph, matrix.

Workout


Recursive function is here. 

Hash function is here. 

Actionable Items


Julia, you miss the heap, binary tree, non-sorted data structure, etc.  


Sunday, May 15, 2016

Leetcode 215: Find kth largest element in the array

May 15, 2016

 Problem statement:
 https://leetcode.com/problems/kth-largest-element-in-an-array/

 Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.

 Read some blogs about this problem:

 http://www.jianshu.com/p/f52a88550588

 Julia likes to spend 10 - 20 minutes to review "Quick Select" - the idea, similar to Quick Sort, most important part is to partition.

 Time complexity: O(nlogn) in quicksort, but O(n) in quick select.

 1. Quick sort: Time complexity: O(nlogn)

 2. Use Heap sort, O(klogN)
Java Solution, using priority queue, code to study:
https://github.com/jianminchen/LeetCode-Java-Solutions/blob/master/215.kth-largest-element-in-an-array.java

Spend 20 minutes to read the blog:  4:23pm - 4:43 pm
1. http://www.cnblogs.com/yuzhangcmu/p/4164807.html

2. https://en.wikipedia.org/wiki/Introselect (read 10 minutes - 4:30pm - 4:40pm)

3. http://stackoverflow.com/questions/7559608/median-of-three-values-strategy

4. http://www.quora.com/What-is-the-most-efficient-algorithm-to-find-the-kth-smallest-element-in-an-array-having-n-elements

5. http://www.geeksforgeeks.org/k-largestor-smallest-elements-in-an-array/ (4:50pm - 5:20pm)

30 minutes to review the solutions, write down short notes:
6 methods:
1. Use bubble k times - O(nk)
Modify bubble sort to run the outer loop at most k times
Like bubble sort, other sorting algorithms like selection sort can also be modified to get the k largest element.

2. Use temporary array
Time complexity: O((n-k)*k)

3. Use sorting
1. Sort the elements in descending order in O(nlogn)
4. Print the first k numbers of the sorted array O(k)
Time complexity: O(nlogn)

4. Use Max Heap
1. Build a Max Heap tree in O(n)
2. Use Extract Max k times to get k maximum elements from the Max Heap O(klogn)
Time complexity: O(n+klogn)

5. Use order statistics:
1) use order statistics algorithm to find the kth largest element.
Julia, take some time to review the article: see the topic selection in worst-case linear time O(n). (10 - 15 minutes)
Write down main ideas using your own words:
Use a deterministic algorithm that runs in O(n) in the worst case.

2)



Friday, July 29, 2016

K largest elements in the array - various ideas

July 29, 2016

Top k values in the array - review the following article: 

http://www.geeksforgeeks.org/k-largestor-smallest-elements-in-an-array/

1. sorting the array   O(nlogn)
2. use selection sort O(nk)
3. use sorting
4. use min heap
5. use max heap
6. use temporary array
7. use order statistics

7A. randomized selection algorithm - a dertministic algorithm that runs in O(n) in the worst case

 http://www.cse.ust.hk/~dekai/271/notes/L05/L05.pdf
1. the idea is to divide n items into n/5 sets (denoting m sets), each contains 5 items. O(n)
2. Find the median of each of the m sets. O(n)
3. Take those m medians and put them in another array.  Use Dselection() to recurisively calculate the median of these medians. Call this x. T(n/5)
4. ...

7B. Use QuickSort partition algorithm to partition around the kth largest number O(n).

7C. Sort the k-1 elements (elements greater than the kth largest element) O(klogk). This step is needed only if sorted output is required.

Tuesday, July 31, 2018

Quick sort technique study

July 31, 2018

Introduction

It is time for me to review the algorithm using quicksort technique. Here is the gist.


Monday, July 25, 2016

Longest common prefix - LCP - facebook code lab

July 25, 2016

Write a function to find the longest common prefix string amongst an array of strings.
Longest common prefix for a pair of strings S1 and S2 is the longest string S which is the prefix of both S1 and S2.
As an example, longest common prefix of "abcdefgh" and "abcefgh" is "abc".
Given the array of strings, you need to find the longest S which is the prefix of ALL the strings in the array.
Example:
Given the array as:
[

  "abcdefgh",

  "aefghijk",

  "abcefgh"
]
The answer would be “a”.

Plan to work on the problem

Blog reading:

1. Talk about CMU computer science - network security course in 2015 - good to know the college - computing teaching
http://article.heron.me/2015/05/cmu-nctu-final.html

course project:
https://github.com/heronyang/youtube_fake_view/blob/master/doc/paper.pdf

2. Four algorithm questions to review
http://codechen.blogspot.ca/search/label/interview

Inspired by the above blog, write code for binary tree path sum - two with same value checking:
https://gist.github.com/jianminchen/b5aa95fb574fcb6f4135f88a4b47d5f8

checklist of code style and design issues:
https://gist.github.com/jianminchen/b5aa95fb574fcb6f4135f88a4b47d5f8
2.1. if statement is minimum - avoid using if statement, tips: let it fall through base case.
2.2. code style:
   Readable code
   Clean code
2.3. use LINQ to code select clause like SQL statement
2.4. Avoid early return when the duplicate path sum is added.
2.5. Let main function to take care of discussion of two path sum with same value

3. Find k most frequent numbers in the array
Problem:
  // nums = [5, 3, 1, 1, 1, 3, 73, 1]
  // k = 1
  // return [1]
 
  // k = 2
  // return [1, 3]
 
  // k = 3

  // return [1, 3, 5]


First, go through the array once, and keep the count for every distinct value:

We can use LINK to call order by and then get Top k values.


But, in the analysis of the top k values in the array -

http://www.geeksforgeeks.org/k-largestor-smallest-elements-in-an-array/


1. sorting the array   O(nlogn)
2. use selection sort O(nk)
3. use sorting
4. use min heap
5. use max heap
6. use temporary array
7. use order statistics

7A. randomized selection algorithm - a dertministic algorithm that runs in O(n) in the worst case

 http://www.cse.ust.hk/~dekai/271/notes/L05/L05.pdf
1. the idea is to divide n items into n/5 sets (denoting m sets), each contains 5 items. O(n)
2. Find the median of each of the m sets. O(n)
3. Take those m medians and put them in another array.  Use Dselection() to recurisively calculate the median of these medians. Call this x. T(n/5)
4. ...

7B. Use QuickSort partition algorithm to partition around the kth largest number O(n).

7C. Sort the k-1 elements (elements greater than the kth largest element) O(klogk). This step is needed only if sorted output is required.

Sunday, January 31, 2016

Sunday - Algorithm day (4) - 25 algorithms study

Feb. 13, 2016

  Algorithm Sunday, work on it, not just Google. Think by yourself first, work hard on it first.

1. Maximum number of overlapping intervals

For example – { (0,2), (3, 7), (4,6), (7,8), (1,5) }. The maximum number of intervals overlapped is 3 during (4,5).
Recall Leetcode merge interval

Good solutions maybe: Using two arrays, one is to sort interval by start, another is by end.

2. Merge two sorted linked lists





Julia's practice:


3. LRU Cache Miss

Read blogs about LRU first:


This blog is excellent. Julia will write the implementation in C#.



4. Leetcode 64: Minimum Path Sum


5. Disk scheduling algorithm: Round Robin


6. K closest point


Read blogs on this website:
blog 

Julia could not believe that she always reads excellent code, and then, also great stories how technologies are different.



7. Rearrange array - 区分正负数


 8. Window sum 



9. Rearrange array in alternating positive negative items with O(1) extra space



idea: 如果用O(1)的话那需要有一个pointer指向第一个错误的数字,比如偶数index的正数和奇数index的负数。然后碰到当前的数如果符号和错误的那个数不一样,那就rotate那段sub array。

10. Iterative binary tree traversal


12. Trie - Java Implementation




O(n)的解法,很巧妙,利用数组的特性,暂且称之为“派送法”哈哈,派送A[i]到A[A[i]-1]。




16. HeapSort


Read 10 minutes lecture notes. 



about partition, quick sorting:
Julia'sblog and her quick sorting partition explanation with a test case.


18. Merge Intervals

上来给一串start time - end time,格式是Apr 2010 - Mar 2011这种,要求计算出这些时间的总跨度,重叠的跨度不重复计算。举例:["Apr 2010 - Dec 2010", "Aug 2010 - Dec 2010", "Jan 2011 - Mar 2011"]这一个string数组,结果为(12-4+3-1)=10个月。一出这题有点蒙,感觉代码量很大,时间又不多了,只能硬着头皮上。写完string->time的解析函数之后,发现其实就是一道mergeinterval的题.

19. 
写一个函数,给一个node,代表一个人,返回他linkedin 或者facebook network

BFS - graph traversal 
如果一个用户 用这个api,那个node 的朋友很多,million to billion 级别,那么response感觉很慢怎么办? 

20. validBST

如果有duplicate 而且 duplicate return false 的时候会 failed 一个corner case

21. Given a tree, find the smallest subtree that contains all of the tree's deepest nodes.
                  a
               /  |  \
             b   c   d
           /   \       |
         e      f      g
       /       /  \
      h      i     j

depth of tree: 4
deepest nodes:[h,i,j]
least common ancestor of [h,i,j]:

return: b

leetcode
上面哪个lowest common ancestor of binary tree

22. insert node in circular list
, 

23. LRU miss count

输入 maxSize, input int array 
输出是miss cout

example:   size = 4, input array   【1,2,3,4,5,4,1】
1 miss
2 miss
3 miss
4 miss
5 miss  替换 1
4 hit    把4提前到第一位
1 miss  替换 2
大概就是这样。。。

February 2, 2016
Read blogs:


February 2, 2016




24.
8 个 cell  
example:【0,1,1,1,1,1,1,0】
规律每天变化:两边相同--》0, 两边不同--》1
输入:8个cell,  天数n

问n天后cell长啥样

ps:两端cell两边假设const = 0;

小example:
day0:  (0)0,1,1,1(0)
day1:  (0)1,1,0,1(0)
day2:  (0)1,1,0,0(0)

25. Longest path from root to leaf in binary tree


Feb. 17, 2016
Check out topcoder training about testing cases, maybe, use it for a while for practice.