Server Side Programming Articles - Page 2137 of 2651

Apothem of a n-sided regular polygon in C++

sudhir sharma
Updated on 24-Oct-2019 08:17:10

261 Views

n-sided regular polygon is a closed figure of n sides that has all sides and angles of equal length. The below figure shows a 6 sided regular polygon commonly known as hexagon.Apothem is a line in the polygon that connects the center of the figure to the side. And it is perpendicular to one of its sides that makes it smallest in length.Now, let drive the formula for its length.The angle made by the side of an n sided polygon is 360/n.Now, as in the figure, the angle is equal to (360 / n )/2 = 180 /nNow taking the ... Read More

An Uncommon representation of array elements in C++ program

Farhan Muhamed
Updated on 09-Jun-2025 19:09:03

161 Views

In this article, we will learn an uncommon representation of array elements in both C and C++. Example of Uncommon Representation of Array Elements Consider following code in C/C++, that is trying to print an element from an array. C C++ #include int main() { int arr[2] = {0,1}; printf("First Element = %d",0[arr]); } Output The output of above program will be: First Element = 0 #include using namespace std; int main() { int arr[2] = {0,1}; cout

An interesting time complexity question in C++

sudhir sharma
Updated on 24-Oct-2019 08:09:38

1K+ Views

Time complexity can be defined as the time required by the algorithm to run its average case.Let's see and calculate the time complexity of some of the basic functions.Methodvoid counter(int n){    for(int i = 0 ; i < n ; i++){       for(int j = 1 ; j

An interesting method to print reverse of a linked list in C++

sudhir sharma
Updated on 24-Oct-2019 08:05:25

170 Views

A linked list is a data structure that stores data elements in linked form. Each node of the linked list has a data element and a link.Print reverse of a linked list is a common problem that needs to be addressed in problem solving. So, here we will learn an interesting way to print reverse of a linked list in c++ programming language.Generally print a reverse linked list needs modifications in the list or multiple traversing of the list but this method does not require any such things and also traverses the linked list only once.The logic of this method ... Read More

An Insertion Sort time complexity question in C++

sudhir sharma
Updated on 24-Oct-2019 08:01:24

1K+ Views

What is the time complexity of insertion sort?Time complexity is the amount of time taken by a set of codes or algorithms to process or run as a function of the amount of input.For insertion sort, the time complexity is of the order O(n) i.e. big O of n in best case scenario. And in the average or worst case scenario the complexity is of the order O(n2).What will be the time complexity of sorting when insertion sort algorithm is applied to n sized array of the following form: 6, 5, 8, 7, 10, 9 …… I, i-1The time complexity ... Read More

Amortized analysis for increment in counter in C++

sudhir sharma
Updated on 24-Oct-2019 07:54:31

628 Views

Amortized analysis for a sequence of operations is used to determine the run time, the average time required by the sequence. In cannot be treated as an average-case analysis done on the algorithm as it does not always take the average case scenario. There are cases that occur as a worst-case scenario of analysis. So, amortized analysis can be treated as a worst-case analysis for multiple operations in a sequence. Here, the cost of doing each operations in different and for some its high. This problem is a general view using the binary counter.Let’s see the working and implementation in ... Read More

Amazing hacks of Python

sudhir sharma
Updated on 14-Jul-2025 15:42:30

226 Views

Python is one of the programming languages known for its simple syntax, readability. Whether working on development, data analysis, or automation, Python provides the tools to get the task done with less effort. But beyond the basics, Python has some hacks that make the code not only shorter but also more efficient. These are not bugs or workarounds, but the smart ways of using the Python built-in features and functions to solve tasks in a faster manner. In this article, we are going to learn about the amazing hacks of Python. Performing a Swap Without a ... Read More

Minimum and Maximum number of pairs in m teams of n people in C++

Arnab Chakraborty
Updated on 23-Oct-2019 09:15:43

305 Views

Problem statementN participants of the competition were split into M teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends.Your task is to write a program that will find the minimum and the maximum number of pairs of friends that could have formed by the end of the competition.Algorithm1. We can obtain max pairs using below formula: maxPairs = ((n – m) * (n – m + 1)) / 2 2. We can obtain min pairs using below formula: minPairs = m * (((n ... Read More

Minimizing array sum by applying XOR operation on all elements of the array in C++

Arnab Chakraborty
Updated on 23-Oct-2019 09:11:59

229 Views

DescriptionGiven an array of size, N. Find an element X such that the sum of array elements should be minimum when XOR operation is performed with X and each element of an array.If input array is: arr [] = {8, 5, 7, 6, 9} then minimum sum will be 30 Binary representation of array elments are: 8 : 1000 5 : 0101 7 : 0111 6 : 0101 9 : 1001 If X = 5 then after performing XOR sum will be 30: 8 ^ 5 = 13 5 ^ 5 = 0 7 ^ 5 = 2 6 ^ ... Read More

Find all the patterns of “1(0+)1” in a given string using Python Regex

Pradeep Elance
Updated on 23-Oct-2019 08:22:30

259 Views

In this tutorial, we are going to write a program which finds all the occurrences of the 1(0+1) in a string using the regexes. We have a re module in Python which helps us to work with the regular expressions.Let's see one sample case.Input: string = "Sample 1(0+)1 string with 1(0+)1 unnecessary patterns 1(0+)1" Output: Total number of pattern maches are 3 ['1(0+)1', '1(0+)1', '1(0+)1']Follow the below steps to write the code for the program.Algorithm1. Import the re module. 2. Initialise a string. 3. Create a regex object using regular expression which matches the pattern using the re.compile(). Remember to ... Read More

Advertisements