Found 26504 Articles for Server Side Programming

How to search in a row wise and column wise increased matrix using C#?

Nizamuddin Siddiqui
Updated on 17-Aug-2021 06:46:07

251 Views

The primitive solution for this problem is to scan all elements stored in the input matrix to search for the given key. This linear search approach costs O(MN) time if the size of the matrix is MxN.The matrix can be viewed as a sorted one-dimensional array. If all rows in the input matrix are concatenated in top-down order, it forms a sorted one-dimensional array. And, in that case binary search algorithm is suitable for this 2D array. The below piece of code develops a function SearchRowwiseColumnWiseMatrix that takes a two-dimensional array and search key as input and returns either true ... Read More

How to check whether the given matrix is a Toeplitz matrix using C#?

Nizamuddin Siddiqui
Updated on 17-Aug-2021 06:39:33

681 Views

A matrix is Toeplitz if every diagonal from top-left to bottom-right has the same elements.Example 1[[1, 2, 3, 4], [5, 1, 2, 3], [9, 5, 1, 2]]Output −trueIn the above grid, the diagonals are −"[9]", "[5, 5]", "[1, 1, 1]", "[2, 2, 2]", "[3, 3]", "[4]".In each diagonal all elements are the same, so the answer is True.Example 2Input: matrix [[1, 2], [2, 2]]Output −falseThe diagonal "[1, 2]" has different elementsCodepublic class Matrix    {    public bool ToeplitzMatrix(int[, ] mat)    {       int row = getMatrixRowSize(mat);       int col = getMatrixColSize(mat);       ... Read More

Node.js – Base64 Encoding & Decoding

Mayank Agarwal
Updated on 16-Aug-2021 12:18:20

7K+ Views

The buffer object can be encoded and decoded into Base64 string. The buffer class can be used to encode a string into a series of bytes. The Buffer.from() method takes a string as an input and converts it into Base64.The converted bytes can be changed again into String. The toString() method is used for converting the Base64 buffer back into the string format.SyntaxBuffer.from(string, [encoding]) object.toString(encoding)ParametersThe parameters are described below:string − This input parameter takes input for the string that will be encoded into the base64 format.encoding − This input parameter takes input for the encoding in which string will be encoded and ... Read More

Node.js – util.format() method

Mayank Agarwal
Updated on 16-Aug-2021 12:14:39

2K+ Views

The util.format() method returns a formatted string that will use the first argument as a printf like format string. This format can also contain zero or more format specifiers. These specifiers can be replaced with the converted value from the corresponding argument.Following are some of the formatted specifiers:%s − String will be used to convert all values except bigInt, object and -0.%d − In this case, number will be used to convert all values except BigInt and symbo%i − parseInt(value, 10) will be used for all values except BigInt and symbol.%f − parseFloat(value) will be used for all values except Symbol%j − This format ... Read More

Node.js – util.callbackify() Method

Mayank Agarwal
Updated on 16-Aug-2021 12:12:32

596 Views

The util.callbackify() method takes an async function as a parameter (or a function with Promise) and returns a function with the callback style. The callback will hold the rejection reason as the first parameter (or null in case of Promise) and the resolved value as the second parameter.Syntaxutil.callbackify(function)Parametersfunction − The input parameter for the async_function required for callback.Example 1Create a file "callbackify.js" and copy the following code snippet. After creating the file, use the command "node callbackify.js" to run this code.// util.callbackify() demo example // Importing the util module const util = require('util'); // Defining a simple async function ... Read More

Node.js – hmac.digest() Method

Mayank Agarwal
Updated on 16-Aug-2021 12:10:41

1K+ Views

The Hmac class is one of the many utility classes that is used for creating the cryptographic HMAC digests. The Hmac.digest() method is used for calculating all the data that is updated using the Hmac.update() method. If encoding is provided, a string will be returned, else a buffer is returned.Syntaxhmac.digest( [encoding] )Parametersencoding − This input parameter takes input for the encoding to be considered while calculating hmac.Example 1Create a file "hmacDigest.js" and copy the following code snippet. After creating the file use, use the command "node hmacDigest.js" to run this code. Live Demo// Hmac.digest() Demo Example // Importing the crypto module ... Read More

Node.js – hash.copy() Method

Mayank Agarwal
Updated on 16-Aug-2021 12:08:01

306 Views

The Hash class is one of the many utility classes that is used for creating the hash digests of data. The hash.copy() method creates a new Hash object that will contain a deep copy of the internal state of the current hash object.Syntaxhash.copy([options])Parametersoptions −This input parameter takes input to control the stream behaviour and therefore will contain the stream.tranformOptions.Example 1Create a file "hashCopy.js" and copy the following code snippet. After creating the file, use the command "node hashCopy.js" to run this code.// hash.update() demo Example // Importing the crypto module const crypto = require('crypto'); // Defining the hash ... Read More

Node.js – util.inherits() Method

Mayank Agarwal
Updated on 16-Aug-2021 12:04:46

558 Views

The util.inherits() method basically inherits the methods from one construct to another. This prototype will be set to a new object to that from the superConstructor.By doing this, we can mainly add some validations to the top of Object.setPrototypeOf(constructor.prototype, superConstructor.prototype).Syntaxutil.inherits(constructor, superConstructor)ParametersThe parameters are described below -constructor − This is a function type input that holds the prototype for constructor the user wants to be inherited.superConstructor − This is the function that will be used for adding and validating the input validations.Example 1Create a file "inherits.js" and copy the following code snippet. After creating the file, use the command "node inherits.js" to run ... Read More

Node.js – util.inspect() method

Mayank Agarwal
Updated on 16-Aug-2021 12:01:15

1K+ Views

The util.inspect() method returns the string representation of the objects that are intended for the debugging process.Syntaxutil.inspect(object, [showHidden], [depth], [colors])ParametersThe parameters are defined as below:object − A JavaScript primitive type or an object is given as input.optionsshowHidden − This is set as false by default. If true, this option includes the non-enumerable symbols and properties that are included in the formatted result. WeakMap and WeakSet are also included.depth − It specifies the number of recursions to be applied while formatting objects.colors − The output is set styled with ANSI color codes if this value is set to true. Colors passed are customizable.customInspect − The ... Read More

Timing features in Node.js

Mayank Agarwal
Updated on 16-Aug-2021 11:57:15

659 Views

The timer module in Node.js consists of different functions that can control and alter the timings of code execution. In this article, we will see how to use some of these functions.setTimeout() MethodThe setTimeout() method schedules the code execution after a designated amount of milliseconds. Only after the timeout has occurred, the code will be executed. The specified function will be executed only once. This method returns an ID that can be used in clearTimeout() method.SyntaxsetTimeout(function, delay, [args])ParametersThe parameters are defined below:function − This parameter takes input for the function that will be executed.delay − This is the time duration after which ... Read More

Advertisements