Nizamuddin Siddiqui

Nizamuddin Siddiqui

1,958 Articles Published

Articles by Nizamuddin Siddiqui

Page 145 of 196

How to invert a binary search tree using recursion in C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Aug-2021 2K+ Views

To invert a binary search tree, we call a method InvertABinarySearchTree which takes node as a parameter. If the node is null then return null, if the node is not null, we call the InvertABinarySearchTree recursively by passing the left and right child values. and assign the right child value to the left child and left child value to the right child. The final output will consist of the tree which will be its own mirror image.Examplepublic class TreesPgm{    public class Node{       public int Value;       public Node LeftChild;       public Node ...

Read More

How to check whether the tree is symmetric or not using recursion in C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Aug-2021 252 Views

In the recursive approach we to find a tree is symmetric or not we initially check whether the tree is null or not, if the tree is null then its symmetric, if the tree is not not null we call amethod issymmetricmirror .In isSymmetricMirror we get the value of the left child and right child, if both left and right child are null we consider as symmetric, if either of the value is null then we consider and not symmetric and at last we call the issymmetric method recursively by passing the left and right child values.Examplepublic class TreesPgm{   ...

Read More

How to check whether the tree is symmetric or not using iterative in C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Aug-2021 229 Views

In the Iterative approach we have to create 2 Queues, one queue saves the left child and another queue saves the right child value. If the tree is empty, then it is symmetrical to the vertical axis going through its root node. Else, check if the value at the root node of both subtrees is the same. If it is, then check if the left subtree and the right subtree are symmetrical. Enqueue the left child value and right child value into the queue1 and enqueue the right child and left child value into the queue1Examplepublic class TreesPgm{    public ...

Read More

How to implement coin change problem using bottom-up approach using C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Aug-2021 608 Views

CoinChangeBottomUpApproach takes 3 parameters as input n is the amount, coins array contains the total number of coins, t contains total number of coins. Declare a dynamic array which stores the previously calculated values. loop through the array and calculate the minimum coins required to calculate the amount. If the calculation is already done the take the value from the dynamic array.Time complexity − O(N)Space complexity − O(N)Examplepublic class DynamicProgramming{    public int CoinChangeBottomUpApproach(int n, int[] coins, int t){       int[] dp = new int[100];       for (int i = 1; i < n; i++){   ...

Read More

How to implement minimum step to one using topDown approach using C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Aug-2021 185 Views

MinimumStepstoOneTopdownApproach takes integer n and an integer array as input. Parameter n contains the total number of elements. Initial condition checks whether n is equal to 1. If n is equal to 1 then return 0. Initialize op1, op2 and op3 to max value . If n mod 3 is equal to 0 then call MinimumStepstoOneTopdownApproach recursively and assign it to op1 , If n mod 3 is equal to 0 then call MinimumStepstoOneTopdownApproach recursively and assign it to op2 else subtract n by 1 and call MinimumStepstoOneTopdownApproach . Finally call the Math.Min to calculate the minimum of three elements ...

Read More

How to implement Fibonacci using topDown approach using C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Aug-2021 913 Views

The Fibonacci sequence is a set of numbers that starts with a one or a zero, followed by a one, and proceeds based on the rule that each number (called a Fibonacci number) is equal to the sum of the preceding two numbers. The top-down approach focuses on breaking down a big problem into smaller and understandable chunks. Space complexity is O(N) because we are creating an extra array memory which is equal to the size of number.Time complexity − O(N)Space complexity − O(N)Examplepublic class DynamicProgramming{    public int fibonacciTopdownApproach(int n, int[] dpArr ){       if(n==0 || n ...

Read More

How to find the length of the longest continuous increasing subsequence from an array of numbers using C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Aug-2021 972 Views

LongestIncreaingSubsequence returns integer of the continuous subsequence from the array. The method has a for loop, which iterates and keeps the track of the numbers. the final result will have the Max calculated. Time complexity is O(N) because every element is visited once and the space complexity is O(1) because we are not making use of any storage space.Time complexity − O(N)Space complexity − O(1)Example   − {2, 4, 6, 5, 8}Output − 3Examplepublic class Arrays{    public int longestIncreaingSubsequence(int[] nums){       if (nums == null || nums.Length == 0){          return -1;     ...

Read More

How to find the length of the longest substring from the given string without repeating the characters using C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Aug-2021 1K+ Views

From the given string input, use the sliding window technique by having 2 pointers i and j . both i and j will point to the same character in the string. Traverse through the string and add it to the list. If the repeated character is found then remove it from the list else append to the list.Example 1Input − s = "abcabcbb"Output − 3Explanation − The answer is "abc", with the length of 3.Example 2Input − s = "bbbbb"Output − 1Explanation − The answer is "b", with the length of 1.Time complexity − O(N)Space complexity − O(N)Examplepublic class Arrays{    public int LongestSubstringWithNoRepeatingCharacters(string s){   ...

Read More

How to check whether the given strings are isomorphic using C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Aug-2021 977 Views

Two strings, X and Y, are called isomorphic if all occurrences of each character in X can be replaced with another character to get Y and vice-versa. For example, consider strings ACAB and XCXY. All occurrences of a character must be replaced with another character while preserving the order of characters. No two characters may map to the same character, but a character may map to itself.Example 1Input − s = "egg", t = "add"Output − trueExample 2Input − s = "foo", t = "bar"Output − falseTime complexity − O(N)Space complexity − O(N)codepublic class Arrays{    public bool IsStringIsomorphic(string s, string t){     ...

Read More

How to move all the zeros to the end of the array from the given array of integer numbers using C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Aug-2021 785 Views

Create a method MoveZeros, traverse through the array and count the number of Zeros in the array. Based on the count size make all the final cells to zero. Return without processing if the array length is null or empty. The final result will be in nums Array. Time complexity is O(N) because we are traversing through the array once.Time complexity − O(N)Space complexity − O(1)Examplepublic class Arrays{    public void MoveZeros(int[] nums){       if (nums == null || nums.Length == 0){          return;       }       int count = 0; ...

Read More
Showing 1441–1450 of 1,958 articles
« Prev 1 143 144 145 146 147 196 Next »
Advertisements