Found 26504 Articles for Server Side Programming

Swift Program to sort an array in ascending order using insertion sort

Ankita Saini
Updated on 10-May-2023 11:05:43

468 Views

In Swift, insertion sort is a sorting technique in which the given array is virtually divided into two parts that are the sorted and the unsorted part. Then the array is searched sequentially, compares two elements from the unsorted part, and moves them into the right place in the sorted part. Using insertion sort, we can easily sort the array elements in ascending or descending order. So in this article, we will learn how to sort an array in ascending order using insertion sort. Working of insertion sort Given unsorted array − To sort the array in ascending order, ... Read More

Swift Program to remove the last specified character from the string

Ankita Saini
Updated on 10-May-2023 13:43:58

512 Views

To remove the last specified character from the string Swift provide a pre-defined remove(at:) function. This function removes a character from the specified position or index. Input String = “Today is cloudy day” Character = “o” Output “Today is cludy day” Where character “o” appears two times in the input string so using the remove(at:) function we removed the last appearance of the “o” character from the string. Hence the output string is “Today is cludy day”. Syntax Str.remove(at:Idx) Where Str is the input string and idx is the valid position/index of the specified character to ... Read More

Swift Program to convert the string into an array of characters

Ankita Saini
Updated on 10-May-2023 13:42:05

3K+ Views

To convert the string into an array of characters Swift proved the following methods − Using Array() initialiser Using append() method Input String = “Cloudy day” Output Array = [“C”, “l”, “o”, “u”, “d”, “y”, “d”, “a”, “y”] Here we converted all the characters present in the input string into the array of characters. Method 1: Using Array() initialiser Swift supports an Array() initialiser which is used to convert the input string into an array of characters. Or we can say that Array() initialiser is used to create array objects. Here we use parametrised array. Syntax ... Read More

Swift Program to convert the string into an array of characters based on the specified character

Ankita Saini
Updated on 10-May-2023 09:33:31

239 Views

In Swift, convert the string into an array of characters based on the specified character using the split() function. The split() function splits the given string at the specified separator and returns the result in an array. Input String = “Today is cloudy day” Character = “y” Output [“toda”, “is cloud”, “da”] Here, the string is split at character “y” and converted the split string into an array. Syntax func.split(separator:Character, maxSplits Int, ommittingEmptySequence:Bool) The split function takes the following arguments − separator − It is an element at which the split operation happens. maxSplits − ... Read More

Array Range Queries to find the Maximum Armstrong number with updates

Tapas Kumar Ghosh
Updated on 10-May-2023 15:11:27

440 Views

The Array range queries are a new interest of data structure. In this query, we have set the random element to the array and given the general query problem to solve the data structure problem efficiently. Armstrong number is the total of its digits' cubes. For example- 0, 1, 153, 370, 371, and 407 are Armstrong numbers. Let’s take an example to understand the Armstrong number Example 1 − The given number is 371 and check whether the number is Armstrong or not. 3*3*3 + 7*7*7 + 1*1*1 = 371 Hence, this is Armstrong number. Example 2 − The given ... Read More

Count of element in an array whose set bits are in a multiple of K

Tapas Kumar Ghosh
Updated on 10-May-2023 15:39:16

353 Views

The set bit is a binary representation form of 0 and 1. This digit 1 is called a set bit in reference to the computer. Let’s take an example to understand the setbit calculation − Let’s take an example to understand the setbit calculation − The set bit calculation of integer 96 is Let’s say we want to set the bit to sum of 96. So as shown in the above representation, we will set bit 1 to those array elements whose total will be 96. This way we will form 2 sets of bit. Therefore, if we take ... Read More

Design a queue data structure to get minimum or maximum in O(1) time

Tapas Kumar Ghosh
Updated on 04-Jun-2025 17:48:39

932 Views

In data structure & algorithm, we have a deque header file that handles the properties of stack and queue. For getting minimum and maximum value from O(1) time complexity, we need constant time. So, deque is one of the possible advantages of using both stack and queue. O(1) Time Complexity The O(1) time complexity is also known as constant time which defines an algorithm for taking the same amount of time instead of using size input. Syntax The basic syntax of deque data structure is as follows: deque name_of_queue; Here, deque : It ... Read More

Check if given words are present in a string

Tapas Kumar Ghosh
Updated on 10-May-2023 14:20:57

966 Views

C++ has a predefined function find() which enables searching from the first element range until the last element. In this article, we are going to understand how we can use this find() function to check if a given word is present in a string or not. Let’s take an example of this. The given string is “John and mark have same color of t-shirt”; For searching the word in a string we will make a variable that is denoted as a search finder. Let’s take two variables and check if the given words are present or not. Var1 = ... Read More

Proof that the Dominant Set of a Graph is NP-Complete

Tapas Kumar Ghosh
Updated on 10-May-2023 14:15:12

582 Views

A Dominant set of a graph is NP-complete is the subset of vertices such that every vertex in the subset or adjacent vertex in the subset. The full form of NP is “Nondeterministic polynomial” which will check the problem in polynomial time and it means that we can check whether the solution is correct or not in polynomial time. The polynomial time has the best complexity to the code like the time complexity of linear search – n, Binary search – logn, Merge sort- n(log)n, etc. The NP-complete graph provides a good solution in a reasonable amount of time. This ... Read More

Find array sum using Bitwise OR after splitting given array in two halves after K circular shift

Tapas Kumar Ghosh
Updated on 10-May-2023 14:06:25

193 Views

In C++ splitting an array mean dividing the array into more than one subarray. The Bitwise OR is used to handle the comparison and calculation between two bits or indexes in C++. In this article, we use k circular shift which means the last index position will be shifted to zero index position i.e, the first array element according to k-th times. Let’s take an example to understand the circular shift into the array. The given array is 1, 2, 3, 4, 5, 6, 7 and has a length of 6. Now we will assign the value 3 to k ... Read More

Advertisements