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
Articles on Trending Technologies
Technical articles with clear explanations and examples
Python Program to Print only Nodes in Left SubTree
When it is required to print the nodes in the left subtree, a class can be created that consists of methods can be defined to set the root node, perform in order traversal, insert elements to the right of the root node, to the left of the root node, and so on. An instance of the class is created, and the methods can be used to perform the required operations.Below is a demonstration of the same −Exampleclass BinaryTree_struct: def __init__(self, data=None): self.key = data self.left = None self.right = None ...
Read MoreRemoving n characters from a string in alphabetical order in JavaScript
ProblemWe are required to write a JavaScript function that takes in a lowercase alphabet string and number num.Our function should remove num characters from the array in alphabetical order. It means we should first remove ‘a’ if they exist then ‘b’ , ‘c’ and so on until we hit the desired num.ExampleFollowing is the code −const str = 'abascus'; const num = 4; const removeAlphabetically = (str = '', num = '') => { const legend = "abcdefghijklmnopqrstuvwxyz"; for(let i = 0; i < legend.length; i+=1){ while(str.includes(legend[i]) && num > 0){ ...
Read MoreCreating permutations by changing case in JavaScript
ProblemWe are required to write a JavaScript function that takes in a string of characters, str, as the first and the only argument.Our function can transform every letter individually to be lowercase or uppercase to create another string. And we should return a list of all possible strings we could create.For example, if the input to the function isInputconst str = 'k1l2';Outputconst output = ["k1l2", "k1L2", "K1l2", "K1L2"];ExampleFollowing is the code −const str = 'k1l2'; const changeCase = function (S = '') { const res = [] const helper = (ind = 0, current = '') => { ...
Read MoreProgram to find out the lowest common ancestor of a binary tree using Python
Suppose, we are given a binary tree and also two specific nodes x and y. We have to find out the lowest common ancestor of the two nodes from the binary tree. The lowest common ancestor in a binary tree is the lowest node of which both the nodes x and y are descendants of. Also, a particular node can also be a descendant of itself. We have to find the node and return it as an output.So, if the input is likeand x = 2, y = 4; then the output will be 3.The node of which the nodes ...
Read MoreHow to use the require function in Lua programming?
Lua offers a high-level function which we can use when we want to load and run libraries. This high-level function is named require function.The require function mainly targets the high level functions and keywords.The require function is a bit similar to the dofile function, but it has two key differences, the first one being that it searches for the file in a specified path and the second one is that it mainly focuses on to control whether the file is already running on the script or not.Syntaxrequire “module-name” // some codeHow Does the require Function Work in Lua?It is mainly ...
Read MoreHow does the event pattern work in .NET?
Events are a simplified pattern that uses delegates. In C#, all delegates have the multicast capability, i.e., an instance of a delegate can represent not just a single method but a list of methods. For example −Exampledelegate int Transformer(int x); static void Main(){ Transformer perform = x =>{ int result = x * x; Console.WriteLine(result); return result; }; perform += x =>{ int result = x * x * x; Console.WriteLine(result); return result; }; perform(2); // prints ...
Read MoreProgram to find out the lowest common ancestor of a binary tree using parent pointers using Python
Suppose, we are given a binary tree and also two specific nodes x and y. We have to find out the lowest common ancestor of the two nodes from the binary tree. The lowest common ancestor in a binary tree is the lowest node of which both the nodes x and y are descendants. A particular node can also be a descendant of itself. We have to find the node and return it as an output.The node structure of the tree is like below −TreeNode: data: left: right: parent: We have to utilize ...
Read MoreHow to use the Time package in Lua programming?
Lua library provides us with a time package that can be used to calculate the current time and that current time can be converted into hours, days and minutes and we can also take the later values and turn them into a Lua representation of time.In order to make use of the library time package, we don’t necessarily need to require anything, we just need to write the following command in a Lua script and we are done.Lua code for printing the current time in Lua format −Exampleprint(os.time())Output1624642168The output of the above time command definitely isn’t something that we normally ...
Read MoreFinding the nth element of the lucas number sequence in JavaScript
Lucas NumbersLucas numbers are numbers in a sequence defined like this −L(0) = 2 L(1) = 1 L(n) = L(n-1) + L(n-2)ProblemWe are required to write a JavaScript function that takes in a number n and return the nth lucas number.ExampleFollowing is the code −const num = 21; const lucas = (num = 1) => { if (num === 0) return 2; if (num === 1) return 1; return lucas(num - 1) + lucas(num - 2); }; console.log(lucas(num));OutputFollowing is the console output −24476
Read MoreFinding value of a sequence for numbers in JavaScript
ProblemConsider the following sequence sum −$$seq(n,\:p)=\displaystyle\sum\limits_{k=0} \square(-1)^{k}\times\:p\:\times 4^{n-k}\:\times(\frac{2n-k}{k})$$We are required to write a JavaScript function that takes in the numbers n and p returns the value of seq(n, p).ExampleFollowing is the code −const n = 12; const p = 70; const findSeqSum = (n, p) => { let sum = 0; for(let k = 0; k
Read More