## Stack Java Class – Explained

Earlier we saw about Stack and its implementation using Linked List. Java has a built in class for Stack. In this article we will discuss about it in detail. First brief about Stack. What...

@tutorialhorizon

Earlier we saw about Stack and its implementation using Linked List. Java has a built in class for Stack. In this article we will discuss about it in detail. First brief about Stack. What...

Infix, Postfix and Prefix notations are most common ways of writing expressions. Infix notation: Example: (A+B) Infix notation is commonly used in arithmetic formula or statements, the operators are written in-between their operands. An...

Objective: Given a Number, find all the set bits in that number. Example: Number: 23 Set bits: 4 (10111) Number: 15 Set bits: 4 (1111) Number: 21 Set bits: 3 (10101) Approach: Check the...

Objective: Given an array of integers, write a program to check if array contains all unique numbers. Example: Integer [] arrA = { 1, 2, 3, 6, 4, 9, 8}; Output: Array has all...

Objective: Given an array of integers which contains duplicates as well. Write a program to find the product of all unique elements in the array. This problem is also referred as find the product...

Objective: Given a number, write a java program to reverse a number Example: Given Number: 1234 Output: 4321 Given Number: 1020 Output: 201 Approach: Using loop Keep divide the number by 10 and add...

Objective: Given a number, write a program to check if given number is perfect sqaure. Example: N = 16 Output: True N = 32 Output: False Approach: Naive Approach: If N = 1 return...

Objective: Given an array of integers, write an algorithm to find the first three largest elements in the array. Example: Int [] a = { 6, 8, 1, 9, 2, 1, 10}; Output: 10,...

What is Selection Sort?? Selection sort is a simple sorting algorithm that builds the sorted array one item at a time. This sorting is efficient for small data sets, not efficient for large data...

Sometimes we need to print the numbers with its sign irrespective of number is positive (+) or negative(-). Example: X = 5, print = +5 Y = -8, print = -8 Say we need...

Objective: Given a string containing just the characters ( , ) determine if the input string is valid. Example: ()()(()(()))() valid: true )()()( valid: false ()()) valid: false Approach: Earlier we discussed the solution which keeps...

Quadratic equation is in the form = ax2 + bx + c Discriminant (d) = b2 – 4ac Then roots are calculates using the equations below Root_1 = (-b + √d)/2a Root_2 = (-b...

Objective: Given two input strings and one output strings, validate if output string contains all the characters from both the input strings. Example: Input1 = “boy”, Input2 = “girl”, output = “gboilry” Result =...

Objective: Given a String, write a program to find largest and smallest word in it. Example: Input String: test Smallest Word: test Largest Word: test —————— Input String: This problem is solved at Algorithms...

Objective: Given an array of integers, write an algorithm to find the two smallest elements in the array. Example: Int [] a = { 6, 8, 1, 9, 2, 10}; Output: 1, 2 Int...

%d bloggers like this: