Found 33676 Articles for Programming

C++ program to remove Nodes that Don't Lie in Any Path With Sum>=k

Prateek Jangid
Updated on 10-Aug-2022 07:27:18

192 Views

In this problem, we have a binary tree with a path from the root node to the leaf node that is completely defined. The sum of all nodes from the root node to the leaf node must be greater than or equal to, a constant value, k. So we need to remove all nodes in those paths whose sum is less than k, such that the only paths left in the tree will be greater than k. An important thing to remember here is that a node may be a part of many paths, so only remove such nodes if ... Read More

How to Perform Numpy Broadcasting using Python using dynamic arrays?

Vikram Chiluka
Updated on 17-Aug-2022 12:17:09

328 Views

"Broadcasting” refers to how NumPy handles arrays of different dimensions during arithmetic operations. The smaller array is "broadcast" across the larger array, subject to certain limits, to ensure that their shapes are consistent. Broadcasting allows you to vectorize array operations, allowing you to loop in C rather than Python." This is accomplished without the need for unnecessary data copies, resulting in efficient algorithm implementations. In some cases, broadcasting is a negative idea since it results in wasteful memory utilization, which slows down the computation. In this article, we will show you how to perform broadcasting with NumPy arrays using python. ... Read More

How to create Correlation Matrix in Python by traversing through each line?

Vikram Chiluka
Updated on 10-Aug-2022 09:29:47

3K+ Views

A correlation matrix is a table containing correlation coefficients for many variables. Each cell in the table represents the correlation between two variables. The value might range between -1 and 1. A correlation matrix is used for summarizing the data, diagnose the advanced analysis, and as an input for a more complicated study. Correlation matrix is used to represent the relationship between the variables in the data set. It is a type of matrix that helps programmers analyze the relationship between data components. It represents the correlation coefficient between 0 and 1. A positive value implies a good correlation, a ... Read More

Swift Program to Print the ASCII values

Ankita Saini
Updated on 05-Aug-2022 08:54:08

3K+ Views

This tutorial will discuss how to write a Swift program to print the ASCII values. ASCII is known as American Standard Code for Information Interchange. In electronic communication, it is a character encoding standard to represent text in the computer and other devices. It generally has 128 standard ASCII codes including every upper case, lowercase alphabets, digits starting from 0-9 and symbols, etc., and assign each character a unique code. Below is a demonstration of the same − Suppose we enter the following input − Value = A Following is the desired output − ASCII value is 65 ... Read More

Swift Program to Get Input from the User

Ankita Saini
Updated on 05-Aug-2022 08:50:42

11K+ Views

Getting input from the user in Swift is very easy with the help of the readLine() function. This function returns a string of characters which is read from the standard input at the end of the current line. If the control is already reached the EOF when the readLine() function is called then this method will return nil. Syntax Following is the syntax of Swift readLine() function − readLine(strippingNewline: true) Or readLine() Reading integer Example The following program shows how to get input from the user. import Foundation import Glibc print("Please enter number 1") var num1 = ... Read More

Swift Program to Display Alphabets (A to Z) using loop

Ankita Saini
Updated on 05-Aug-2022 08:40:12

1K+ Views

This tutorial will discuss how to write a Swift program to display alphabets (A to Z) using loop. In Swift, we can display alphabets starting from A to Z in both lower and upper case with the help of for-loop. Here we use the following terms in the below codes − Scalar − It represents a single value. Unicode − It is a standard encoding for text. UnicodeScalar − It represents a single Unicode scalar value. Below is a demonstration of the same − Suppose we enter the following input − A to Z Following is the desired output ... Read More

Swift Program to Display All Prime Numbers from 1 to N

Ankita Saini
Updated on 05-Aug-2022 08:34:45

5K+ Views

This tutorial will discuss how to write a Swift program to display all prime numbers from 1 to N. Prime numbers are those numbers that are greater than 1 and has exactly two factors that is 1 and the number itself. For example, 2 is the prime number because it has only two factors that are 1 and 2. Below is a demonstration of the same − Suppose we enter the following input − Range - 1 to 20 Following is the desired output − Prime numbers between 1 to 20 are - 2, 3, 5, 7, 11, ... Read More

Swift Program to Check if two of three boolean variables are true

Ankita Saini
Updated on 05-Aug-2022 08:28:16

507 Views

This tutorial will discuss how to write a Swift program to check if two of three boolean variables are true. Given three boolean values now we have to check if two of the boolean variables are true or not. Boolean variables are those variables that either contain true or false. We can also use this program to check, out of given three conditions two are true or not. Below is a demonstration of the same − Suppose we enter the following input − Value1 = true Value2 = true Value3 = false Following is the desired output − Two of ... Read More

Swift Program to Display Fibonacci Series

Ankita Saini
Updated on 05-Aug-2022 08:24:24

7K+ Views

Fibonacci sequence is a sequence of numbers in which every number is the sum of the preceding two numbers and the starting number of this sequence are 0 and 1. So the general Fibonacci series is − 0, 1, 1, 2, 3, 5, 8, 13, 21, ...... Formula Following is the formula of Fibonacci series − Fn = Fn-1 + Fn-2 Below is a demonstration of the same − Suppose we enter the following input − Number = 5 Following is the desired output − Fibonacci Series is- 0, 1, 1, 2, 3 We can find the ... Read More

Swift Program to Count Number of Digits in an Integer

Ankita Saini
Updated on 05-Aug-2022 08:08:16

3K+ Views

This tutorial will discuss how to write a Swift program to count the number of digits in an integer. Below is a demonstration of the same − Suppose we enter the following input − Number = 3454634 Following is the desired output − Total count is 7 We can count the number of digits using the following methods − Iterative method Recursion method Iterative Method We can calculate the total digits present in the given integer with the help of loops like if, while loop, etc. It is the easiest and cheapest method. Algorithm The algorithm ... Read More

Advertisements