Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles by karthikeya Boyini
Page 39 of 143
Searching for values in an Javascript Binary Search Tree
We're going to use the property of a BST to look up elements in it. In a Binary Search Tree, values smaller than the current node are in the left subtree, and values larger are in the right subtree, making search operations efficient. Iterative Search Implementation The iterative approach uses a loop to traverse the tree: searchIter(data) { let currNode = this.root; while (currNode !== null) { if (currNode.data === data) { ...
Read MoreWhat to do with content that renders outside the element box with JavaScript?
When content exceeds an element's dimensions, it can overflow outside the visible area. JavaScript provides several ways to handle this using the overflow property, which controls how overflowing content is displayed. Understanding Overflow Values The overflow property accepts several values: visible - Default behavior, content flows outside the box hidden - Clips content that overflows scroll - Always shows scrollbars auto - Shows scrollbars only when needed Example: Dynamic Overflow Control Here's a complete example demonstrating how to manage overflow with JavaScript: ...
Read MoreHTML5 & JavaScript: resolution or size of
HTML5 provides two approaches for capturing photos from mobile devices with different levels of control over image resolution and size. HTML Media Capture The simplest approach uses HTML's capture attribute with accept="image/*" on input elements to access the device camera. HTML Media Capture Capture Photo with HTML document.getElementById('camera').addEventListener('change', function(e) { ...
Read MoreCalculating the balance factor in a Javascript AVL Tree
AVL tree checks the height of the left and the right sub-trees and assures that the difference is not more than 1. This difference is called the Balance Factor. For example, in the following trees, the first tree is balanced and the next two trees are not balanced: Balanced (BF ≤ 1) B A C Unbalanced (BF = 2) ...
Read MoreInserting a node in a Javascript AVL Tree
We can learn how to insert a node in an AVL Tree. Insertions in AVL trees follow the same process as BST, but we need to perform one extra step called balance tree during insert whenever we move down the tree. This requires calculating the balance factor and applying appropriate rotation methods based on the tree configuration. The balance factor determines which type of rotation is needed to maintain the AVL property. Understanding AVL Tree Balance An AVL tree maintains balance by ensuring that for every node, the heights of its left and right subtrees differ by ...
Read MoreCreating a Graph in Javascript
We'll be creating a graph class that supports weights and both directed and undirected types. This will be implemented using an adjacency list. As we move to more advanced concepts, both weights and directed nature of the graphs will come in handy. An adjacency list is an array A of separate lists. Each element of the array Ai is a list, which contains all the vertices that are adjacent to vertex i. We're defining it using 2 members, nodes and edges. Graph Class Structure Let's set up the graph class by defining our class and some methods ...
Read MoreBreadth-first search traversal in Javascript
BFS visits the neighbor vertices before visiting the child vertices, and a queue is used in the search process. Following is how a BFS works − Visit the adjacent unvisited vertex. Mark it as visited. Display it. Insert it in a queue. If no adjacent vertex is found, remove the first vertex from the queue. Repeat Rule 1 and Rule 2 until the queue is empty. How BFS Traversal Works Let us look at an illustration of how BFS Traversal works: ...
Read MoreThe Fibonacci sequence in Javascript
The Fibonacci sequence is a series of numbers where each number is the sum of the two preceding ones. The sequence starts with 1, 1 (or sometimes 0, 1). 1, 1, 2, 3, 5, 8, 13, 21, 34, ... Naive Recursive Approach The most straightforward way to generate the nth Fibonacci number uses recursion: function fibNaive(n) { if (n
Read MoreTopological sorting using Javascript DFS
A topological sort or topological ordering of a directed graph is a linear ordering of its vertices such that for every directed edge UV from vertex u to vertex v, u comes before v in the ordering. This only makes sense in directed acyclic graphs (DAGs). There are many places where topological sort makes a lot of sense. For example, let's say you're following a recipe, in this, there are some steps that are prerequisites for going to the next steps. Similarly, during college when selecting courses, there are prerequisites for more advanced courses which themselves may be prerequisites ...
Read MorePrim's algorithm in Javascript
Prim's algorithm is a greedy algorithm that finds a minimum spanning tree for a weighted undirected graph. It finds a subset of the edges that forms a tree that includes every vertex, where the total weight of all the edges in the tree is minimized. The algorithm operates by building this tree one vertex at a time, from an arbitrary starting vertex, at each step adding the cheapest possible connection from the tree to another vertex. How Prim's Algorithm Works Let us look at an illustration of how Prim's algorithm works: 1. Choose any arbitrary node ...
Read More