Question: We are given an input string, and we need to find the character with the maximum frequency. Input:- “This is an sample string.” Output:- The character with maximum frequency is :- i The logic of this problem is very simple, we need to scan the string and store the frequency of each of the character. For this we can use the ASCII code of the characters which is a separate integer. Note that character are not only the English alphabets. !@#$ are also characters. To extend our program to…
nikoo28
nikoo28
a tech-savvy guy and a design buff... I was born with the love for exploring and want to do my best to give back to the community. I also love taking photos with my phone to capture moments in my life. It's my pleasure to have you here.
-
-
This algorithm is one of the specific ones people generally have a problem to understand. We will try out best to simplify it and understand it.Basically quick sort comprises of these steps:- Choose a pivot element (it can be any random element in array) In one iteration keep all the numbers smaller to it on the left side and larger to it on the right side.(smaller numbers)_ _ _[PIVOT]_ _ _(larger numbers) Now we have the left sub-array of (small numbers) and the right sub-array (large numbers) Repeat steps 1…
-
Question: Write a program in C to reverse a string using recursion Input: Hello Everyone Output: enoyrevE olleH We will use the simple concept of recursion to print the string in reversed order. Note that, we will not store the reversed string in any variable, we are just printing the string in reversed order. Recursive function (reversePrint) takes string pointer (str) as input and calls itself with next location to passed pointer (str+1). Recursion continues this way, when pointer reaches ‘\0′, all functions accumulated in stack print char at passed…
-
Question: Write a program that changes the case of each character in a string. If its uppercase, convert it to lowercase and vice-versa. Input: ThE quiCK brOwN FOX jUMPs. Output: tHe QUIck BRoWn fox Jumps. In this program we shall apply the basic principle that each character is represented as an integer ASCII code. For more reference look into the post – Find the case of a character input by the user. Now we know that ‘a’ -> ASCII CODE = 97 ‘A’ -> ASCII CODE = 65 Thus the…
-
Strings
Write a program to find the case of a character entered from the keyboard.
by nikoo281 minutes readQuestion: Write a program that returns the case of the character? Input: e Output: lower case We shall use the concept of ASCII characters to determine the case of the character input by the user. The ASCII table can be found at this link. ASCII TABLE From this we can see the following ASCII codes:- CHARACTER ASCII CODE A 65 Z 90 a 97 z 122 Thus, to check the case we simply compare the ASCII codes. Since we are using C language, in C every character is considered as…
-
Merge Sort is one of the most popular methods of sorting an array and as offers a constant operating time of . And, as the name suggests it involves merging of several sorted arrays to combine and form a single sorted arrays in the end. The steps involved in merge sort are:- Divide the array in 2 parts left and right. Now recursively divide the left and right parts into more left and right sub parts. Keep doing step 2 , until the sub parts are no greater than a…
-
Question: We have 2 sorted arrays and we want to combine them into a single sorted array. Input: arr1[] = 1, 4, 6, 8, 13, 25 || arr2[] = 2, 7, 10, 11, 19, 50 Output: 1, 2, 4, 6, 7, 8, 10, 11, 13, 19, 50 One of the simplest ways to solve this problem would be to copy both the arrays into a new array and then apply some sorting technique on them. But this method will not utilize the fact that both the arrays are already sorted.…
-
Bubble sort is one of the simplest sorting algorithms and it works on the principle of swapping two elements. Think of the bubble sort as a water bubble that arises from the bottom of the ocean. As it rises up, it grows in size and its the maximum when it reaches the surface. Similarly, in bubble sort, we arrange items from smallest to the largest at the end one by one in each iteration.The algorithm for bubble sort is as follows:- We start from the bottom of the array and…
-
As the name suggests SELECTION SORT involves selecting an element. Now the question arises, as to how should we select this element. What is the criteria? Where should we put it? All these answers are given in the algorithm for SELECTION SORT. In selection sort, what we do is:- Start from the first position in the array. Traverse the remaining array to find the smallest number Swap this smallest number with the number we selected in the first place. Repeat steps 2 and 3 with the next position. Let us…
-
Insertion sort is the most generic example of a sorting algorithm, and the one which is used by one of the most naive users. Often we must have also used this algorithm in our real life examples unknowingly. One of the favorite example is:- This is a very common scenario and we must have used it. Suppose you get a hand of cards. Our general approach is that we start scanning the cards from starting and if we find a card out of place, we remove it from there and…