C/C++ Program for Greedy Algorithm to find Minimum number of Coins

sudhir sharma
Updated on 19-Sep-2019 08:02:59

5K+ Views

A greedy algorithm is an algorithm used to find an optimal solution for the given problem. greedy algorithm works by finding locally optimal solutions ( optimal solution for a part of the problem) of each part so show the Global optimal solution could be found.In this problem, we will use a greedy algorithm to find the minimum number of coins/ notes that could makeup to the given sum. For this we will take under consideration all the valid coins or notes i.e. denominations of { 1, 2, 5, 10, 20, 50 , 100, 200 , 500 ,2000 }. And we ... Read More

C++ vs C#

sudhir sharma
Updated on 19-Sep-2019 07:57:35

175 Views

C++ Programming languageA successor of the c programming language that has introduced the concept of classes and objects. It encapsulates features of c and high-level language hence it can be treated as an intermediate-level language. When it was created it was thought of as a C that has classes because of its similarities with C.C# Programming LanguageC# (also known as C sharp) is a general-purpose programming language that was developed by Microsoft to run on .net framework for developing applications for its operating system. It is an object-oriented programming language with features like object-oriented, statically typed, decorative, multiparadigm programming language.Both ... Read More

C++ program to print unique words in a file

sudhir sharma
Updated on 19-Sep-2019 07:39:36

419 Views

A file is a memory location that stores word streams. In a file, there are various words. In this program, we will find all unique words from the file and print them.A unique word means the number of occurrences of the word is one in the file.For example, Tutorials point is best for programming tutorials.Here, the word tutorial occurs more than once, hence it is not unique. Rest all words are unique.AlgorithmTo check for unique words in the given file. Using iterator with two variables : data and occurence. Input : File Step 1 : Read each line from the ... Read More

Name some of the string methods in javascript?

Ayush Gupta
Updated on 19-Sep-2019 07:37:38

147 Views

The String object lets you work with a series of characters; it wraps Javascript's string primitive data type with a number of helper methods. As JavaScript automatically converts between string primitives and String objects, you can call any of the helper methods of the String object on a string primitive.Following are some of the methods available for strings in JavaScript −concat() −Combines the text of two strings and returns a new string.indexOf() −Returns the index within the calling String object of the first occurrence of the specified value, or -1 if not found.lastIndexOf() −Returns the index within the calling String ... Read More

C++ Program to print current Day, Date and Time

sudhir sharma
Updated on 19-Sep-2019 07:35:01

2K+ Views

Current day, date and time are all calendar dates that are printed on screen. In c++, the ctime library contains all the methods and variables related to date and time.You can also check current date and time details using the ctime library which contains methods to display time. The following methods are used to display details of date and time −time() − The time() method is used to find the current time. The return time of the time() method is time_t. time_t is the data type that can store time.localtime() − To convert the time_t type variables to a variable ... Read More

Write the usage of split() method in javascript?

Ayush Gupta
Updated on 19-Sep-2019 07:33:18

161 Views

The split([separator, [limit]]) method splits a String object into an array of strings by separating the string into substrings, using a specified separator string to determine where to make each split.Example usage of split methodlet a = "hello, hi, bonjour, namaste"; let greetings = a.split(', '); console.log(greetings)Output[ 'hello', 'hi', 'bonjour', 'namaste' ]Note that the commas were removed here. Any separator provided will be removed.If separator is an empty string, str is converted to an array having one element for each character of str.Examplelet a = "hello"; console.log(a.split(""))Output[ 'h', 'e', 'l', 'l', 'o' ]If no separator is provided, the string is ... Read More

C++ program to find the type of the given iterator

sudhir sharma
Updated on 19-Sep-2019 07:30:27

139 Views

An iterator is an object just like a pointer that is used to iterate over elements of a container. The main advantage of using an iterator is to create a common interface and make the algorithm immune from the type of container used to implement it.In C++ standard library there are Types of iterators −Forward iteratorBidirectional iteratorInput iteratorOutput iteratorRandom Access iteratorThe program is to check which of the above iterators are used by the data structure.There are a few factors that can be useful for determining the type of iterator used.typeid, returns the type identification information at runtime.iterator traits, defines ... Read More

C++ program for Sorting Dates using Selection Sort

sudhir sharma
Updated on 19-Sep-2019 07:27:31

744 Views

Date is number day, month and year. There are various ways to display a date.Here, we have a program to sort dates using selection sort. So let's learn about things that are used in this concept.Sorting datesThe concept of sorting dates needs a clear and well-versed knowledge of dates and their validations. Before we try sorting technique we need to check if the date inputted by the user is a valid date of not like 29-2 is only valid for leap years.After validation of dates comes the sorting of dates. For sorting, we will go in reverse order sorting years ... Read More

C++ Program for Longest Common Subsequence

sudhir sharma
Updated on 19-Sep-2019 07:16:44

2K+ Views

A subsequence is a sequence with the same order of the set of elements. For the sequence “stuv”, the subsequences are “stu”, “tuv”, “suv”, .... etc.For a string of length n, there can be 2n ways to create subsequence from the string.ExampleThe longest common subsequence for the strings “ ABCDGH ” and “ AEDFHR ” is of length 3. Live Demo#include #include using namespace std; int max(int a, int b); int lcs(char* X, char* Y, int m, int n){    if (m == 0 || n == 0)       return 0;    if (X[m - 1] == ... Read More

How to convert a string to camel case in JavaScript?

Ayush Gupta
Updated on 19-Sep-2019 07:15:02

1K+ Views

Camel case is the practice of writing phrases such that each word or abbreviation in the middle of the phrase begins with a capital letter, with no intervening spaces or punctuation. For example, Concurrent hash maps in camel case would be written as −ConcurrentHashMapsWe can implement a method to accept a string in JavaScript to convert it to camel case in the following way −Examplefunction camelize(str) {    // Split the string at all space characters    return str.split(' ')       // get rid of any extra spaces using trim       .map(a => a.trim())     ... Read More

Advertisements