Programming Articles - Page 1954 of 3366

Count number of binary strings of length N having only 0’s and 1’s in C++

Sunidhi Bansal
Updated on 15-May-2020 12:50:50

522 Views

We are given a number let’s say, num and the task is to calculate the count of binary strings that can be formed through the given number num containing only o’s and 1’s.Binary Number System is one the type of Number Representation techniques. It is most popular and used in digital systems. Binary system is used for representing binary quantities which can be represented by any device that has only two operating states or possible conditions. For example, a switch has only two states: open or close.In the Binary System, there are only two symbols or possible digit values, i.e., ... Read More

Count full nodes in a Binary tree (Iterative and Recursive) in C++

Sunidhi Bansal
Updated on 15-May-2020 12:48:59

1K+ Views

We are given a binary tree and the task is to calculate the count of full nodes available in a binary tree using iterative and recursive approach. Full nodes are those nodes who have both the children and no child is null. Note that in full nodes we consider nodes with exactly two children.Binary Tree is a special data structure used for data storage purposes. A binary tree has a special condition that each node can have a maximum of two children. A binary tree has the benefits of both an ordered array and a linked list as search is ... Read More

Count half nodes in a Binary tree (Iterative and Recursive) in C++

Sunidhi Bansal
Updated on 15-May-2020 12:43:29

465 Views

We are given a binary tree and the task is to calculate the count of half nodes available in a binary tree using iterative and recursive approach. Half nodes are those nodes who have only one child and another child is null. Note that in half nodes we don't consider leaf nodes.Binary Tree is a special data structure used for data storage purposes. A binary tree has a special condition that each node can have a maximum of two children. A binary tree has the benefits of both an ordered array and a linked list as search is as quick ... Read More

Count elements in a vector that match a target value or condition in C++

Sunidhi Bansal
Updated on 15-May-2020 12:23:16

631 Views

We are given a vector and the task is to calculate the count of those elements in a vector that matches a target value or condition.Vectors are sequence containers that can change size. Container is an object that holds data of the same type. Sequence containers store elements strictly in linear sequence.Vector stores elements in contiguous memory locations and enables direct access to any element using subscript operator []. Unlike arrays, vectors can shrink or expand as needed at run time. The storage of the vector is handled automatically.To support shrink and expand functionality at runtime, vector containers may allocate ... Read More

Count consonants in a string (Iterative and recursive methods) in C++

Sunidhi Bansal
Updated on 15-May-2020 12:21:38

725 Views

We are given a string with let’s say str of any length and the task is to calculate the count of consonants in the given string using both iterative and recursive methods.Consonants are those alphabets that are not vowel i.e alphabets except a, i, e, o, u are considered as consonants. So in the program below we need to find the count of alphabets other than these in string.The Recursion and Iteration both repeatedly execute the set of instructions. Recursion is when a statement in a function calls itself repeatedly. The iteration is when a loop repeatedly executes until the ... Read More

Count common subsequence in two strings in C++

Sunidhi Bansal
Updated on 15-May-2020 12:19:02

616 Views

We are given two strings, let's say str1 and str2 containing characters and the task is to calculate the common subsequences in both the strings. In the below program we are using dynamic programming and for that we need to know what dynamic programming is and at what problems it can be used.Dynamic programming approach is similar to divide and conquer in breaking down the problem into smaller and yet smaller possible sub-problems. But unlike, divide and conquer, these subproblems are not solved independently. Rather, results of these smaller subproblems are remembered and used for similar or overlapping sub-problems.Dynamic programming ... Read More

Count changes in Led Lights to display digits one by one in C++

Sunidhi Bansal
Updated on 15-May-2020 12:16:03

323 Views

We are given a positive number let’s say num and the task is to calculate the count of changes in the Led lights displayed one by one. We will assume that initially all LEDs are off and they will be started based upon the string value.For solving this question we need to understand what a seven segment display is and its working.What are Seven Segment DisplaysSeven segment displays are the output display device that provide a way to display information in the form of image or text or decimal numbers which is an alternative to the more complex dot matrix ... Read More

Count number of digits after decimal on dividing a number in C++

Sunidhi Bansal
Updated on 15-May-2020 12:13:39

587 Views

We are given two integer numbers let’s say num1 and num2 and the task is to divide the num1 with num2 and calculate the count of digits after decimal on dividing these given numbers.For ExampleInput − num1 = 2, num2 = 5 Output − count is 1Explanation − when we divide 2 with 5 i.e. ? = 0.4, so digits after decimal is 1 therefore count is 1.Input − num1 = 2, num2 = 0 Output − Floating point exception (core dumped)Explanation − when we divide any number with 0 it will return an error and terminate the program abnormally.Input ... Read More

Count BST nodes that lie in a given range in C++

Sunidhi Bansal
Updated on 15-May-2020 12:11:37

280 Views

We are given a binary search tree made up of nodes and also a range and the task is to calculate the count of nodes that lies in the given range and display the result.A Binary Search Tree (BST) is a tree in which all the nodes follow the below-mentioned properties −The left subtree of a node has a key less than or equal to its parent node's key.The right subtree of a node has a key greater than to its parent node's key.Thus, BST divides all its sub-trees into two segments; the left subtree and the right subtree and ... Read More

Count maximum elements of an array whose absolute difference does not exceed K in C++

Sunidhi Bansal
Updated on 15-May-2020 12:06:27

570 Views

We are given an array let’s say, arr[] of integer elements of any given size and a positive integer k and the task is to calculate the count of those element pairs whose absolute difference doesn’t exceed the given integer k.Arrays a kind of data structure that can store a fixed-size sequential collection of elements of the same type. An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type.For exampleInput − int arr[] = {2, 3, 6, 12, 14}, k= ... Read More

Advertisements