<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Amira Abdelhalim</title>
    <description>The latest articles on DEV Community by Amira Abdelhalim (@amiraabdelhalim).</description>
    <link>https://dev.to/amiraabdelhalim</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F700246%2Fc343f2b6-df06-4942-8870-7d57bbcb9bb7.jpg</url>
      <title>DEV Community: Amira Abdelhalim</title>
      <link>https://dev.to/amiraabdelhalim</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/amiraabdelhalim"/>
    <language>en</language>
    <item>
      <title>Breadth-First Search </title>
      <dc:creator>Amira Abdelhalim</dc:creator>
      <pubDate>Fri, 18 Feb 2022 13:25:54 +0000</pubDate>
      <link>https://dev.to/amiraabdelhalim/breadth-first-search-1p6l</link>
      <guid>https://dev.to/amiraabdelhalim/breadth-first-search-1p6l</guid>
      <description>&lt;p&gt;&lt;strong&gt;Breadth-First Search is an algorithm to search graph to find the shortest distance between two things.&lt;/strong&gt; &lt;br&gt;
&lt;em&gt;In order to talk about breadth-first search we need to know what is a graph? and what do we mean by shortest path? So first, let's figure out what is a graph.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Graph
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;It is a model for a set of connections.&lt;br&gt;
For Example, you are heading to many places today and you want to draw a graph to the places you would pass by, you will go from home to work, then to a restaurant, then you go back home, after that you would go to the supermarket.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc413dlfgvsg34red4z0t.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc413dlfgvsg34red4z0t.gif" alt="an illustration about a graph model"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Graphs are made of nodes and edges. A node can be directly connected to other nodes through edges. The directly connected nodes are called neighbors. In the above graph home is directly connected to work, so they are neighbors but work isn't directly connected to supermarket.&lt;br&gt;
&lt;em&gt;graphs are a way to model how different things are connected  to one another.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Now let's talk about what is meant by shortest-path.&lt;/p&gt;

&lt;h2&gt;
  
  
  Shortest-Path
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;It is an algorithm to find the path with the fewest steps. consider the path from your house to your friends house, ask yourself can you do it in one step? if no can you do it in two steps? keep asking until you find the shortest path.&lt;br&gt;
So in shortest path algorithms we follow two steps:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Model the problem as a graph.&lt;/li&gt;
&lt;li&gt;Solve the problem using breadth-first search.😉&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;It is time to talk about breadth-first search.&lt;/p&gt;

&lt;h2&gt;
  
  
  Breadth-First Search
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;It is an algorithm that runs on a graph. It helps in answering two questions: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Is there a path from node A to node B?&lt;/li&gt;
&lt;li&gt;What is the shortest path from node A to node B?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;let's have an example to understand breadth-first more.&lt;br&gt;
Suppose you are a new cat parent and you want to take your cat to a vet to make a checkup but you don't know any vet yet. Yo decided to have a look in your Facebook friends list to know if you are having a vet in your list.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;First, you will make a list of your friends to search.&lt;/li&gt;
&lt;li&gt;second, go to each person on the list and check whether that person is vet.
If the person is a vet CONGRATULATIONS you are done. If not go to the next person in the list.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Suppose none of your friends are vet. Now you have to search through your friends' friends. so you need to connect every friend of your friends with a list of their friends and start searching the new list. while doing this process you have created a graph of connected people and preformed a search algorithm to find a vet.&lt;br&gt;
In the previous process we saw how breadth-first search answers the first question. &lt;em&gt;Is there a vet in my network?&lt;/em&gt;&lt;br&gt;
Now let's try to answer the second question &lt;em&gt;who is the closest vet?&lt;/em&gt; Your friends are 1st degree connections and their friends are 2nd degree, so it is preferred to find vet in your 1st degree connections. While forming a list of connections it is preferred to use a QUEUE to make sure that people are searched in the order you added them.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Breadth-First Search Usage
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Here are some examples where breadth-first search is used:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;AI checkers that calculates the fewest moves to victory.&lt;/li&gt;
&lt;li&gt;Spell checker (fewest edits for the misspelled words).&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Implementing a Graph
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foxcbv8unm9sinbp5dza9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foxcbv8unm9sinbp5dza9.png" alt="implementing graph in python"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9ry27blt2n5gfeejqvvg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9ry27blt2n5gfeejqvvg.png" alt="graph visualization"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Implementing Breadth-First
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhleyu7xr22kq1qdmx6e3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhleyu7xr22kq1qdmx6e3.png" alt="breadth first search implementation"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>algorithms</category>
      <category>programming</category>
      <category>python</category>
      <category>datastructure</category>
    </item>
    <item>
      <title>Hash Tables</title>
      <dc:creator>Amira Abdelhalim</dc:creator>
      <pubDate>Sun, 17 Oct 2021 10:41:18 +0000</pubDate>
      <link>https://dev.to/amiraabdelhalim/hash-tables-35mj</link>
      <guid>https://dev.to/amiraabdelhalim/hash-tables-35mj</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;In this article we are starting by example before digging deeper into hash tables.&lt;/em&gt;&lt;br&gt;
suppose a cashier working in a grocery store and need to know the price of an apple, he/she would find the price in a book. If the book is alphabetized he/she would use a simple search which would take O(n) time. And if the book is alphabetized he/she would use binary search to find price of apples which would take O(log n) time.&lt;br&gt;
But what if the cashier is having an assistant, who memorize every item and its price, so it would take O(1) time.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Hash Function
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;hash function maps a string to a number. So a hash function can play the cashier assistant role, where he/she maps string &lt;strong&gt;item&lt;/strong&gt; to number &lt;strong&gt;price&lt;/strong&gt;. &lt;br&gt;
suppose we are having an array where we store the prices, we would give the hash function the apple price to be stored and the hash function would output number 0 which is the index where the apple price is stored in the array.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Hash Table
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;It is a complex data structure as it is a combination of a hash function and an array. hash tables consist of key and value.&lt;br&gt;
&lt;code&gt;{"apple": 5, "banana": 3}&lt;/code&gt;&lt;br&gt;
&lt;em&gt;you don't have to implement a hash table yourself it is already implemented in most programming languages.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Hash Table Use Cases
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;h5&gt;
  
  
  Using hash tables for lookup
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;the phone contact every name has a number associated to it.&lt;/li&gt;
&lt;li&gt;lookup for IP address that is associated with a web address.&lt;/li&gt;
&lt;/ul&gt;
&lt;h5&gt;
  
  
  Preventing duplicate entries
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;like voting system the same person cannot vote twice.&lt;/li&gt;
&lt;/ul&gt;
&lt;h5&gt;
  
  
  Using hash table as a cache
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;memorizing data instead of requesting it over and over.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Collisions
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;It is when two keys are assigned to the same slot in memory.&lt;br&gt;
One way to deal with a collision, if multiple keys are assigned to the same slot, start a linked list at this slot.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Performance
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;In the average case, hash tables have O(1) time complexity of everything!&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>datastructures</category>
      <category>hashtable</category>
    </item>
    <item>
      <title>Divide and Conquer</title>
      <dc:creator>Amira Abdelhalim</dc:creator>
      <pubDate>Wed, 13 Oct 2021 12:23:58 +0000</pubDate>
      <link>https://dev.to/amiraabdelhalim/divide-and-conquer-p0d</link>
      <guid>https://dev.to/amiraabdelhalim/divide-and-conquer-p0d</guid>
      <description>&lt;h2&gt;
  
  
  Divide and Conquer
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;it is a well-known recursive technique for solving problems. D&amp;amp;C gives a new way to think about solving problem.&lt;br&gt;
To solve a problem using D&amp;amp;C technique, there are two steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;figure out the base case(the simplest possible case).&lt;/li&gt;
&lt;li&gt;divide the problem until it becomes the base case.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;D&amp;amp;C isn't a simple algorithm that is applied to a problem. it is a way of thinking about the problem.&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;em&gt;Example&lt;/em&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If we want to know the sum of numbers in an array... let's think of the simplest base case we can have.&lt;br&gt;
The simplest case is to have an array of 0 or 1 item. so in each step we need to take our array closer to an empty array.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_NKJzEa9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1xp9v0sd0o9opj7xmoqg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_NKJzEa9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1xp9v0sd0o9opj7xmoqg.png"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Quicksort
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Quicksort is one of the algorithms that is built on divide and conquer technique. It is a sorting algorithm faster than selection sort and it is frequently used in real life.&lt;br&gt;
let's say we want to sort an array using quicksort what are the steps we shall do to have a sorted array.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;pick an element from the array, this element is called the &lt;em&gt;pivot&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;find the elements smaller than the pivot then the elements greater than the pivot. &lt;code&gt;this process is called partitioning&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;[33, 10]&lt;/code&gt; &lt;code&gt;(33)&lt;/code&gt; &lt;code&gt;[50, 34]&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;if sub-arrays are sorted we just need to combine them together.&lt;/li&gt;
&lt;li&gt;if sub-arrays are not sorted then repeat the first 2 steps until having a sorted array.&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;

</description>
    </item>
    <item>
      <title>Recursion and Stacks</title>
      <dc:creator>Amira Abdelhalim</dc:creator>
      <pubDate>Fri, 01 Oct 2021 16:41:11 +0000</pubDate>
      <link>https://dev.to/amiraabdelhalim/recursion-and-stacks-2a2i</link>
      <guid>https://dev.to/amiraabdelhalim/recursion-and-stacks-2a2i</guid>
      <description>&lt;h2&gt;
  
  
  What is Recursion?
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Recursion is where a function calls itself. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;em&gt;lets have an example&lt;/em&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;we are having a box that contains other boxes, and you know there is a key inside one of these boxes. You want to find that key, what would you do?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Here is an approach:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Make a pile of boxes to look through.&lt;/li&gt;
&lt;li&gt;Grab a box, and look through it.&lt;/li&gt;
&lt;li&gt;If you find a box, add it to the pile to look through later.&lt;/li&gt;
&lt;li&gt;If you find a key, you are DONE!🎉&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This approach uses a while loop, while pile is not empty grab a box, and look through it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvxryilbcve34pd1xln0w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvxryilbcve34pd1xln0w.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;An alternate approach:&lt;/strong&gt; &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Look through the box.&lt;/li&gt;
&lt;li&gt;If you find a box, go to step 1.&lt;/li&gt;
&lt;li&gt;If you find a key, you are DONE!🎉&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwpldpa1bm0cuqzvvestq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwpldpa1bm0cuqzvvestq.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This second approach uses &lt;em&gt;recursion&lt;/em&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;be careful using recursion as it may end up with infinite loop. 
That's why recursive functions has two parts
1. The base case -&amp;gt; function doesn't call itself again.
2. The recursive case -&amp;gt; function calls itself.  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Stacks
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Stack is an important concept in general programming, and also important to understand when using recursion.&lt;br&gt;
&lt;em&gt;let's have an example&lt;/em&gt;&lt;br&gt;
we are having a stack of sticky notes. when we insert an item we add it to the top of the stack. when we read an item we only read the topmost item, and it is taken of the stack.&lt;br&gt;
so our todo has two actions &lt;em&gt;push&lt;/em&gt;(insert) and &lt;em&gt;pop&lt;/em&gt;(remove)&lt;br&gt;
&lt;strong&gt;stack is last in first out data structures&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  The Call Stack
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;The computer uses a stack internally called &lt;em&gt;the call stack&lt;/em&gt; let's see how it works:&lt;br&gt;
&lt;em&gt;example&lt;/em&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyd4k5fxhqkrc2kaica5z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyd4k5fxhqkrc2kaica5z.png"&gt;&lt;/a&gt;&lt;br&gt;
This greet() function calls two functions greet2() and bye().&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxclezq1k2578517v670t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxclezq1k2578517v670t.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;suppose you call greet('maggie') your computer allocates a box in memory for that function call.&lt;/li&gt;
&lt;li&gt;variable &lt;code&gt;name&lt;/code&gt; is set to &lt;code&gt;maggie&lt;/code&gt; inside that memory box. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;every time you make a function call, your computer saves variables for that call in memory like the previous steps. Computer uses a stack of these boxes on top of each other every time you call a new function it is added to the top until it is finished then removed, that means the first function called the last to be finished.&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>algorithms</category>
      <category>stack</category>
      <category>recursion</category>
    </item>
    <item>
      <title>Linked lists, Arrays and Selection sort...</title>
      <dc:creator>Amira Abdelhalim</dc:creator>
      <pubDate>Thu, 09 Sep 2021 22:56:26 +0000</pubDate>
      <link>https://dev.to/amiraabdelhalim/linked-lists-arrays-and-selection-sort-41p</link>
      <guid>https://dev.to/amiraabdelhalim/linked-lists-arrays-and-selection-sort-41p</guid>
      <description>&lt;p&gt;Here is with chapter 2 of Grokking Algorithms.&lt;br&gt;
    • Computer memory is like a giant set of drawers, each drawer has an address. Each time we want to store an item we ask computer for some space and it gives us an address where we can store the item.&lt;br&gt;
    • Storing multiple items requires an array or a list&lt;/p&gt;

&lt;p&gt;“Array Vs Linked List”&lt;/p&gt;

&lt;p&gt;Arrays&lt;br&gt;
    • using array means our items will be stored contiguously in memory.&lt;br&gt;
    • Every time we add an item to the array we need to check if there is an empty place in the array it is added successfully else we need to ask if there is an empty place in memory that fits all our items right next to each other. &lt;br&gt;
    • The place of an item in array is known because items are stored contiguously so to read an item from array it takes O(1).&lt;br&gt;
    • To insert in an array it takes O(n) as  if we want to insert item at the beginning of an array we will need to shift all other items in the array.&lt;br&gt;
    • To delete from an array it also takes O(n) as every thing needs to be moved up when we delete an item.&lt;br&gt;&lt;br&gt;
    • Elements in array should be of the same type (int, string...etc,)                                                                                                &lt;/p&gt;

&lt;p&gt;“Let’s say we created an array with 10 slots but used only 5 slots in this case we won’t need to move to a new place in memory but here we wasted 5 places in memory.”&lt;/p&gt;

&lt;p&gt;Linked Lists&lt;br&gt;
    • using linked lists allow items to be stored anywhere in memory.&lt;br&gt;
    • Each item in the list stores the address of the next item.&lt;br&gt;
    • insertion takes O(1) in linked list as we only need to change what a previous element points to.&lt;br&gt;
    • deletion takes O(1) as well .&lt;br&gt;
    • Reading from a linked list takes O(n) as reading needs to go one by one to read the required element.&lt;/p&gt;

&lt;p&gt;“Selection Sort”&lt;br&gt;
    • sorting items according to certain criteria like:&lt;br&gt;
    1. sorting list of songs from most liked to least.&lt;br&gt;
    2. travel dates&lt;br&gt;
    3. emails ( newest to oldest)&lt;br&gt;
    4. names in a phone book &lt;br&gt;
    • time complexity of selection sort is O(n2) as we loop through list items 2 times (n x n).&lt;/p&gt;

&lt;h6&gt;
  
  
  # Here is an example of selection sort to find the smallest number in an array.
&lt;/h6&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F48it1fuh9ea5csvimn7z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F48it1fuh9ea5csvimn7z.png"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>algorithms</category>
      <category>datastructure</category>
      <category>linkedlist</category>
      <category>array</category>
    </item>
    <item>
      <title>Binary Search vs Simple Search</title>
      <dc:creator>Amira Abdelhalim</dc:creator>
      <pubDate>Mon, 06 Sep 2021 10:00:51 +0000</pubDate>
      <link>https://dev.to/amiraabdelhalim/binary-search-vs-simple-search-22cm</link>
      <guid>https://dev.to/amiraabdelhalim/binary-search-vs-simple-search-22cm</guid>
      <description>&lt;p&gt;I have been reading Gorkking Algorithms by Aditya Y.Bhargava. The book is one of the most interesting and enjoyable books about algorithms, so I thought I would share insights from each chapter.&lt;/p&gt;

&lt;p&gt;Chapter one is mainly  about the differences between simple search and binary search, the differences are as follow:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  “study case searching for number 10 in a list of 10 elements”

• simple search would loop on each element check if it is number 10 in case number 10 is the last element we would loop 10 times to reach our element …. what is the list is 1000,000 elements?

• Binary search is one of the searching algorithms that requires a sorted list as an input and outputs the location of the required element or null if doesn’t exist.

• Binary search works as follow =&amp;gt; “we are still working on our 10 elements list”
1. Low =&amp;gt; 0   first element of the list
2. high =&amp;gt; length(list) – 1  the last element of the list
3. mid =&amp;gt; (low + high) / 2
• check if number 10 is equal to mid if yes … Congratulations number 10 is found
• if number 10 is greater than mid … update low value to mid and recalculate mid value
• if number 10 is less than mid update high value to mid and recalculate mid value 
  “IN THIS STEP WE ELIMINATED THE LIST BY HALF”
• Repeat the past two steps until 10 is found.

• binary search would find an element in a list of 10 elements in only 3 steps if the element is the last element… if it is a list of 1000,000 elements it would take 20 steps only.

• simple search complexity according to big O notation is O(n).

• binary search complexity is O(log n).
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>algorithms</category>
    </item>
  </channel>
</rss>
