- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 1401 Articles for C
![Sunidhi Bansal](https://www.tutorialspoint.com/assets/profiles/124656/profile/60_131452-1581053210.jpg)
815 Views
The task involves printing leaf nodes of a binary tree at given level k which is specified by the user.Leaf nodes are the end nodes whose left and right pointer is NULL which means that particular node is not a parent node.ExampleInput : 11 22 33 66 44 88 77 Output : 88 77Here, k represents the level of a tree which needs to be printed. The approach used here is traversing every node and checking whether the node is having any pointer. Even if there is one pointer that means either left or right or both than that particular ... Read More
![Sunidhi Bansal](https://www.tutorialspoint.com/assets/profiles/124656/profile/60_131452-1581053210.jpg)
410 Views
The task is to print the left nodes of a given binary tree. Firstly user will insert data hence generating binary tree and than print left view of the tree so formed.Every node can have at most 2 child so here the program must traverse only the left pointer associated with a nodeIf left pointer is not null means it will have some data or pointer associated with it if not than it will be the left child to be printed and displayed as an output.ExampleInput : 1 0 3 2 4 Output : 1 0 2here, orange nodes represent ... Read More
![Sunidhi Bansal](https://www.tutorialspoint.com/assets/profiles/124656/profile/60_131452-1581053210.jpg)
1K+ Views
Given a string in which we have to check that the length of the longest prefix which is also a suffix of the string like there is a string “abcab” so here “ab” is of length 2 and is the longest substring with same prefix and suffix.ExampleInput: str[] = { “aabbccdaabbcc” } Output: 6 Input: abdab Output: 2If we will start the pointer from start and end of the string than they will get overlapped at some point so instead of doing that we will break the string from middle and start matching left and right string. If they are ... Read More
![Sunidhi Bansal](https://www.tutorialspoint.com/assets/profiles/124656/profile/60_131452-1581053210.jpg)
95 Views
Given an array arr[m] with m number of integers and n, which is the value to be added in an array and r queries are given with some start and end. For each query we have to add value n from the start till the end of the limit in an array.ExampleInput: arr[] = {1, 2, 3, 4, 5} query[] = { { 0, 3 }, { 1, 2 } } n = 2 Output: If we run above program then it will generate following output: Query1: { 3, 4, 5, 6, 5 } Query2: { 3, 6, 7, 6, ... Read More
![Sunidhi Bansal](https://www.tutorialspoint.com/assets/profiles/124656/profile/60_131452-1581053210.jpg)
2K+ Views
Given with the matrix of n x n the task is to print that matrix of n x n in lower triangular pattern.Lower triangular matrix is a matrix which has elements below the principle diagonal including the principle diagonal elements and rest elements as zero.Let’s understand this with help of a diagram −Above the elements in green are the elements below the principle diagonal and the red elements are the elements above the principle diagonal which are set as zero.ExampleInput: matrix[3][3] = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 ... Read More
![Sunidhi Bansal](https://www.tutorialspoint.com/assets/profiles/124656/profile/60_131452-1581053210.jpg)
351 Views
Given with an array of size n x n and the task is to print the matrix elements of integer type diagonally downwards.Diagonally downwards means printing the array of any size of n x n in diagonally moving downward like in the figure given below −Firstly it will print 1 and then move to 2 print it and moves down to 4 diagonally and print it and so on.ExampleInput: Matrix [3][3] = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 }} Output: 1 2 4 3 5 7 6 8 ... Read More
![Sunidhi Bansal](https://www.tutorialspoint.com/assets/profiles/124656/profile/60_131452-1581053210.jpg)
160 Views
You are provided with a string str with some length n. Print the position of every element of the string so it can form a palindrome, else print a message “No palindrome” on screen.What is palindrome?Palindrome is a word, sequence of characters which reads same from the reverse or backward as from the forward manner, like MADAM, racecar.To find a sequence or a word is palindrome we generally store the reverse of a word in a separate string and compare both if they are same then the given word or sequence is palindrome. But in this question we have to ... Read More
![Sunidhi Bansal](https://www.tutorialspoint.com/assets/profiles/124656/profile/60_131452-1581053210.jpg)
102 Views
Given a number n, we have to print the steps to make the number as in form of 2^X-1 by using Xor operation.We should XOR the number with any 2^M-1, where M is chosen by you, at odd step. At even step increment the number by 1Keep performing the step until n becomes 2^X-1, and print all the stepsExampleInput: 22 Output: Step 1 : Xor with 15 Step 2: Increase by 1 Step 3 : Xor with 7 Step 4: Increase by 1 Step 5 : Xor with 1 Input:7 Output: No Steps to be performedAlgorithmint ... Read More
![Sunidhi Bansal](https://www.tutorialspoint.com/assets/profiles/124656/profile/60_131452-1581053210.jpg)
238 Views
We will be given a connected graph with N vertices and M edges. So we have to print the lexicographically smallest DFS of the graph starting from 1.Vertices should be numbered from 1 to NExampleInput: N = 5 M =5 edge(1, 4, arr) edge(3, 4, arr) edge(5, 4, arr) edge(3, 2, arr) edge(1, 5, arr) edge(1, 2, arr) edge(3, 5, arr) edge(1, 3, arr) output: 1 2 3 4 5Instead of doing a normal DFS, first we will sort the edges associated with each vertex, so that in each turn only the ... Read More
![Sunidhi Bansal](https://www.tutorialspoint.com/assets/profiles/124656/profile/60_131452-1581053210.jpg)
400 Views
We will be given a connected graph with N vertices M edges. So we have to print the lexicographically smallest BFS of the graph starting from 1.Lexicographically means in order starting from the given point till the end point is found.Vertices should be numbered from 1 to NExampleInput: N = 5 M = 5 edges(1, 4, arr) edges(3, 4, arr) edges(5, 4, arr) edges(3, 2, arr) edges(1, 5, arr) Output: 1 4 3 2 5Instead of doing a normal BFS traversal with a simple queue on the graph, we can use a priority queue(min ... Read More