BlogPost_206

Corey Tyler
4 min readOct 28, 2019
  1. Tell us about something you learned this week.

This week we learned about API calls. API’s or Application Programming Interface. These are computer programs that give us something we ask for. We make API calls to retrieve information from back-end servers. The calls we make to these servers are called promises and these are set up as functions.

2. What are the pros and cons of immutability?

An immutable object is an object that can not be changed or modified.

Pros:

The headline argument for using any library for immutable data types, is the reassurance that anyone working on your project cannot violate your principles of immutability.

As such ‘Immutable’ helps simplify development, as you never have to trace through your code to find where your data was altered. Instead your immutable data type will always represent precisely the app state present in the store.

Cons:

When debugging someone elses code you may be none the wiser that someone may have made their code immutable. When trying to debug a developer may can not fix a problem because the original developer may be using custom datatypes. This all can slow down development.

3. How can you achieve immutability in your own code?

Mutable objects are those whose state is allowed to change over time. An immutable value is the exact opposite — after it has been created, it can never change. Strings and Numbers are inherently immutable in javascript.

4. What are Divide and Conquer algorithms? Describe how they work. Can you give any common examples of the types of problems where this approach might be used?

In computer science, divide and conquer is an algorithm design paradigm based on multi-branched recursion. A divide-and-conquer algorithm works by recursively breaking down a problem into two or more sub-problems of the same or related type, until these become simple enough to be solved directly.

This approach can be used when searching for a singular thing in a huge database.

5. How do Insertion sort, Heapsort, Quicksort, and Merge sort work?

Insertion Sort:

We start with a marker, telling us we have one number in the sort portion of the array. We then move over one number at a time to see if it’s greater than the one to it’s left. If it’s less, move it to the left of the number. We repeat this for each number in the unsorted part of the array. When the number is greater than the number it’s compared to it stays in place and we grab the next unsorted number.

Heapsort:

Heap sort algorithm is divided into two basic parts: Creating a Heap of the unsorted list/array. Then a sorted array is created by repeatedly removing the largest/smallest element from the heap, and inserting it into the array. The heap is reconstructed after each removal.

Quicksort:

Quick Sort use a pivot element as a partition then looks at numbers to the left and right of the partition to see if they need to be move over or not. Then it repeats the sequence on the left and right sides of the partitions. Then again and again until all the numbers are in order.

Merge Sort:

Merge sort is one of the most efficient sorting algorithms. It works on the principle of Divide and Conquer. Merge sort repeatedly breaks down a list into several sublists until each sublist consists of a single element and merging those sublists in a manner that results into a sorted list.

6. What are the key advantages of Insertion Sort, Quicksort, Heapsort and Mergesort? Discuss best, average, and worst case time and memory complexity.

The insertion sort is one of the least efficient ways to sort. It compares the current number to the one next to it to see if it is greater or less than the current number then moves on. It is however an advantage to bubble sort which is the more inefficient ways to sort.

The Quicksort algorithm use a pivot element to look at the element to the left and right and sees if they need to be moved or not. This is more slightly less efficient than the insertion sort because it compares the pivot element to 2 other elements and not one. Using more computing power.

Heapsort is also one of the most efficient ways to sort given that it breaks all your elements down into a heap then assembles them into a new array comparing multiple elements.

Mergesort is the most efficient way to sort things since it doesn’t doesnt increase computing power exponentially.

7. Explain the difference between mutable and immutable objects

Mutable objects are objects that can be changed or augmented over time. Immutable objects are objects that can not be changed or augmented.

8. What is an example of an immutable object in JavaScript?

An example of a immutable object would be a number or a string.

--

--