Write a program to implement binary search in PHP.
Given a sorted array, write a PHP code to search an element using binary search algorithm.
For example –
Input : { 1, 3, 5, 6, 7, 8, 9} , k = 6
Output: 3 (6 is found at 3rd index)
Write a java code to check balanced parentheses in an expression using stack.
Given an expression containing characters ‘{‘,’}’,'(‘,’)’,'[‘,’]’. We have to write a code to check whether an input string has valid parentheses.
An input string is valid if:
Open brackets must be closed by the same type of brackets.
Open brackets must be closed in the correct order.
Example –
i) {[]}) – Invalid
ii) {()}[] – Valid
Write a java program to reverse a string using stack data structure. Given an input string, We have to write a java code to reverse a string using stack.
In my previous tutorial, I have explained java program to reverse a string using recursion.
Before solving this problem, Let’s understand what is a stack data structure.