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 7 of 143
Binary Search Tree in Javascript
A Binary Search Tree (BST) is a specialized data structure where each node follows a specific ordering rule. A node's left child must have a value less than its parent's value, and the node's right child must have a value greater than its parent's value. 8 3 10 1 6 14 ...
Read MoreCircle Collision Detection HTML5 Canvas
Circle collision detection in HTML5 Canvas involves checking whether two circles intersect by calculating the distance between their centers and comparing it to the sum of their radii. How Circle Collision Detection Works Two circles collide when the distance between their centers is less than or equal to the sum of their radii. If the distance is greater, they don't collide. distance r1 r2 Basic Formula The collision detection formula uses the Pythagorean theorem to calculate distance: distance = Math.sqrt((x2 - x1)² + (y2 - y1)²) collision = distance
Read MoreCreating a BinaryTree using Javascript
A Binary Search Tree (BST) is a hierarchical data structure where each node has at most two children. Let's learn how to create and represent a binary search tree in JavaScript by building a complete BST class with essential operations. Basic Structure We'll start by creating the BinarySearchTree class and defining a Node class for individual tree elements. class BinarySearchTree { constructor() { // Initialize a root element to null this.root = null; ...
Read MoreSearching 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 More