Stable Sort for Descending Order

Vaishnavi Tripathi
Updated on 05-Oct-2023 11:55:41

311 Views

In this article, we will discuss what is meant by stable sorting and how can we sort an array in descending order keeping in mind that the sorting algorithm should be stable. Let us first discuss about what are the features of a stable sort algorithm − A sorting algorithm is called stable if it keeps the original order of items with the same value in the input data when they are sorted. So, if there are two or more items with the same value, a stable sorting algorithm will not change their relative positions in the sorted output. Stable ... Read More

Ropes Left After Every Removal of Smallest Rope

Vaishnavi Tripathi
Updated on 05-Oct-2023 11:49:33

188 Views

In this article, we will discuss two approaches to solve the problem - Ropes left after every removal of smallest rope. Problem Statement We are given an array of elements where array [i] denotes the length of the ith rope in the array. Our task is to cut a length equal to the smallest element of the array from all the elements of the array until we have all the elements length equal to zero. We have to output the number of ropes with non-zero lengths after each cut operation. Let us consider an example for the same − Let ... Read More

Minimum Sum of Multiplications of N Numbers

Vaishnavi Tripathi
Updated on 05-Oct-2023 11:46:23

167 Views

In this article, we will discuss two approaches to generate the desired sum. Both the approaches are dynamic programming-based approaches. In the first approach, we will memorization for dynamic programming and then we will apply the same approach for tabulation in order to avoid the use of extra stack space for recursion. Problem Statement We are given a list of n integers, and our goal is to minimize the sum of multiplications by repeatedly taking two adjacent numbers, summing them modulo 100, and replacing them in the list until only one number remains. Let's consider the input [30, 40, 50] ... Read More

Minimum Number of Subtract Operations to Make an Array Decreasing

Vaishnavi Tripathi
Updated on 05-Oct-2023 11:44:55

278 Views

In this article, we will work upon sorting an array in decreasing order by applying some subtraction operations on it. Problem Statement We are given an array containing a series of n numbers from array[0], array[1], . . . . , array[ n-1 ]. We are also given an integer nums. Our task is to generate a decreasing array by subtracting nums from the array elements in every operation. We need to return the least possible number of such operations required in order to make the array decreasing in order. Let us understand the problem with an example − ... Read More

Maximum in Array Which is at Least Twice of Other Elements

Vaishnavi Tripathi
Updated on 05-Oct-2023 11:42:11

149 Views

In this article, we will discuss different approaches to point out the greatest element in the array which is at least twice of all the other elements in the same array. Problem Statement An array of n different elements is given to us, we have to find out the maximum element in the given array "nums" such that it is either greater than or equal to twice of all the other elements in that array. In other words, we can also say the we have to find out whether or not all the other elements of the given array are ... Read More

Largest Number That Is Not a Perfect Square

Vaishnavi Tripathi
Updated on 05-Oct-2023 11:34:32

198 Views

In this article, we will discuss two different approaches to find out the largest number smaller than a given number which is not a perfect square. In the first approach, we will run a loop to check for every number until we find the desired number while in the second approach, we will use the concept of square root to generate the perfect square number just smaller than the given number and based on this, we will find out the largest number smaller than "nums" which is not a perfect square. Let us first understand the problem statement. Problem Statement ... Read More

K Smallest Elements in Same Order Using O(1) Extra Space

Vaishnavi Tripathi
Updated on 05-Oct-2023 11:32:10

137 Views

We have an array "nums" consisting of "size" elements and an integer "number" denoting the number of smallest elements we have to return. Our task is to find out the "number" smallest elements from the given array. The order of the elements should be preserved and we are not allowed to use any extra variable space for the solution i.e., the space complexity of the solution should be O(1). Let us understand this using an example, nums = { 4, 2, 6, 5, 1 } The solution should return 4, 2, 5 as they are the smallest 3 ... Read More

Read and Write Class Objects to File in C++

Sunidhi Bansal
Updated on 05-Oct-2023 01:10:37

39K+ Views

The iostream standard library has two methods cin, to accept input from standard input stream and cout to print output to the standard output stream. In this article we will learn how to read data from files into class objects and how to write data in class objects to files.Reading and writing data to and from files requires another standard library of C++ . The three main data types of fstream are −ifstream − represents input file stream and reads information from files.ofstream − represents output file stream and writes information to files.fstream − represents general file stream and has ... Read More

Select Rows Where Column Contains String in MySQL

Ankith Reddy
Updated on 05-Oct-2023 01:06:33

40K+ Views

To select the row value containing string in MySQL, use the following syntax.SELECT *FROM yourTableName where yourColumnName like ‘%yourPattern%’;To understand the above syntax, let us first create a table. The query to create a table is as follows.mysql> create table PatternDemo -> ( -> Id int, -> Name varchar(100), -> Age int -> ); Query OK, 0 rows affected (0.97 sec)Insert records in the table using insert command. The query is as follows.mysql> insert into PatternDemo values(1, 'James', 23); Query OK, 1 row affected (0.11 sec) mysql> insert into PatternDemo values(2, 'Joseph', 21); Query OK, 1 row affected (0.18 ... Read More

Abstract Data Type in Data Structures

Arnab Chakraborty
Updated on 05-Oct-2023 01:03:30

37K+ Views

The Data Type is basically a type of data that can be used in different computer program. It signifies the type like integer, float etc, the space like integer will take 4-bytes, character will take 1-byte of space etc.The abstract datatype is special kind of datatype, whose behavior is defined by a set of values and set of operations. The keyword “Abstract” is used as we can use these datatypes, we can perform different operations. But how those operations are working that is totally hidden from the user. The ADT is made of with primitive datatypes, but operation logics are ... Read More

Advertisements