<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Garrett Codes on Medium]]></title>
        <description><![CDATA[Stories by Garrett Codes on Medium]]></description>
        <link>https://medium.com/@ghalstein97?source=rss-962086c38ff6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*dPihpq-LqxupLedFQTGr6A.jpeg</url>
            <title>Stories by Garrett Codes on Medium</title>
            <link>https://medium.com/@ghalstein97?source=rss-962086c38ff6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 05:46:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ghalstein97/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Quick Guide: How to Become a Software Engineer without a Computer Science Degree]]></title>
            <link>https://medium.com/@ghalstein97/quick-guide-how-to-become-a-software-engineer-without-a-computer-science-degree-5fdec3ed45b2?source=rss-962086c38ff6------2</link>
            <guid isPermaLink="false">https://medium.com/p/5fdec3ed45b2</guid>
            <category><![CDATA[how-to]]></category>
            <category><![CDATA[software-engineer]]></category>
            <category><![CDATA[codingbootcamp]]></category>
            <category><![CDATA[flatiron-school]]></category>
            <category><![CDATA[how-to-be-a-developer]]></category>
            <dc:creator><![CDATA[Garrett Codes]]></dc:creator>
            <pubDate>Fri, 24 Apr 2020 02:40:05 GMT</pubDate>
            <atom:updated>2020-04-25T22:10:00.091Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zGm8o0N4CwR1vxrbCjRrsw.jpeg" /></figure><p>No matter what stage you are at in the process of becoming a software engineer, I hope that this article helps out in some way. In this article I want to quickly touch upon the main points you should do to get hired as a software engineer without having any previous knowledge of programming or development. And if you find it helpful, I recommend checking out my youtube channel for more resources and advice.</p><p><strong>Step One: Learn Computer Science</strong></p><p>If you are 100% set on becoming a front-end developer then you might not have to worry about computer science fundamentals too much because your goal should be to master javascript and html/css. However, I do think for most people the best thing to do would be to take a computer science course that introduces computer science fundamentals. This gives the proper foundation to branch off into software development and start preparing for technical interviews. I recommend checking out incredible resources like MIT Open Courseware’s intro class on youtube or Harvard’s cs50 on edX. The best part is they are free!</p><p><strong>Step Two: Learn how to build projects to add to your portfolio</strong></p><p>Now that you have a good foundation for computer science I recommend building out your portfolio! This is one of the most important things to do. You can do this on your own by using online resources like udemy courses, freecodecamp or similar resources to learn how to build your own apps. Here are examples of some helpful courses: <a href="https://www.udemy.com/course/the-complete-web-development-bootcamp/?source=aw&amp;awc=16235_1587692225_5d719c78fb3868a6fef2582b10f0d052&amp;utm_source=Growth-Affiliate&amp;utm_medium=Affiliate-Window&amp;utm_campaign=Campaign-Name&amp;utm_term=644257&amp;utm_content=Placement">The Complete Web Development Bootcamp</a> or <a href="https://www.udemy.com/course/the-web-developer-bootcamp/?source=aw&amp;awc=16235_1587692227_db04ac601b3ed8f2769d05947fbcd559&amp;utm_source=Growth-Affiliate&amp;utm_medium=Affiliate-Window&amp;utm_campaign=Campaign-Name&amp;utm_term=644257&amp;utm_content=Placement">The Web Developer Bootcamp</a>. Just understand your goal is to build out full-stack applications so find a course that best suits you. And you can take specific courses for each topic like a whole course covering python back end development, a whole course in vanilla javascript and then a whole course covering react. There are so many options out there and I am just naming a couple. For some of you that feel you want more guidance and have the money to spend you can go down the bootcamp route. I went to Flatiron School and felt they helped me build a decent portfolio to showcase on my resume. <a href="https://youtu.be/V1bUrCRFivc"><em>Click here to hear about my experience there</em></a>. And if you are considering bootcamps or looking for advice while in one I recommend going through my bootcamp video playlist here: <a href="https://www.youtube.com/playlist?list=PL8xbMtjGzG_xy0lp4wIyh7zAVAnVwNrcW">Coding Bootcamp Playlist</a>. It is important to understand why we are doing this and the main reason is to show your experience and skills on your resume to attract employers.</p><p><strong>Step Three: Learn Data Structures and Algorithms</strong></p><p>Now I know I called this step three but you should really be doing this alongside your time learning software development. The reason why is that this is very important for your interviews. So the earlier you get started the better you will be at interview questions. And there is no limit to how much you can study this stuff. I recommend taking a data structures course in the language you plan on interviewing. So if you chose Python for interviews find a Python data structures course. If you are planning on taking them in Javascript then find a Javascript course. I heard some good things about <a href="https://www.udemy.com/course/js-algorithms-and-data-structures-masterclass/">Javascript Algorithms and Data Structures Masterclass</a> but there are a ton of resources out there. Just understand that the course should <em>at the very least </em>teach you about arrays, linked lists, trees, graphs, heaps, queues, stacks, sorting and searching algorithms. You also can take a course that is not in the language you plan on interviewing in if you want to but I feel keeping it the same language will take away some layers of abstraction and allow you to focus more on the concepts.</p><p><strong>Step Four: Resume, Interview Prep &amp; Job Search</strong></p><p>Now once you built out enough projects to your heart’s content and solved enough algorithms its time to start searching for jobs. Make sure your resume is as attractive as possible, showcasing all of your new-found skills and projects. Check out my resume walkthrough for ideas and tips: <a href="https://youtu.be/W9sVof_25MI">The Resume That Got Me Into IBM</a>. I recommend keeping up your algorithm practice as much as you can. If you want, you can prep for the technical interviews using <em>pramp</em>. It is also great for meeting other professionals. Also target what the companies are looking for and see if you can include some of the keywords their job applications mention on your resume.</p><p><strong>Conclusion</strong></p><p>So I meant to make this article short and concise so I hope you got something out of it by reading it. I plan on posting more focused content on here in the future and will continue posting more videos as resources on <a href="https://www.youtube.com/channel/UCxFU0nGRBUEkidfiDGL4yWg/">YouTube</a>. So if you are interested, check out my youtube channel that covers more stuff related to becoming a software engineer. Also, if you have any kind of questions that my posts do not answer please reach out to me on linkedin or drop a comment on a video.</p><ul><li><a href="https://www.youtube.com/channel/UCxFU0nGRBUEkidfiDGL4yWg/">Garrett Halstein</a></li><li><a href="https://www.linkedin.com/in/garrett-halstein-472b3b156/">Garrett Halstein - Software Engineer - IBM | LinkedIn</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5fdec3ed45b2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Divide-and-Conquer]]></title>
            <link>https://medium.com/@ghalstein97/divide-and-conquer-25079158516f?source=rss-962086c38ff6------2</link>
            <guid isPermaLink="false">https://medium.com/p/25079158516f</guid>
            <category><![CDATA[divide-and-conquer]]></category>
            <category><![CDATA[quicksort]]></category>
            <category><![CDATA[dynamic-programming]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Garrett Codes]]></dc:creator>
            <pubDate>Sun, 03 Nov 2019 04:10:37 GMT</pubDate>
            <atom:updated>2019-11-03T04:10:37.223Z</atom:updated>
            <content:encoded><![CDATA[<p>Divide-and-conquer is a style of solving problems that is not at all limited to computer science problems. It’s the idea of solving a problem in a recursive manner, or breaking a bigger problem down into smaller subproblems that can be solved more easily. There are three parts to it including the <strong>divide</strong> part, the <strong>conquer</strong> part and then <strong>combining</strong> the sub-solutions together.</p><h3>Divide</h3><p>The divide part focuses on splitting the big problem up into smaller and more manageable subproblems. This process continuously keeps breaking the problem down into smaller problems, which is known as the <em>recursive case</em>, until the subproblems are small enough. The <em>base case</em> is when no more recursion is necessary for a subproblem. For an example, let’s look at some pseudocode for quick sort.</p><pre>// pseudocode for quick sort</pre><pre>quicksort(int[] arr, int low, int high) {<br>  <br>  if (low &lt; high) {<br>    int p = partition(arr, low, high);<br>    <br>    quicksort(arr, low, p - 1); // calling the lower half<br>    quicksort(arr, p + 1, high); // calling the upper half</pre><pre>  }<br>}</pre><pre>// pseudocode for partition that makes all smaller numbers in front // of the pivot and all bigger numbers behind the pivot</pre><pre>partition (int arr[], int low, int high) {<br>  // pivot (Element to be placed at right position)<br>  pivot = arr[high];  <br> <br>  int i = (low - 1)  // Index of smaller element<br><br>  for (j = low; j &lt;= high - 1; j++) {<br>    // If current element is smaller than the pivot<br>    if (arr[j] &lt; pivot) {<br>      ++i;    <br>      swap(arr[i] and arr[j])<br>    }<br>  }<br>  swap(arr[i + 1] and arr[high])<br>  return (i + 1)<br>}</pre><p>As you can see it is calling quicksort within its own function. This is the recursive case. The base case is implicitly interpreted in the conditional of quicksort so that when the condition is not met there is nothing left to do.</p><h3>Conquer</h3><p>The base case is the goal. When breaking down a problem into smaller problems, it will start to become solved when it gets small enough and no more recursion is necessary. This is the conquer part. As you can see in the example the base case would be considered the conditional in quicksort . If that condition is not true then no more recursion is called in that branch of calls. It would be time to combine the solution of this branch of calls with the other branch of calls.</p><p>In the quicksort example you can see that every time quicksort is called the partition function is called. This is the part where the subproblem gets solved, or <em>conquered</em>, and is then combined with the other sub-solutions.</p><h3>Combining</h3><p>The combining part is important because even though the smaller problems are solved in order to get the solution to the big problem the smaller ones have to be combined. The combining portion is a little less noticeable in quicksort because we are working with an array, which involves passing by reference. The subproblem solutions are making direct changes to the array in solving the smaller problems, which is ultimately sorting the entire array. Combining is more apparent in something like solving the Fibonacci sequence for the nth term, which has a recursive case return value of fib(n — 1) + fib(n — 2) . Here, every sub-solution is visibly combined within the function.</p><h3>Closing Remarks</h3><p>As you can see this is a brief introduction to divide-and-conquer algorithms. They can be very helpful in optimizing solutions to problems, and many times even the most logical solution to implement. It’s great to practice implementing the basic algorithms like quick sort on your own to familiarize yourself with it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=25079158516f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Looking into Red-Black Trees]]></title>
            <link>https://medium.com/@ghalstein97/looking-into-red-black-trees-beabb3048958?source=rss-962086c38ff6------2</link>
            <guid isPermaLink="false">https://medium.com/p/beabb3048958</guid>
            <category><![CDATA[binary-search-tree]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[red-black-tree]]></category>
            <dc:creator><![CDATA[Garrett Codes]]></dc:creator>
            <pubDate>Thu, 24 Oct 2019 00:36:37 GMT</pubDate>
            <atom:updated>2019-10-24T22:38:43.884Z</atom:updated>
            <content:encoded><![CDATA[<p>As you may know, a <strong>Binary Search Tree</strong> of height, <em>h,</em> is able to support any basic dynamic-set operations. These operations such as searching, inserting or finding the minimum value can be very fast under smaller data sets. However, the larger the tree’s height becomes, the higher the time complexity may get without having a properly balanced tree. For example, what do you get when every node of a tree is directly linked to the right node? Yes, you get a simple linked list. Thus, the operational runtime for searching data in a severely unbalanced tree can be O(n).</p><p>So, without maintaining the balance of a Binary Search Tree you may find trouble with continuing to use the data structure under certain scenarios. Precautions can be taken in designing a BST so that it keeps itself balanced. That is the idea behind <strong>Red-Black Trees</strong>.</p><h3>Properties of red-black trees</h3><p>The cost of maintaining a balanced BST is having extra storage for every node in the tree. This extra storage keeps track of the color for each node, which in the RBT’s case can be either red or black. This allows the tree to maintain its components easily.</p><p>Knowing this, here are a few of the properties of RBT’s:</p><ol><li>Every node is either red or black.</li><li>The root node by convention is always black.</li><li>Every leaf is black.</li><li>If a node is red, then both of its children would be black.</li><li>For every node, all simple paths from the node to its descending leaves contain the same amount of black nodes.</li></ol><p>Here is an example of a red black tree illustration from <em>Introduction to Algorithms</em>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/956/1*9ABrSGmx7o1sT21zV3ajNg.png" /><figcaption><em>Introduction to Algorithms, 3rd Edition</em></figcaption></figure><p>Note that the “NIL” nodes are just representing null endpoints, and are considered black. It is important to really think about the properties of RBT’s and why they work (Especially 4 and 5). Understanding, what these properties do and why they are important is instrumental in grasping how RBT’s work.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=beabb3048958" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Exploring Graphing Algorithms in Computer Science]]></title>
            <link>https://medium.com/@ghalstein97/exploring-graphing-algorithms-in-computer-science-b67c653a5e21?source=rss-962086c38ff6------2</link>
            <guid isPermaLink="false">https://medium.com/p/b67c653a5e21</guid>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[graph-theory]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[breadth-first-search]]></category>
            <dc:creator><![CDATA[Garrett Codes]]></dc:creator>
            <pubDate>Tue, 23 Jul 2019 14:17:52 GMT</pubDate>
            <atom:updated>2019-07-23T19:55:50.863Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>What is a Graph and why is it important?</strong></p><p>A graph is data structure of interconnected nodes. These nodes can also be referred to as vertices and are where the actual data is stored. The edges of a graph are the connections between two different nodes. Graphs are probably the most important data type of the modern age. It is the basis of the entire internet. Most applications that require efficient processing between networks rely on them. Some examples are google maps or google searching.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/724/1*2jL0bKbT8ttskAlEVDv1yg.jpeg" /><figcaption>A simple graph of cities on google maps. The red lines are edges and the green circles are nodes.</figcaption></figure><p><strong>How do you navigate a Graph?</strong></p><p>Despite the graph above offering a visual representation of cities and interconnected routes to each one, how can we use it to find the best routes to take? The answer is Dijkstra’s shortest path algorithm, which is used to determine the most optimal path to take to get from one node to the next in the shortest amount of time. In fact, this guy was able to come up with this algorithm that we now call <em>breadth first search</em> in just several minutes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/486/1*VJSCuD5WQg6P8d9OCNRgVQ.jpeg" /><figcaption><a href="https://en.wikipedia.org/wiki/Edsger_W._Dijkstra">Edsger W. Dijkstra</a></figcaption></figure><p><strong>Breadth-First-Search (BFS)</strong></p><p>First, we start with the initial node anywhere on the graph, which is the starting point. From there we add (enqueue) every node that is directly connected to the current node onto a <strong>queue</strong>. A queue is just an abstract array/linkedlist that follows a <strong>FIFO</strong> (first-in-first-out) policy. Thus, it resembles a line and how the first person on the line is the first to exit. So as we add nodes, or enqueue to the queue, we can also remove nodes or dequeue from the queue in the order they were in line. This allows us to focus on the nodes that were first in line and thus we handle the closest nodes first and then the further nodes later. As we add nodes to the queue and check the value of each node to see if it is the desired value we map it out on a hashMap. This is another data structure that resembles a symbol table or dictionary depending on the type of languages you are familiar with. It is ultimately a key and value pair that shows the path or the edge as the key and the value is the distance or number of nodes in between the current node and the starting node.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/349/1*U_BKAIJT3mq5L0oD4F8vcg.png" /><figcaption>(BFS) Finding the shortest path</figcaption></figure><p>This is a very simple approach at viewing how google maps works. For google maps we have to deal more with weighted graphs where each edge has weight or should we say specifically, distance. All that does is filter the order of which the nodes of the connected nodes are added to the queue first. Despite this being a simple example it is still a lot of stuff to take in. Read more about graphs and the lower level data structures that they use to get a better grasp of how these work. Fortunately, graphs are such a high level data structure that much of their usage is abstracted to a large degree using different frameworks. However, it doesn’t hurt to get to know how these data types function especially for debugging purposes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/578/1*MEweqXw2op646Sqq4N1jfg.png" /><figcaption>Weighted graph of different cities in the U.S.</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b67c653a5e21" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Linked Lists?]]></title>
            <link>https://medium.com/@ghalstein97/linked-lists-2f135064231d?source=rss-962086c38ff6------2</link>
            <guid isPermaLink="false">https://medium.com/p/2f135064231d</guid>
            <category><![CDATA[linked-lists]]></category>
            <category><![CDATA[linked-data]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[data-structures]]></category>
            <dc:creator><![CDATA[Garrett Codes]]></dc:creator>
            <pubDate>Thu, 11 Jul 2019 14:14:27 GMT</pubDate>
            <atom:updated>2019-07-11T14:14:27.278Z</atom:updated>
            <content:encoded><![CDATA[<h3>What is this data structure?</h3><p>A linked list is essentially the opposite construction of an array but is used to store data just like an array does. So they are both used for storage, but they serve different purposes for storage.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/759/1*6ReSYwX-z-n4jWPCRSxqBw.png" /><figcaption>Visualization of a linked list.</figcaption></figure><h3>How does it differ from arrays?</h3><p>An array is a contingent data structure declared in memory. Thus, once you declare an instance of an array its size cannot be changed. However, with abstraction you can make seemingly “resizing” arrays, which is just an array backed up by methods that create a bigger array if an element is added to it when its already full. There is more to resizing arrays and different ways to implement them but the idea behind them is that they are an abstracted array so that they can be used more flexibly.</p><p>A linked list essentially solves the problem for arrays without using extra abstraction. And with that there are compromises being made because there is not a single perfect data structure. The main trade-off between a linked list and an array is that a linked list is designed so that you can keep adding elements to it without a problem. So how is this done and what is the compromise.</p><p>Firstly, a linked list holds a subclass within its own class usually referred to as a node. This node is basically a single slot of memory. You can think of it as a single index in an array. The node typically accepts attributes such as a string or integer. However, that is all stored in the node. It is just a tiny piece of memory. However, by making use of pointer and another node you can have a linked chain of data.</p><pre><strong>class</strong> LinkedList {</pre><pre>Node head; // head of list</pre><pre>/* Linked list Node*/</pre><pre><strong>   class</strong> Node {</pre><pre><strong>      int</strong> data;</pre><pre>      Node next;</pre><pre>/* Constructor to create a new node Next is by default initialized as null */</pre><pre>      Node(<strong>int</strong> d) { data = d; }</pre><pre>   }</pre><pre>}</pre><p>Looking at the code above you may be wondering how a node holds itself within itself? This is a recursive idea in programming but in order to point to another node you need some way of pointing to that other node. Using another node as an attribute for that node is a good way of calling on it. However, this is how it is done in Java where recursive classes are a built-in feature. Fortunately pointers are handled for us in Java, but C++ typically makes you handle your own pointers. A new node can then point to another node which can then point to a new node and so on. Thus this allows you to add more elements to a storage unit and it manages to just increase every time you insert an element. The addition of a new node is instant time complexity of O(1), which is a far better transaction than the O(n) time complexity found in how arrays are “resized”. So if linked lists are such a great way to dynamically store data then why don’t we just always use them. Well as I mentioned before there is no perfect data structure and trade-offs are made made when using one compared to the other. One small reason is that linked lists take up slightly more space than array slots. This is due to the pointer and node details of a linked list requiring more space than raw array memory. Also the beauty of having an array is that you can call on an index of that array with constant time complexity, O(1). However, in the case of a linked list you have to always start from the head node when traversing through it because the only thing connecting the data are the pointers. Thus the time complexity for traversing a linked list is linear O(n). This is not nearly as favorable time complexity for selecting from or even traversing through a list.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/420/1*C1n3Q-NtQwRlpac4US-vJQ.gif" /><figcaption>Binary Search Tree building off linked lists to make more organized data.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/232/1*MnIsbShNwP7u6UFTDtpFhg.png" /><figcaption>A HashTable based on an array holding linked lists.</figcaption></figure><h3>When to use what?</h3><p>So because two data structures have their trade-offs certain situations may require one or the other. It is preferable to use arrays for when storing a large amount of data that you will refer back to is the ultimate goal. However, linked lists come in handy for more dynamic motives that require a ton of adding and deleting data. However, because of modern technology it may seem that linked lists are becoming more antiquated because of the increase in RAM. Ignoring space complexity, resizing arrays might seemingly be able to do everything a linked list can do but even better because all elements can be recalled in it with constant time complexity and elements can be easily sorted. However, linked lists are a crucial data structure for higher level data structures that either solely or partially depend on them such as hash tables and binary search trees. In higher scale applications where data is stored at incredible rates RAM can still be an issue and this is why linked lists are still here to stay.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2f135064231d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introducing Data Structures: Arrays]]></title>
            <link>https://medium.com/@ghalstein97/introducing-data-structures-arrays-124069490d13?source=rss-962086c38ff6------2</link>
            <guid isPermaLink="false">https://medium.com/p/124069490d13</guid>
            <category><![CDATA[bootc]]></category>
            <category><![CDATA[arrays]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Garrett Codes]]></dc:creator>
            <pubDate>Mon, 24 Jun 2019 20:53:22 GMT</pubDate>
            <atom:updated>2019-06-26T03:45:59.042Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/715/1*_Rx5XRmPSbCi52IcWPEuMw.jpeg" /></figure><h3>What is an array?</h3><p>People coming from different backgrounds may have different answers about what an array is but generally a similar idea about what it can be used for. However, the great distinction comes into play based on the level of the language you are using an array in. Lower level programming languages such as C++ and Java tend to show what is going under the hood while languages such as Javascript or Ruby provide a more abstracted array class from the start. All languages can still agree that an array can be used to store data.</p><h3><strong>What is going on under the hood?</strong></h3><p>I want to talk about what is going on under the hood because many people breaking into tech that start off learning very high level languages may have never gotten the opportunity to understand the true mechanics of certain data structures. For example, when I was learning Ruby, I noted it was a beautifully written language with incredible readability, yet if I did not have prior exposure to languages like Java I would have not been able to grasp certain concepts about the details of an array.</p><p>Certain mechanics of an array that are abstracted in Ruby and Javascript can be especially apparent in an array’s size. The size of an array at the most bare level is not dynamic. It is a statically set size that cannot change. This is because an array underneath all abstraction is just a collection of contiguous blocks of memory. You cannot just add memory to it as needed. Specifically, in Java and languages alike, you have to declare the array’s size and even the datatype it holds like shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/382/1*lVfzqSOuJ9_V6XPPED2mGw.jpeg" /><figcaption>Declaring an array in Java.</figcaption></figure><p>This may seem limiting but it is how arrays are stored in memory at lower levels. In fact, underneath the abstraction of higher level languages there are static arrays just as you see above.</p><h3>Why does this matter?</h3><p>Earlier I brushed upon why it is important to understand how an array works under the hood of abstraction. Now, I want to discuss more about it. An array is a great tool to use for storing data but once it gets full or even close to empty you are going to want to change the size of it. The former is because there is no space left in the current array and the ladder is because there is too much wasted space. So, how does this happen if the array’s true structure is static? Let’s discuss what the abstraction is actually doing. Just like in Ruby, Java has abstractions of the array class that allows them to be more flexible such as ArrayLists. The idea behind a resizing array is that when the array is full and an item is added to it, it will double in size to accommodate for more space. The pseudo code below demonstrates how the instance of the class keeps track of the amount of elements in the array via the “size” variable and compares it to the actual array length.</p><pre>if (size == array.length) { // when the array is full</pre><pre>...Create a new array double in size ...</pre><pre>}</pre><p>The array does not actually double in size, in fact, by using the pseudo code above it keeps track of the array size and a new array is created when it is full. Then by iterating through the old array to add the contents in the same order to the new array, a copy of the new array that is double in size is formed. Now the the new array can hold the new element that was added without triggering any “index out of bound” error. This is a simple process but costs quite a bit of time because the array must be iterated fully through to make a copy of it. If you are familiar with Big-O-notation that would be equivalent to O(n), where n is the length of the array. It most favorable to keep Big-O time complexity as low as possible. However, in this case it is worth it because normally an array does not have to resize that often, especially when it is larger in size. Thus, appending to an array on average manages to keep a constant time complexity.</p><p>Alright, we resized an array when it got full, but what happens when you delete the element immediately after you just added it … That’s right it does nothing. It might seems wasteful to allocate so much mor space than what you currently need but it does not seem wise to create a new, smaller array and copy all of the contents right after you just did it the step before either. This could cause time complexity to snowball especially for programs involving a lot of adding and deleting from arrays. Thus, the program could begin to slow down over time. It would be better to only resize if it is completely necessary. What actually happens with dynamic arrays like ArrayLists, or Ruby arrays, is that the array will half in size if it is a quarter-filled after a deletion. The idea behind this is that the array never wastes too much space and is on average half-way filled. The average time complexity stays low because it does not have to resize that often. It is not magic but it can appear that way using it on the surface.</p><h3>Going forward…</h3><p>After reading this hopefully you are taking in some key-points about the under-workings of an array. Going forward with this you can start looking at the time complexity at work with an array. For example, when you add an element to the front of an array start to think about the effect it has on your array and the time that it could take if it is a large array. You cannot just stick it there, but you will have to slide everything over to free up that first index. That is once again a time complexity of O(n). Understanding the consequences of some of these manipulations on arrays is important and will definitely change your way of thinking when approaching algorithm questions and optimizing efficiency.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=124069490d13" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>