Posts

Array Basics

Image
Size of the array is fixed and can't be modified during runtime Arrays store data of specified type only Every cell has a unique index The index starts at 0.  Array elements are stored at contiguous memory locations in the array. Elements of all array types including linear, 2D, 3D, etc are stored in linear contiguous locations in memory. Suppose we want to go to a[6] i.e. seventh element and not 6th element, the computation is done internally as 0+6 i.e 6 elements after the first element, hence we get the seventh element. refToArray[x102] -------->[0][0][0][0]                                             here we get to the first element as x102 + 0                                                           ...

Single Linked List - All Operations

Image
  // the single linked list node class Node{     int data;     Node next;     Node(int x){         this.data=x;         this.next=null;     } } public class Main {       // head and tail of linked list     // we are maintaining a tail pointer too, as it helps us in inserting at the last of linked list very //easy     Node head;     Node tail;       // function to add a new node in linked list    // Time Complexity - O(1) , Space Complexity - O(1)      public void addNode(int x){         // create a new node with data x,  Time Complexity - O(1) , Space Complexity - O(1)          Node newNode = new Node(x);               // if linked list is empty         if(head==null){     ...
Hi everyone, I am Kshitiz Kumar. I am a Software Engineer. Currently, I am looking forward to strengthening my Data Structures and Algorithms Skills. Hence I thought of creating a space where I can write down my notes to revise later and maybe, create a resource for you guys which will contain clear, crisp, concise and relevant information only. I will be covering Data structures first, starting with the linked list. Ideally, it should start with the Array data structure, but this idea came to my mind when I was revising the linked list's concepts. I will add concepts of Arrays later during my revision. I am not taking any reference as of now and coding completely all by myself, please feel free to further optimize the code and point out any errors. The whole motive of this is to LEARN and I believe mistakes are the best way to do that. As I am a Java developer, I will code only in Java. My main focus is going to be on code. You can find all the topics that I cover und...