PolarZone
http://polarzone.me/
Recent content on PolarZoneHugo -- gohugo.ioen-us, zh-cnWed, 09 Mar 2022 15:58:07 +0800Binary Search Tree
http://polarzone.me/posts/cs2040s/week-06/binary-search-tree/
Wed, 09 Mar 2022 15:58:07 +0800http://polarzone.me/posts/cs2040s/week-06/binary-search-tree/Recall that in binary search, we find the middle element of a list, compare the element that we want to find with the middle element, and then chooses to go to the left part of the list or the right part. A binary search tree is using a similar approach. The difference here is that in a binary search tree, we store the elements in a tree structure.
Say that we have a list that looks like this:Midterm Review Notes
http://polarzone.me/posts/ma2001/midterm-review-notes/
Fri, 04 Mar 2022 13:19:44 +0800http://polarzone.me/posts/ma2001/midterm-review-notes/Linear Systems A linear system is a set of linear equations. A linear system is consistent if it has 1 or infinite solutions, and inconsistent if it has no solutions. There are only 3 different situations to the solutions of a linear system: no solution (inconsistent) 1 solution (consistent) infinite solutions (consistent) A consistent linear system is different from a homogeneous one. Consistent means having solutions; Homogeneous means a linear system where all the constants are zero.Tutorial Q3 Economic Research
http://polarzone.me/posts/cs2040s/week-06/tutorial-q3-economic-research/
Wed, 16 Feb 2022 21:56:05 +0800http://polarzone.me/posts/cs2040s/week-06/tutorial-q3-economic-research/You are an economist doing a research on the wealth of different generations in Singapore. You have a huge (anonymised) dataset that consists of ages and wealth, for example, it looks something like:
24 150,000 32 42,000 18 1,000 78 151,000 60 109,000 That is, each row consists of a unique identifier, an age, and a number that represents their amount of wealth. Your goal is divide the dataset into “equi-wealth” age ranges.Quick Sort Revised
http://polarzone.me/posts/cs2040s/week_04/quick-sort-revised/
Wed, 16 Feb 2022 18:42:50 +0800http://polarzone.me/posts/cs2040s/week_04/quick-sort-revised/In the previous article, I discussed the brief idea behind quicksort. However, I wasn’t clear about the details, therefore creating much trouble for my own implementation of the quick sort. This article will build on top of the ideas discussed in the previous article. More specifically, it will focus more on the details of the implementation of quick sort. Specifically, we shall be discussing quicksort with 3-way partitioning.
I also have to give a shout out to my friends Anis and Bruce.Quick Sort
http://polarzone.me/posts/cs2040s/week_04/quick-sort/
Mon, 07 Feb 2022 23:16:11 +0800http://polarzone.me/posts/cs2040s/week_04/quick-sort/I apologize for the poor quality of this article. To be honest, writing this article was a huge mess. I spent a lot of time writing the article, but then I realized that I didn’t really get the details right. The idea was correct, but I vaguely described the implementation. When I went on to write the code, I realized that quick sort is actually all about details. Vaguely understanding the idea of quicksort makes it hard to implement it correctly – I spent hours debugging my code.PPT to PDF: Batch Conversion Using AppleScript
http://polarzone.me/posts/random-snippets/ppt_to_pdf_batch_conversion/
Sat, 05 Feb 2022 15:04:53 +0800http://polarzone.me/posts/random-snippets/ppt_to_pdf_batch_conversion/If you are just here looking for the solution, this is my github link for the script. It should be pretty straight-forward.
I am a DevonThink user. The thing that I love most about it is that it combines document organization tools with document viewing / editing tools. In one window, you will be able to edit the contents of a specific file while seeing the other files under the same directory.Selection Sort
http://polarzone.me/posts/cs2040s/week_03/selection_sort/
Mon, 31 Jan 2022 00:16:21 +0800http://polarzone.me/posts/cs2040s/week_03/selection_sort/Idea One way of sorting a list is that we iterate through the list, and for every iteration, we pick out the least item and move it to the front.
Suppose below is the list that we want to sort.
1 9 7 5 4 6 8 10 3 2 Firstly, we find out the least item in the entire list through iteration. In this case, the least item is $1$, which happens to be the first item of the list.Bubble Sort
http://polarzone.me/posts/cs2040s/week_03/bubble_sort/
Mon, 31 Jan 2022 00:16:14 +0800http://polarzone.me/posts/cs2040s/week_03/bubble_sort/Suppose that we are given the following list:
1 9 7 5 4 6 8 10 3 2 The idea of bubble sort is that we iterate through the entire list several times, and for each time, we swap the adjacent values if their relative position is not correct.
So, for the first iteration, we start looking at 1 and 9, and find out that their relative position is correct. We then go on to look at 9 and 7, and find that their relative position is incorrect.Insertion Sort
http://polarzone.me/posts/cs2040s/week_03/insertion_sort/
Mon, 31 Jan 2022 00:15:22 +0800http://polarzone.me/posts/cs2040s/week_03/insertion_sort/In merge sort, our goal was to make sure that the first $i$ items are sorted and are the least items. However, the process of finding the least item in each iteration is actually quite expensive - you’ll have to iterate through the whole least. Hence, an alternative idea would be to simply make sure that the first $i$ items are sorted, and nothing more. Therefore, we do not need to search for the least item.Week 03
http://polarzone.me/posts/cs2040s/week_03/
Mon, 31 Jan 2022 00:05:10 +0800http://polarzone.me/posts/cs2040s/week_03/This week’s lectures mainly focused on the different sorting techniques. Below is a table detailing the techniques.
Technique Big-Omega Big-Theta Big-O Bubble Sort $O(n)$ $O(n^2)$ $O(n^2)$ Selection Sort $O(n^2)$ $O(n^2)$ $O(n^2)$ Insertion Sort $O(n)$ $O(n^2)$ $O(n^2)$ Merge Sort $O(n\log n)$ $O(n\log n)$ $O(n\log n)$ Merge Sort
http://polarzone.me/posts/cs2040s/week_03/merge_sort/
Mon, 31 Jan 2022 00:03:37 +0800http://polarzone.me/posts/cs2040s/week_03/merge_sort/Suppose we have a list
1 9 7 5 4 6 8 10 3 2 and our goal is to sort the list. Merge sort’s idea is to divide the list into small segments and recombine them.
Here, we have the list sorted.
Code Java Implementation public class MergeSort{ public void sort(int[] nums) { copy(nums, _sort(nums));; } static void copy(int[] arr1, int[] arr2) { assert arr1.length == arr2.length: "trying to copy two arrays that do not have the same size"; for (int i = 0; i < arr1.CS2100
http://polarzone.me/posts/cs2100/
Wed, 19 Jan 2022 16:04:17 +0800http://polarzone.me/posts/cs2100/Disclaimer TBD Course Contents Lecture 03 Discussed how to represent integers, floating point numbers, and more.
For detailed notes, see data representationLecture 03
http://polarzone.me/posts/cs2100/lecture_03/
Wed, 19 Jan 2022 16:02:12 +0800http://polarzone.me/posts/cs2100/lecture_03/Module: CS2100
Discussed how to represent the four basic data types in C:
Integer Float Char Double For detailed notes, see data representation.Data Representation
http://polarzone.me/posts/cs2100/lecture_03/data_representation/
Wed, 19 Jan 2022 16:00:23 +0800http://polarzone.me/posts/cs2100/lecture_03/data_representation/Module: CS2100
Lecture: Lecture 03
There are four basic data types in C. Namely, they are:
int - 4 bytes long, which is equivalent to 32 bits. float - 4 bytes long, which is equivalent to 32 bits. double - 8 bytes long, which is equivalent to 64 bits. char - 1 byte long, which is equivalent to 8 bits. In this article, we are going to explore the underlying data structure that represet the 4 data types in C.Lecture 03
http://polarzone.me/posts/cs2040s/week_02/
Tue, 18 Jan 2022 17:51:13 +0800http://polarzone.me/posts/cs2040s/week_02/This lecture discusses the Big-O Notation and Binary Search.
Big-O Notation Big-O notation is used to describe the order of growth of many types of things. In CS2040S, we use it to describe time complexity of algorithms.
Note that:
$O(f(n))$ describes the upperbound of the growth of $f$, i.e. the worst case-time complexity;
$\Omega(f(n))$ describes the lowerbound of the growth of $f$, i.e. the best-case time complexity;CS2040S
http://polarzone.me/posts/cs2040s/
Tue, 18 Jan 2022 17:47:31 +0800http://polarzone.me/posts/cs2040s/About Here are my notes for the NUS Module CS2040S Data Structures and Algorithms.
Technically speaking, they are not notes, but rather my attempts to explain the contents covered in the class.
Disclaimer I titled this series CS2040S because it is the notes that I wrote while taking the CS2040S. However, I do not by any means represent the teaching team at NUS (I am only a newbie student taking this course), nor do the contents that I wrote represent what was taught in class.Binary Search
http://polarzone.me/posts/cs2040s/week_02/binary_search/
Tue, 18 Jan 2022 17:34:18 +0800http://polarzone.me/posts/cs2040s/week_02/binary_search/Module: CS2040S
Lecture: Lecture 03
Binary search is HARD!
What is Binary Search? Bineary search is an algorithm that allows you to find the item you want in a sorted list in $O(\log(n))$ time. It accomplishes this by dividing the list into two parts, check which part the target value is in, and then go on to divide that part of the list into two parts ……
An Example by Hand Here is an example where we do binary search by hand.Big O Notation
http://polarzone.me/posts/cs2040s/week_02/big_o_notation/
Tue, 18 Jan 2022 15:40:47 +0800http://polarzone.me/posts/cs2040s/week_02/big_o_notation/Module: CS2040S
Week: Week 02
We use big O notation to denote the complexities of growths of certain things. Specifically, in the context of computer algorithms, we use big O notations to measure the time complexities. Below is a function:
$$ f(x) = x^3+2x^2+3x+1 $$
suppose that we want to learn about the order of growth of the function above. We would quickly realize one thing: as $x$ gets greater and greater, the $x^3$ seemed to become the component that contributes the most to the function’s growth, whereas the other components have a less and less contribution.