Learning Journal | Encora Academy | Week 16

Martha Rodríguez
3 min readJan 18, 2021

January 11— January 18

Hello! 👋 This is my fifteenth-week takeaways being part of the Encora Academy program, a space to learn, practice, and grow. I’ll post every week, all about the topics I’ve learned during this adventure.

This is the second week of the Your Personal Branch Phase and these are my takeaways:

What is a hash function?

A has function, is a function that receives an object, usually a string, process it and returns a limited object of certain data type, usually and integer.

The process that happened inside, is different depending the environment, could be created for the developer who is using it, or it could be part of a language.

The idea is to have a compact representation of the input.

A good hash function should:

  • Be efficiently computable
  • Should return as more different result as possible, each result should be equally likely for each input.

How a Hastables works?

A hashtable is a data structure that use a hash function to convert a value, and make it a lot easier to access.

Here, there is a very simple example.

The hash function returns the first 3 elements of the input as an integer.

Then we have 3 string values that are added to a hash table, using the hash result as the index. To access it, we hash the value again to get the index we need.

In JavaScript the hash table is more defined for the way we add values and access to it, more than a data structure itself, that is why we use an array.

Collisions

You should be asking? but if another value is 1230987, where will it be stored?

In this example, there aren’t collisions because we have just a few values, but we can manage them, creating arrays inside a hash index or incrementing the index by 1 until find a space for that value.

Ruby attribute accessors

Usually, we have getters and setters on classes, functions that help us to access to our class attributes.

In Ruby, those are so easy to add, you just have to add

  • attr_accesor. Give write and read access to the attributes.
  • attr_writer. Give just write access to the attribute.
  • attr_reader. Give just read access to the attribute.

Binary search

What if we start searching from the middle instead from the beginning? Well that is what binary search does, it look for a number in an ordered array or list starting in the middle, it will look to the up half if the number is bigger or in the down half if the number is smaller, and so on.

Big O notation

This notation, helps to know the performance of an algorithm it tells you how fast an algorithm is.

You can write it with a big O and the mathematical function that describes the performance between parentheses. For example: O(n)

The expression between parentheses, also represents the number of steps that takes an algorithm to finish.

Also, it usually describes the worst case scenario, it means, the number of steps that will take in a not ideal environment but, you can also look at the average or best scenario, it depends on the needs.

To calculate it, we should:

  • Count the number of expression executions. How many time each expression is executed?
  • Find the fastest growing term. Which expression grows the fastest? What is it function?
  • Remove the coefficients and extra terms. What is the minimum expression of this function?

That’s all for this week, see you!

--

--

Martha Rodríguez

Hello World!👋🏽 I’m a programmer in development. I’ll share with you my sketch notes about everything I learn during my journey as an Encora Intern…and more 😉