Sunidhi Bansal has Published 1100 Articles

Product of the nodes of a Singly Linked List

Sunidhi Bansal

Sunidhi Bansal

Updated on 20-Sep-2019 08:01:06

276 Views

Given with n nodes the task is to print the product of all the nodes of a singly linked list. The program must traverse all the nodes of a singly linked list starting from the initial node till the NULL is not found.ExampleInput -: 1 2 3 4 5 Output ... Read More

Product of the alternate nodes of linked list

Sunidhi Bansal

Sunidhi Bansal

Updated on 20-Sep-2019 07:50:04

119 Views

Given with n nodes the task is to print the product of alternate node in a linked list. The program must only print the product of alternate nodes without actually changing the locations of the nodes.ExampleInput -: 10 20 30 40 50 60 Output -: 15000In the above example, starting ... Read More

Print the nodes of binary tree as they become the leaf node in C++ Programming.

Sunidhi Bansal

Sunidhi Bansal

Updated on 04-Sep-2019 07:29:57

83 Views

Given a binary tree, we have to print its leaf nodes and then we have to remove those leaf nodes and then repeat till there are no nodes left in the tree.ExampleSo the output of the problem should be −6 7 9 13 14 3 4 2 1ApproachWe have adopted ... Read More

Print matrix in zag-zag fashion in C Programming.

Sunidhi Bansal

Sunidhi Bansal

Updated on 04-Sep-2019 07:22:21

1K+ Views

Given a matrix mat[row][col] we have to print the given matrix in zig-zag fashion like in the given image below −So the output should be like −Output: 10 20 40 70 50 30 60 80 90For the above problem, we have followed a simple approach where we have to iterate ... Read More

Print path between any two nodes in a Binary Tree in C++ Programming.

Sunidhi Bansal

Sunidhi Bansal

Updated on 04-Sep-2019 07:05:59

368 Views

We are given with a binary tree of distinct nodes and two nodes of the binary tree whose path in the binary tree we want to print.For Example − We want to print the path between node 140 to 211 so its output should be like −Output: 140->3->10->211The idea is ... Read More

Print the first shortest root to leaf path in a Binary Tree in C++ Programming.

Sunidhi Bansal

Sunidhi Bansal

Updated on 04-Sep-2019 06:57:54

96 Views

Given the binary tree the program must find out the shortest path from the root to leaf amongst many given paths.Since we traverse the tree from left to right, so if there are multiple shortest paths from the root to leaf than the program will print the first traversed the ... Read More

Print root to leaf paths without using recursion in C++ Programming.

Sunidhi Bansal

Sunidhi Bansal

Updated on 04-Sep-2019 06:45:51

139 Views

Given the binary tree the program must find out the multiple paths from the root to a leaf which means all the paths should be printed but the challenge is to without using recursion.We will traverse the tree iteratively as the constraint is to do it without recursion. So to ... Read More

Print the nodes at odd levels of a tree in C++ Programming.

Sunidhi Bansal

Sunidhi Bansal

Updated on 04-Sep-2019 06:38:59

90 Views

Given the binary tree, the program must print the nodes at odd levels of a tree and the levels of a binary tree start from 1 to n.As nothing is mentioned one of the two approaches can be implemented i.e. recursion or iteration.Since we are using a recursive approach, the ... Read More

Print Levels of all nodes in a Binary Tree in C++ Programming.

Sunidhi Bansal

Sunidhi Bansal

Updated on 04-Sep-2019 06:34:51

182 Views

Given the binary tree, the task is to print the level associated with every key stored in a node starting from 1 to nIn the above tree, nodes are −10 at level 1 3 and 211 at level 2 140, 162, 100 and 146 at level 3Given the key the ... Read More

Print the number of set bits in each node of a Binary Tree in C++ Programming.

Sunidhi Bansal

Sunidhi Bansal

Updated on 04-Sep-2019 06:29:29

85 Views

Given the binary tree, the function will generate the binary values of the keys stored in the nodes and then return the number of set bits(1) in that binary equivalent.ExampleBinary tree having keys as: 10 3 211 140 162 100 and 146KeyBinary equivalentSet bits(output)101010230011221111010011514010001100316210100010310011001003146100100103Here we are using the function __builtin_popcountThe ... Read More

Advertisements