Posts

Showing posts from November, 2021

How To Implement Binary Search Tree In Javascript - letsbug

      Many times we required to have more than two paths from data object  (non-linear) when we have to represent one or many relationship. The best way is to use non-linear data structure.     Tree is a non-linear data structure. Non-linear  data structures are capable of expression more complex relationship than linear data structure. In general, wherever the hierarchical relationship among data is to be preserved tree is used.     Today in this article we are going to implement a basic Binary Search Tree . But before that lets see a binary tree.     What is a Binary Tree?      Binary Tree is a special form of a tree is finite set of nodes, which is either empty or partitioned into three sets, one which is the root and two disjoint binary trees called left subtree and right subtree. It si a tree where every node can have at most two bran

How To Visualize Sorting Algorithm In Javascript | Bubble Sort - letsbug

Image
    One of the most  important thing that we have learnt over the years while learning in data structures and algorithms is that as important is to understand it and to use it. One should also know how to visualize these data structures and algorithms.      And we've got you covered in this article we are visualizing the bubble sort algorithm in javascript . And for this we are taking a help of a Javascript library called P5.js you can learn more about it by clicking here.       Let me give you a brief description about P5.js to you. Its is a library that helps you in your canvas, animation and simulation projects. In this project we have used downloaded the library but there is a cdn link that you can use in your project. And if you want to learn about the bubble sort algorithm click here.       So let's start out project  Bubble Sort Algorithm Visualizer Create a project folder. Create index.js, index.html files in it. Copy the html code in index.html and javascript code i

How To Implement Stack | In Javascript - letsbug

      Stack an ordered collection of items in which insertion and deletions are allowed only at one end called the top of the stack. Today in this article we are seeing how to implement stacks in Javascript. But before that a little intro to stacks     Stack is most essential linear data structure. A stack is a non-primitive linear data structure. And most important all the deletion and insertion in a stack is done from top of the stack, the last added element will be the first element to be removed from the stack. That is the reason why stack is also called Last-In-First-Out(LIFO) type of list.     This is how to define it A stack is an ordered collection of homogeneous data elements where the insertion and deletion operation take place at only one end; called as top of the stack.   And now How to implement stack in javascript     To implement it we will use "class" to create a stack class in javascript. The stack class constructor has two properties that is items which is

How To Do Binary Search In Javascript | Binary Search - letsbug

   Binary Search is one of the most important searching algorithm and today's article is on it.  Binary search is a quicker method to search than linear search. But it cannot be applied to unsorted data structures. The binary search is based on the approach divide-and-conquer.  Binary Search In Javascript     The binary search starts by testing the data in the middle element of the array. This determines target is whether in the first half or second half. If target is in first half, we do not need to check the second half and if it is in second half no need to check in first half.     And similarly we repeat this process until we find target in the list or not found from the list. Here we need 3 variable to identify first, last and middle element. This algorithm can be Iterative or recursive. Below is the code of binary search in javascript. /**  *  * @param {Array<Number>} arr is array  * @param {Number} x  * is the element to find in array arr  * @returns {Number} t

How to convert time to 24 hours format in javascript | letsbug

    Today is we are doing something which is the most basic thing that you come across in your everyday life. But barely notice it. And while you are learning programming you may have sometimes ignored it. It is time converting or changing it to different format.     And we will see  How To Convert Time To 24 Hours Military Format In Javascript       So, lets get started by creating a function. Name the function anything you want mine is timeConverter(time). We are passing time to the function.      Time which we are passing is a string like this "1:00:05AM". Now in the function first lets extract some important data from the input. Like we will extract hours, minutes and seconds.     Then as the format of input time is in 12 hours that means we will have AM/PM to differentiate between day and night. So, we will extract that data also. The variable half stores AM or PM.     After we have all the data extracted we can now convert it to 24 hours format. By first checking that

How To Find The Median In A Array | Javascript | letsbug

    When you are trying to learn Data structures and algorithms you come across this data type which is a array or list whatever you call it. It is one of the most basic data type and is fairly easy even for a newbie who is just getting started.     And one being easy means that it has ability to do very complex tasks. A array is just that. It is simple and does many complex things. But before going on complex algorithms and data structures lets see a simple problems first.     This is simple problem is  Finding Median in a Array     So let's start by first understanding what is median. The median is the middle number in a sorted, ascending or descending, list of numbers and can be more descriptive of that data set  than the average.     We are doing this in javascript by making a function which returns the median if we pass the array to the function. Hence below we have created  a  function which takes array as a parameter and returns the median.     In the function len variable s

How to reverse a array? How to reverse a array in javascript? - letsbug

     Hey everyone in this article we're going to see how we can reverse a array. In this article I am using javascript but it's not important. You can use any language you want only thing which is important is the logic behind it. You understand the logic means you can do or implement this in any language.     In the below code I start by first creating a arr variable and add random 10 numbers as the elements in the array. Actual reversing of the array happens in the reverseArray(array, n) function.     In the function we first create a variable and initialize it to a array to store the reversed array. The we loop the original array backwards starting from the last element to the first element. While passing through each element we push that element to the start of our reverserdArray variable. After the loop terminates we have the reversed version of original array returned from the function.     After that we can call the function and check the console to see the output. That&

Categories

Big Data Analytics Binary Search Binary Search Tree Binary To Decimal binary tree Breadth First Search Bubble sort C Programming c++ Chemical Reaction and equation class 10 class 10th Class 9 Climate Complex Numbers computer network counting sort CSS Cyber Offenses Cyber Security Cyberstalking Data Science Data Structures Decimal To Binary Development diamond pattern Digital Marketing dust of snow Economics Economics Lesson 4 Email Validation English fire and ice Food Security in India Footprints Without feet Forest And Wildlife Resources game Geography Geography lesson 6 glassmorphism Glossary Graph HackerRank Solution hindi HTML image previewer India-Size And Location Insertion Sort Internet Network Status Interview Questions Introduction to cyber crime and cyber security IT javascript tricks json to CSV converter lesson 2 lesson 1 lesson 2 Lesson 3 Lesson 6 lesson 7 Life lines of National Economy life processes Linear Search Linked List lowest common ancestor Machine Learning MCQs median in array Merge sort min and max of two numbers Moment Money and Credit My Childhood Natural Vegetation and Wildlife NCERT Network connectivity devices Network Models Network Security No Men Are foreign Node.js operator overloading P5.js PHP Physical features of India Population Prime Numbers python Quick sort R language Rain on the roof Regular Expression Resources and development reversing array saakhi science Searching Algorithm Selection sort Social Media Marketing social science Software Engineering Software Testing Sorting Algorithm Stacks staircase pattern System Concepts Text Recognition The last Leaf time converter Time Passed From A Date Todo List App Tree Trending Technologies Understanding Economic Development username and password video player Visualization water resources Wired And Wireless LAN साखी
Show more

Popular Posts

Big Data MCQs(multiple choice questions) with answers - letsbug

Digital Marketing MCQ(Multiple Choice Questions) with Answers | part 1 | letsbug

Software Engineering MCQs questions with answers - letsbug