Skip to main content

Posts

Showing posts from June, 2023

Time Complexity in One Shot | MyCodingNetwork

  After exploring various aspect of programming, it's important to understand and calculate the amount of time our code takes to execute for a given size of input. The concept needed for this is called Time Complexity. In this article we will be exploring various aspects of Time Complexity and also solve numerous questions on it, so that we can have strong foundation of one of the most important aspect in the world of DSA. Introduction For a beginner the first question that should come to his/her mind is, "what is time complexity?". The answer is pretty simple, it is a measure of the amount of time an algorithm takes to complete as a function of the size of the input . It is important to analyze the time complexity of an algorithm because it helps us to compare different solutions and choose the most efficient one for a given problem.  In simple words (just to understand), one way to measure the time complexity of an algorithm is to count the number of iterations it perfo

Reverse a Linked List | Java | MyCodingNetwork

How to Reverse a Linked List Hey everyone, welcome to another article on Linked List. Till now we have covered various operations on linked list and in this article, we would be unraveling another operation on Linked List to understand this data structure in a much deeper way. The problem statement of this article is:   How to Reverse a Linked List. Algorithm for reversing a Linked List iteratively: There can be a several approaches to solve this problem, but in this article we would be restricting ourselves to iterative approach. 1. Create three nodes, ‘prev’, ‘curr’ and ‘next’.        2.         Assign: ·          ‘prev’ as ‘NULL’ ·          ‘curr’ as ‘head’ ·          ‘next’ as ‘NULL’        3.        Create a while loop with condition curr not equal to null. In each iteration: ·          ‘next’ is assigned with curr.next ·          ‘curr’ is made to point towards ‘prev’ ·          Assign ‘prev’ with ‘curr’ ·          Assign ‘curr’ with ‘next’        4.        Af