Found 7347 Articles for C++

Binary representation of previous number in C++

sudhir sharma
Updated on 09-Jul-2020 11:40:57

230 Views

In this problem, we are given the binary representation of a number and we have to find the binary representation of the previous number i.e. the number that is resulted after subtracting one from the given number.Binary representation of a number is changing the base of the number to base 2 and representing the number using only 0 or 1.For example, Binary representation of 23 is 10111.So, here we would be given a number, let's say n in binary form. And we have to find the binary representation of n-1.To solve this problem, we need to know the basics of ... Read More

Binary representation of next number in C++

sudhir sharma
Updated on 22-Nov-2019 09:05:48

429 Views

In this problem, we are given the binary representation of a number and we have to find the binary representation of the next number i.e. the number that is resulted after adding one to the given number.Binary representation of a number is changing the base of the number to base 2 and representing the number using only 0 or 1.For example, Binary representation of 14 is 1110.So, here we would be given a number, let's say n in binary form. And we have to find the binary representation of n+1.To solve this problem, we need to know the basics of ... Read More

Binary Insertion Sort in C++

sudhir sharma
Updated on 22-Nov-2019 09:02:40

3K+ Views

Binary Insertion sort is a special type up of Insertion sort which uses binary search algorithm to find out the correct position of the inserted element in the array.Insertion sort is sorting technique that works by finding the correct position of the element in the array and then inserting it into its correct position.Binary search is searching technique that works by finding the middle of the array for finding the element.As the complexity of binary search is of logarithmic order, the searching algorithm’s time complexity will also decrease to of logarithmic order.Implementation of binary Insertion sort. this program is a ... Read More

Biggest number by arranging numbers in certain order in C++

sudhir sharma
Updated on 22-Nov-2019 07:45:31

125 Views

In this problem, we are given an array of numbers and we have to find the largest value that can be made by changing them in a certain way. the condition for the arrangement is, the order of even numbers and odd numbers shall remain the same i.e. the order of all even numbers cannot be changed.let's take an example to understand the concept better, Input : {17, 80, 99, 27, 14 , 22} Output: 801799271422 Explanation: the order of Even and Odd numbers is : Even : 80 14 22 Odd : 17 99 27Here 99 is the biggest ... Read More

BFS for Disconnected Graph in C++

sudhir sharma
Updated on 22-Nov-2019 07:37:46

747 Views

Disconnected graph is a Graph in which one or more nodes are not the endpoints of the graph i.e. they are not connected.A disconnected graph…Now, the Simple BFS is applicable only when the graph is connected i.e. all vertices of the graph are accessible from one node of the graph. in the above disconnected graph technique is not possible as a few laws are not accessible so the following changed program would be better for performing breadth first search in a disconnected graph.Example#include using namespace std; void insertnode(vector adj[], int u, int v) {    adj[u].push_back(v); } void breathFirstSearch(int u, ... Read More

Best meeting point in 2D binary array in C++

sudhir sharma
Updated on 22-Nov-2019 07:32:49

125 Views

In this problem, we are given a 2D binary array i.e. it has values that are either 0 or 1, where 1 is marked as a home of a person of the group. And people of the group want to meet. So, they need to minimise the total distance travelled by them for meeting at a common point. A valid meeting point can be anywhere but not at anyone home.For find minimum distance a formula is created, this is named as manhattan distance, where distance −(p1, p2) = |p2.x| + |p2.y - p1.y|.Let’s take an example, to make the concept ... Read More

Best First Search (Informed Search)

sudhir sharma
Updated on 22-Nov-2019 07:29:28

6K+ Views

Best first search is a traversal technique that decides which node is to be visited next by checking which node is the most promising one and then check it. For this it uses an evaluation function to decide the traversal.This best first search technique of tree traversal comes under the category of heuristic search or informed search technique.The cost of nodes is stored in a priority queue. This makes implementation of best-first search is same as that of breadth First search. We will use the priorityqueue just like we use a queue for BFS.Algorithm for implementing Best First SearchStep 1 ... Read More

Bell Numbers - Number of ways to Partition a Set in C++

sudhir sharma
Updated on 22-Nov-2019 07:24:12

593 Views

A bell number is used to denote the number of ways a set of n elements can be partitioned into subsets that are not empty (i.e. have at least one element).In this program, we are given a set of n elements and we have to find the number of ways to partition the set into non-empty subsets.ExampleInput : 3 Output : 5Explanation − let the set of three elements {1, 2, 3}.The subsets are {{1} , {2} , {3}} ; {{1} , {2, 3}} ; {{1 , 2} , {3}} ; {{2} , {1 , 3}} ; {1 , 2 , 3}.Bell ... Read More

Basic Operators in Shell Scripting

sudhir sharma
Updated on 22-Nov-2019 07:19:26

15K+ Views

Shell is an interface using which the programmer can execute command and interact directly to the operating system. Shell scripting is giving commands that a shell can execute.In shell also there are variables and operators that are used to manipulate these variables. There are 5 basic operators in shell scripting.Arithmetic OperatorsRelational OperatorsBoolean OperatorsBitwise OperatorsFile Test OperatorsArithmetic OperatorsArithmetic operators in shell scripting are used to perform general arithmetic/ mathematical operations. There are 7 valid arithmetic operators in shell scripting −Addition (+) is used to add two operands (variables).Subtraction (-) is used to subtract two variables (operands) in shell scripting.Multiplication (*) is ... Read More

Basic Operators in Relational Algebra

sudhir sharma
Updated on 22-Nov-2019 07:13:33

4K+ Views

Relational Algebra is a procedural query language, it is used to provide a single table / relation as output of performing operations on more than one relations. Some of the basic relations will be discussed here.In our course of learning, we will use three relations (table) −Table 1: courseCourse_idName1Computer science2Information Technology3mechanicalTable 2: studentsRoll No.Nameaddressage1RamDelhi182Rajuhyderabad204FaizDelhi225Salmanhyderabad20Table 3: HostelSt. No.Nameaddressage1RamDelhi182Akashhyderabad203nehaJhansi21On this relations, we will perform some operation to make new relation based on operations performed.Selection operation (σ) − The selection operator denoted by sigma σ is used to select the tuples of a relation based on some condition. Only those tuples that fall ... Read More

Advertisements