Skip to content

Add details to DNC problems #183

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions dnc/binary_search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ TestBinarySearch tests solution(s) with the following signature and problem desc

func BinarySearch(list []int, search int) int

Given a sorted set of integers like {1,2,3,4,6}, and a target int like 4 find its
position in the set like 3 using Binary Search.
Given a sorted slice of integers like and a target int find the position of the target in the
slice.

In Binary Search we start with the middle element of the set and compare it with
the target. If the target is greater than the middle element we search the right
half of the set, otherwise we search the left half of the set. We repeat this
process until we find the target or we exhaust the set.

For example given {1,2,3,4,6} and 4 as a target, return 3 because 4 is at index 3.
*/
func TestBinarySearch(t *testing.T) {
tests := []struct {
Expand Down
12 changes: 11 additions & 1 deletion dnc/merge_sort_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,17 @@ TestMergeSort tests solution(s) with the following signature and problem descrip

func MergeSort(list []int) []int

Given a list of integers like {3,1,2}, return a sorted set like {1,2,3} using Merge Sort.
Given a slice of integers, return a sorted slice using Merge Sort.

Merge sort is a divide and conquer algorithm that works by dividing the
input array into two halves, recursively sorting each half, and then merging
the two sorted halves back together. The merge step is where the actual
sorting takes place.

For example given {3,1,2}, return {1,2,3}. The merge sort algorithm would first
divide the array into two halves: {3} and {1,2}. It would then it would divide {1,2}
into {1} and {2}. Finally, it would merge the two halves back together
into a single sorted array: {1,2,3}.
*/
func TestMergeSort(t *testing.T) {
tests := []struct {
Expand Down
12 changes: 11 additions & 1 deletion dnc/quick_sort_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,17 @@ TestQuickSort tests solution(s) with the following signature and problem descrip

func QuickSort(list []int) []int

Given a list of integers like {3,1,2}, return a sorted set like {1,2,3} using Quick Sort.
Given a slice of integers like, return a sorted slice of integers using quick sort.

Quick sort works by selecting a 'pivot' element from the array and partitioning
the other elements into two sub-arrays, according to whether they are less than
or greater than the pivot. The sub-arrays are then sorted recursively. The
base case of the recursion is an array of size 0 or 1, which is always sorted.

For example given {3,1,2}, return a {1,2,3}. The quick sort algorithm would first
choose a pivot element, say 2. It would then partition the array into two
sub-arrays: {1} and {3}. It would then recursively sort the two sub-arrays
and combine them with the pivot element to produce the final sorted.
*/
func TestQuickSort(t *testing.T) {
tests := []struct {
Expand Down
3 changes: 3 additions & 0 deletions dnc/rate_limit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ TestRateLimiter tests solution(s) with the following signature and problem descr
Given a number of allowed requests calls per second (calls/time) write an IsAllowed
function which returns false if the request should be rate limited because it exceeds the
limit and true if the request should be allowed.

For example given limit of 2 requests per second, if 3 requests are made in the first second
two calls to IsAllowed would return true and the third would return false.
*/
func TestRateLimiter(t *testing.T) {
tests := []struct {
Expand Down
2 changes: 2 additions & 0 deletions dnc/square_root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ TestSquareRoot tests solution(s) with the following signature and problem descri

Given a number and precision, return the square root of the number using the binary
search algorithm.

For example given 9 and 3, it should return 3.
*/
func TestSquareRoot(t *testing.T) {
tests := []struct {
Expand Down
10 changes: 8 additions & 2 deletions dnc/towers_of_hanoi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@ TestTowerOfHanoi tests solution(s) with the following signature and problem desc

func TowerOfHanoi(n, start, end int) [][2]int

Given n, number of disks, and start and end tower, return the moves it takes to move all
disks from start to end tower. The disks are stacked on top of each other with the
Given n, number of disks, and start and end tower, return the number of moves it takes to
move all disks from start to end tower. The disks are stacked on top of each other with the
lightest being on top and heaviest being in the bottom. A heavier disk cannot be placed
on a lighter disk. You can move one disk at a time.

For example given 2 disks, start of 1 and end of 3 return {1, 2}, {1, 3}, {2, 3}.
The first move is to move the top disk from tower 1 to tower 2.
The second move is to move the top disk from tower 1 to tower 3.
The final move is to move the top disk from 2 to 3.
By the end all disks are moved from tower 1 to tower 3.
*/
func TestTowerOfHanoi(t *testing.T) {
tests := []struct {
Expand Down