<?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: Andres Ramirez</title>
    <description>The latest articles on DEV Community by Andres Ramirez (@afmirez).</description>
    <link>https://dev.to/afmirez</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%2F1348503%2Fcd44f54d-7a45-4a4e-96fa-91c164d5af75.jpeg</url>
      <title>DEV Community: Andres Ramirez</title>
      <link>https://dev.to/afmirez</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/afmirez"/>
    <language>en</language>
    <item>
      <title>C# Priority Queue</title>
      <dc:creator>Andres Ramirez</dc:creator>
      <pubDate>Mon, 29 Apr 2024 14:50:09 +0000</pubDate>
      <link>https://dev.to/afmirez/c-priority-queue-5agj</link>
      <guid>https://dev.to/afmirez/c-priority-queue-5agj</guid>
      <description>&lt;p&gt;Imagine a heap as a special kind of tree where each parent node has a value that's less than or equal to the values of its children. In simpler terms, you can think of it as a tree where the parent node is always smaller (or larger) than its children. This property makes heaps perfect for priority queues, where the topmost element (root) always has the highest (or lowest) priority.&lt;/p&gt;

&lt;p&gt;By default, the .NET class &lt;a href="https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.priorityqueue-2?view=net-8.0"&gt;PriorityQueue&lt;/a&gt; provide us with a Min Heap. This means that the smallest element is always at the root (every parent node has a value less than or equal to the values of its children), however, we are allowed to pass a "Comparer" function to modify this behavior.&lt;/p&gt;

&lt;p&gt;This is what I want to show you in this article. We are going to implement a Max Heap using the Priority Queue class, introduced in .NET 6&lt;/p&gt;

&lt;p&gt;We will resolve this &lt;a href="https://leetcode.com/problems/largest-number-after-digit-swaps-by-parity/"&gt;leetcode exercise&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;You are given a positive integer num. You may swap any two digits of num that have the same parity (i.e. both odd digits or both even digits).&lt;/p&gt;

&lt;p&gt;Return the largest possible value of num after any number of swaps.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Solution:  This method initializes two priority queues, pqOdd and pqEven, to store odd and even digits respectively in descending order. It then iterates through each digit of the input number, enqueuing them into the appropriate priority queue based on their parity (odd or even) and marking their position in the result list accordingly. After all digits are processed, it dequeues the digits from the priority queues in the order specified by the result list, effectively rearranging them to form the largest integer possible. Finally, it converts the rearranged digits back into an integer and returns it.&lt;/p&gt;

&lt;p&gt;Note that we pass a Comparer function and therefore achieve the behavior of the priority queue as a max heap&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Solution
{
    // Method to find the largest possible integer by rearranging the digits of the input number
    public int LargestInteger(int num)
    {
        // Initialize two priority queues to store digits: pqOdd for odd digits and pqEven for even digits
        // Priority queues are initialized with custom comparers to ensure descending order
        PriorityQueue&amp;lt;int, int&amp;gt; pqOdd = new PriorityQueue&amp;lt;int, int&amp;gt;(Comparer&amp;lt;int&amp;gt;.Create((a, b) =&amp;gt; b - a));
        PriorityQueue&amp;lt;int, int&amp;gt; pqEven = new PriorityQueue&amp;lt;int, int&amp;gt;(Comparer&amp;lt;int&amp;gt;.Create((a, b) =&amp;gt; b - a));

        // List to store the result digits
        List&amp;lt;int&amp;gt; result = new List&amp;lt;int&amp;gt;();

        // Iterate through each digit of the input number
        foreach (char digit in num.ToString())
        {
            // Convert the character digit to an integer
            int digitInt = int.Parse(digit.ToString());

            // Check if the digit is even or odd
            if (digitInt % 2 == 0) {
                // If even, enqueue the digit into pqOdd with the digit itself as priority
                pqOdd.Enqueue(digitInt, digitInt);
                // Add 0 to the result list to mark the position of the even digit
                result.Add(0);
            }
            else {
                // If odd, enqueue the digit into pqEven with the digit itself as priority
                pqEven.Enqueue(digitInt, digitInt);
                // Add 1 to the result list to mark the position of the odd digit
                result.Add(1);
            };
        }

        // Iterate through the result list to rearrange the digits
        for (int i = 0; i &amp;lt; result.Count(); i++)
        {
            // If the result at index i is 0, dequeue the top element from pqOdd and update the result list
            if (result[i] == 0)
            {
                result[i] = pqOdd.Dequeue();
            }
            // If the result at index i is 1, dequeue the top element from pqEven and update the result list
            else
            {
                result[i] = pqEven.Dequeue();
            }
        }

        // Convert the result list to a string and then to an integer, and return it
        return int.Parse(string.Join("", result));
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>csharp</category>
      <category>algorithms</category>
    </item>
    <item>
      <title>C# Stacks</title>
      <dc:creator>Andres Ramirez</dc:creator>
      <pubDate>Thu, 28 Mar 2024 17:55:28 +0000</pubDate>
      <link>https://dev.to/afmirez/c-stacks-5h1b</link>
      <guid>https://dev.to/afmirez/c-stacks-5h1b</guid>
      <description>&lt;p&gt;A stack follows the Last In, First Out (LIFO) or First In, Last Out (FILO) order, which means that the last element added to the stack is the first one to be removed.&lt;/p&gt;

&lt;p&gt;To manage a stack, a pointer to the top is maintained, allowing access only to the top element.&lt;/p&gt;

&lt;p&gt;Basic operations include push, pop, peek, isempty, top, and size. &lt;/p&gt;

&lt;p&gt;Two types of stacks exist: dynamic (adjusting size dynamically) and static (fixed size).&lt;/p&gt;

&lt;p&gt;Stacks can be implemented using arrays or linked lists.&lt;/p&gt;




&lt;h3&gt;
  
  
  Implementing Stack using Arrays
&lt;/h3&gt;

&lt;h2&gt;
  
  
  &lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F995j53shibdfipy7sujx.png" alt="Implementing Stack using Arrays" width="800" height="1544"&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Implementing Stack a Linked List
&lt;/h3&gt;

&lt;h2&gt;
  
  
  &lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn8bw50tnwdx9wtsscqp9.png" alt="Implementing Stack a Linked List" width="800" height="1438"&gt;
&lt;/h2&gt;

&lt;p&gt;Implement a stack using singly linked list&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using System;

// Create Stack Using Linked list
public class StackUsingLinkedlist {

    // A linked list node
    private class Node {
        // integer data
        public int data;

        // reference variable Node type
        public Node link;
    }

    // create global top reference variable
    Node top;

    // Constructor
    public StackUsingLinkedlist() { this.top = null; }

    // Utility function to add
    // an element x in the stack
    // insert at the beginning
    public void push(int x)
    {
        // create new node temp and allocate memory
        Node temp = new Node();

        // check if stack (heap) is full.
        // Then inserting an element
        // would lead to stack overflow
        if (temp == null) {
            Console.Write("\nHeap Overflow");
            return;
        }

        // initialize data into temp data field
        temp.data = x;

        // put top reference into temp link
        temp.link = top;

        // update top reference
        top = temp;
    }

    // Utility function to check if
    // the stack is empty or not
    public bool isEmpty() { return top == null; }

    // Utility function to return
    // top element in a stack
    public int peek()
    {
        // check for empty stack
        if (!isEmpty()) {
            return top.data;
        }
        else {
            Console.WriteLine("Stack is empty");
            return -1;
        }
    }

    // Utility function to pop top element from the stack
    public void pop() // remove at the beginning
    {
        // check for stack underflow
        if (top == null) {
            Console.Write("\nStack Underflow");
            return;
        }

        // update the top pointer to
        // point to the next node
        top = (top).link;
    }

    public void display()
    {
        // check for stack underflow
        if (top == null) {
            Console.Write("\nStack Underflow");
            return;
        }
        else {
            Node temp = top;
            while (temp != null) {

                // print node data
                Console.Write(temp.data);

                // assign temp link to temp
                temp = temp.link;
                if(temp != null)
                    Console.Write(" -&amp;gt; ");
            }
        }
    }
}

// Driver code
public class GFG {
    public static void Main(String[] args)
    {
        // create Object of Implementing class
        StackUsingLinkedlist obj
            = new StackUsingLinkedlist();

        // insert Stack value
        obj.push(11);
        obj.push(22);
        obj.push(33);
        obj.push(44);

        // print Stack elements
        obj.display();

        // print Top element of Stack
        Console.Write("\nTop element is {0}\n", obj.peek());

        // Delete top element of Stack
        obj.pop();
        obj.pop();

        // print Stack elements
        obj.display();

        // print Top element of Stack
        Console.Write("\nTop element is {0}\n", obj.peek());
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>csharp</category>
      <category>datastructures</category>
      <category>coding</category>
    </item>
    <item>
      <title>Multiple Pointers | C#</title>
      <dc:creator>Andres Ramirez</dc:creator>
      <pubDate>Tue, 26 Mar 2024 12:59:15 +0000</pubDate>
      <link>https://dev.to/afmirez/multiple-pointers-c-12d6</link>
      <guid>https://dev.to/afmirez/multiple-pointers-c-12d6</guid>
      <description>&lt;h2&gt;
  
  
  What is this all about?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Used for searching pairs in a SORTED array&lt;/li&gt;
&lt;li&gt;Create pointers that correspond to an index and move towards the beginning, end or middle based on a certain condition.&lt;/li&gt;
&lt;li&gt;We are able to process two or more elements per loop instead of just one.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  When do we use it?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;In many problems involving collections such as arrays or lists, we have to analyze each element of the collection compared to its other elements.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Common patterns
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Two pointers, each starting from the beginning and the end until they both meet.&lt;/li&gt;
&lt;li&gt;One pointer moving at a slow pace, while the other pointer moves at twice the speed.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;--- Problem
    We are asked to compare two elements in an ordered array.

--- FOOR LOOP
     If we use a for loop, we create an external pointer and use the 
     internal "j" as the second pointer.
         var i = 0;          
         for(var j = 1; j &amp;lt; array.length; j++){  
                if(arr[i] !== arr[j]){
                    i++; 
                    arr[i] = arr[j]
                }

--- WHILE LOOP
    If we use a while loop we create two external pointers and the  
    base one case is while left&amp;lt;right {}. This structure is used when 
    we need to traverse the array from two opposite points. 

        let left = 0                       &amp;lt;-- pointer 1
        let right = array.length - 1       &amp;lt;-- pointer 2
        while (left &amp;lt; right) {
            let average = array[left] + array[right] / 2 
            if (average === target) return true; 
            else if(average &amp;lt; target) left++
            else right--  
        }
        return false 
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  In action
&lt;/h2&gt;

&lt;p&gt;Implement a function called countUniqueValues, which accepts a sorted array, and counts the unique values in the array. &lt;/p&gt;

&lt;p&gt;Code to resolve this:&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7hlxbdeqr99cvns7nxfh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7hlxbdeqr99cvns7nxfh.png" alt="Ex1 Solution" width="800" height="888"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>csharp</category>
      <category>datastructures</category>
      <category>coding</category>
    </item>
    <item>
      <title>Frequency Counter Technique in C#</title>
      <dc:creator>Andres Ramirez</dc:creator>
      <pubDate>Thu, 21 Mar 2024 22:08:30 +0000</pubDate>
      <link>https://dev.to/afmirez/frequency-counters-52km</link>
      <guid>https://dev.to/afmirez/frequency-counters-52km</guid>
      <description>&lt;h2&gt;
  
  
  How to identify it?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Querying item presence in A against B.&lt;/li&gt;
&lt;li&gt;Prioritizing linear time complexity (O(n)) over quadratic (O(n²)), avoiding nested loops.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  TO ACCOMPLISH THIS OBJECTIVE...
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Utilize individual O(n) loops instead of nested loops for efficiency.&lt;/li&gt;
&lt;li&gt;Employ object mapping to facilitate element comparison.&lt;/li&gt;
&lt;li&gt;Establish keys as elements and values as their respective frequencies.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;---Pseudocode
            A) Iterate through the array 
            B) Grab the value of each item in the array and set it to variable key 
            C) If key exists as a key in myObject... 
            D) ... increment it by 1 
            E) If not (key doesn't exist in myObject)... 
            F) ... create key in myObject and set it equal to 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  FREQUENCY COUNTER IN ACTION
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; Write a function frequencyCounter, which accepts two arrays. The function should return true if every value in the array has its corresponding value squared in the second array. The frequency values must be the same.&lt;/p&gt;

&lt;p&gt;Code to solve this problem:&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv404c873zkiiti3kp9vj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv404c873zkiiti3kp9vj.png" alt="Frequency Counter Ex1" width="800" height="1455"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Mapping each list's elements to their frequencies in separate dictionaries enables efficient comparison, ensuring a streamlined process. &lt;strong&gt;This technique sidesteps nested loops&lt;/strong&gt;, resulting in a time complexity of O(n) and superior efficiency compared to alternative methods.&lt;/p&gt;

&lt;p&gt;With two individual loops, each element in the arrays is processed separately, allowing for direct comparison and frequency counting. Nested loops, on the other hand, would lead to redundant comparisons between every pair of elements, resulting in unnecessary computations.&lt;/p&gt;




&lt;h2&gt;
  
  
  ADDITIONAL EXERCISES:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://leetcode.com/problems/valid-anagram/"&gt;Valid Anagram&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://walkccc.me/CS/JavaScript/01/frequencyCounters/#:~:text=true%3B%0A%7D%3B-,areThereDuplicates(...args),-%C2%B6"&gt;Are There Duplicates?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://onecompiler.com/posts/4248c2n9u/frequency-counter-write-a-function-called-samefrequency-given-two-positive-integers-find-out-if-the-two-numbers-have-the-same-frequency-of-digits"&gt;Same Frequency&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>csharp</category>
      <category>datastructures</category>
      <category>programming</category>
    </item>
    <item>
      <title>C# Linked Lists: Exploring Dummy Nodes, Pointers, and More | Data Structures</title>
      <dc:creator>Andres Ramirez</dc:creator>
      <pubDate>Wed, 20 Mar 2024 17:37:22 +0000</pubDate>
      <link>https://dev.to/afmirez/c-linked-lists-data-structures-1gag</link>
      <guid>https://dev.to/afmirez/c-linked-lists-data-structures-1gag</guid>
      <description>&lt;p&gt;Implementing a Linked List (LL) involves creating a linear data structure with interconnected nodes. Utilizing pointers, such as 'Head' and 'Tail,' involves variables pointing to the memory locations of the first and last elements in the LL, respectively.&lt;/p&gt;

&lt;p&gt;An essential concept in Linked Lists (LL) is their dependence on references rather than indexes. Navigating to a specific point, such as D, entails methodically traversing the sequence A → B → C → D.&lt;/p&gt;

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




&lt;h2&gt;
  
  
  🔄IMPLEMENTATION
&lt;/h2&gt;

&lt;p&gt;This code initializes a linked list with a single node containing a specified value. The LinkedList class includes a private Node class with properties for value and next, and a constructor that creates a new node and sets both head and tail to reference it, initializing the length to 1.&lt;/p&gt;

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




&lt;h2&gt;
  
  
  📝LINKED LISTS TYPES
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Single LL: Each node in the list contains a reference (or pointer) to the next node in the sequence. The last node points to null, indicating the end of the list.&lt;/li&gt;
&lt;li&gt;Doubly LL: Each node contains references to both the next and the previous nodes in the sequence. Allows traversal in both forward and backward directions.&lt;/li&gt;
&lt;li&gt;Circular LL: Similar to a singly linked list, but the last node points back to the first node, forming a circular structure. Can be implemented with a singly linked list or a doubly linked list.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  ✏️BASIC OPERATIONS
&lt;/h2&gt;

&lt;p&gt;To establish a robust foundation in Linked Lists, proficiency in the following key areas is imperative:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Get: Retrieve information from the Linked List.&lt;/li&gt;
&lt;li&gt;Update: Modifying existing elements within the Linked List.&lt;/li&gt;
&lt;li&gt;Insertion: Manage the addition of elements within the Linked List structure.&lt;/li&gt;
&lt;li&gt;Deletion: Handle the removal of elements from the Linked List.&lt;/li&gt;
&lt;li&gt;Reverse: Change the order of elements in the list so that the last node becomes the first and vice versa.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Get familiar with the &lt;a href="https://www.geeksforgeeks.org/data-structures/linked-list/#:~:text=Header%20Linked%20List-,Basic%20Operations%3A,-Linked%20List%20Insertion"&gt;Basic LL operations&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  📈FUNDAMENTALS FOR EXPLORING MORE COMPLEX LL EXERCISES
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Linked Lists and Reference Types: In Linked Lists, nodes are reference types. This means that any operation affecting a node will also affect any pointer that points to it.&lt;/li&gt;
&lt;li&gt;Pointer: A pointer is a variable that stores the memory address of another variable or object. In linked lists, pointers are used to keep track of the connections between nodes.&lt;/li&gt;
&lt;li&gt;Dummy Node: A dummy node is a special node added at the beginning of a linked list to simplify certain operations. It does not hold meaningful data and is used as a placeholder.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  CODING, CODING AND CODING...
&lt;/h2&gt;

&lt;p&gt;The best way to illustrate these concepts is if we explore some exercises.&lt;/p&gt;

&lt;h3&gt;
  
  
  Linked List Cicle
&lt;/h3&gt;

&lt;p&gt;Checkout this &lt;a href="https://leetcode.com/problems/remove-duplicates-from-sorted-list-ii/description/"&gt;PROBLEM&lt;/a&gt;. We need to validate if a LL has cycle in it. This is a perfect example to illustrate the use of pointers.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqc1bv63vujubtyhzi8q7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqc1bv63vujubtyhzi8q7.png" alt="Cycle in a LL" width="488" height="193"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Code to solve this problem:&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fio8mzi3ttm9b61si577j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fio8mzi3ttm9b61si577j.png" alt="Ex1 Solution" width="800" height="519"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Explanation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Pointers (fast and slow) are essential for traversing a linked list, enabling movement from one node to the next. Without them, iterating through and examining nodes would be impossible.&lt;/li&gt;
&lt;li&gt;By moving a fast pointer twice as fast as a slow pointer, the algorithm efficiently identifies whether a cycle exists in the list.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Remove Duplicates from Sorted List II
&lt;/h3&gt;

&lt;p&gt;In this &lt;a href="https://leetcode.com/problems/remove-duplicates-from-sorted-list-ii/description/"&gt;problem&lt;/a&gt;, we need to delete all nodes that have duplicate numbers. This is a perfect example to illustrate the use of a dummy node. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgv3ia15je1x7wau48vnk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgv3ia15je1x7wau48vnk.png" alt="Removing Duplicate Elements in a LL" width="621" height="180"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Code to solve this problem:&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwdtyire3ygmmrr3y1259.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwdtyire3ygmmrr3y1259.png" alt="Ex2 Solution" width="800" height="655"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It's important to note that we create a dummy node which always points to the head. This is convenient because even if the node pointed to by "head" changes, we'll always have a constant reference to the new value in question.&lt;/p&gt;

&lt;p&gt;This case teaches us that &lt;strong&gt;WE CAN USE A DUMMY NODE IN SITUATIONS WHERE THE HEAD OR THE LINKED LIST ITSELF MAY UNDERGO CHANGES AS THEY GO THROUGH OUR CODE&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Merge Two Sorted Lists
&lt;/h3&gt;

&lt;p&gt;In this &lt;a href="https://leetcode.com/problems/merge-two-sorted-lists/"&gt;problem&lt;/a&gt; we need to merge the two lists into one (new) sorted list. This is a very good example of using a dummy node, but with a different approach.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frxvn326knyw58tfwuhxl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frxvn326knyw58tfwuhxl.png" alt="Merge Two Sorted Lists" width="662" height="302"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Code to solve this problem:&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg34kw9skczg5lo7dcam5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg34kw9skczg5lo7dcam5.png" alt="Ex3 Solution" width="800" height="744"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The dummy node acts as a placeholder for the merged list. It ensures that current always points to a valid node, even if the first node of the merged list changes during the merging process.&lt;/li&gt;
&lt;li&gt;Inside the loop, the value of current is updated iteratively based on the values of the nodes in list1 and list2. By using a dummy node, we can avoid special handling for the first node of the merged list.&lt;/li&gt;
&lt;li&gt;After the loop, the next pointer of the last node (current) points to the remaining nodes of either list1 or list2. The dummy node's next pointer (dummy.next) then serves as the head of the merged list.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  CONCLUSION
&lt;/h2&gt;

&lt;p&gt;Understanding pointers and dummy nodes is crucial for effectively solving complex problems involving linked lists. Pointers facilitate efficient traversal and manipulation of linked list elements, while dummy nodes provide a consistent starting point for various operations, simplifying code logic. Additionally, grasping the reference type nature of nodes in linked lists helps in managing node connections and ensuring proper list manipulation. Together, these concepts empower developers to tackle intricate linked list problems with clarity and efficiency.&lt;/p&gt;

</description>
      <category>csharp</category>
      <category>datastructures</category>
      <category>codinginterview</category>
    </item>
    <item>
      <title>C# ARRAYS | DATA STRUCTURE.</title>
      <dc:creator>Andres Ramirez</dc:creator>
      <pubDate>Wed, 20 Mar 2024 13:36:23 +0000</pubDate>
      <link>https://dev.to/afmirez/c-arrays-data-structure-29i</link>
      <guid>https://dev.to/afmirez/c-arrays-data-structure-29i</guid>
      <description>&lt;p&gt;&lt;strong&gt;Arrays&lt;/strong&gt; are fundamental data structures that allow you to store multiple values of the &lt;strong&gt;same data type&lt;/strong&gt; in a single variable.&lt;/p&gt;




&lt;h2&gt;
  
  
  🔢ARRAY PROPERTIES AND LIMITATIONS
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Array dimensions are set upon declaration, with lengths determined during instantiation, remaining immutable thereafter.&lt;/li&gt;
&lt;li&gt;Elements in an array are accessed using an index.&lt;/li&gt;
&lt;li&gt;All elements in an array must be of the same data type.&lt;/li&gt;
&lt;li&gt;Accessing an index beyond the array's bounds triggers a runtime exception.&lt;/li&gt;
&lt;li&gt;When passing an array as a parameter to a method, you are passing a reference to the array, not a copy of the entire array. &lt;/li&gt;
&lt;li&gt;Arrays can be single-dimensional, multidimensional, or jagged.&lt;/li&gt;
&lt;li&gt;Unlike lists and other data structures, arrays lack built-in methods for typical operations such as element addition, removal, or sorting&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🧩ARRAY TYPES
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Single-dimensional array:&lt;/strong&gt; An array containing elements arranged in a single line. Accessed using a single index. Represented as a linear collection of elements.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Two-dimensional array:&lt;/strong&gt; An array containing elements arranged in rows and columns. Accessed using two indices, one for the row and one for the column. Represents a table-like structure of data.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Three-dimensional array:&lt;/strong&gt; An array containing elements arranged in a three-dimensional space. Accessed using three indices, representing depth, row, and column. Represents a cube-like structure of data.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Jagged array:&lt;/strong&gt; An array whose elements are arrays themselves. Each sub-array can have a different length. Provides flexibility in representing irregular or non-rectangular data structures.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  📦INITIALIZATION
&lt;/h2&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%2F4ck5ypqg70693sdsywk9.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%2F4ck5ypqg70693sdsywk9.png" alt="Arrays | Initialization"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  📚ARRAY CLASS
&lt;/h2&gt;

&lt;p&gt;C# offers an &lt;strong&gt;Array class&lt;/strong&gt; to handle various array-related operations. Equipped with methods for creating, manipulating, searching, and sorting array elements, this class serves as the foundational framework for all arrays within the .NET programming ecosystem.&lt;br&gt;
&lt;a href="https://www.javatpoint.com/c-sharp-array-class" rel="noopener noreferrer"&gt;Learn more&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  🎯ADDITIONAL RESOURCES
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.geeksforgeeks.org/array-data-structure/" rel="noopener noreferrer"&gt;Array Data Structure | Geeks For Geeks&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=i6n_fwLTKIc&amp;amp;ab_channel=DaniKrossing" rel="noopener noreferrer"&gt;Multidimensional Arrays in C# | Video Tutorial &lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=m-QmN3CjhRk&amp;amp;ab_channel=tutorialsEU-C%23" rel="noopener noreferrer"&gt;Jagged Array | Video Tutorial&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>csharp</category>
      <category>datastructures</category>
      <category>interview</category>
    </item>
  </channel>
</rss>
