1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
damaskus [11]
3 years ago
13

1. Write a recursive method to determine if a character is in a list of characters in O(logN) time. Mathematically prove (as we

did in class) that T(N) = O(logN). You can assume that this list is sorted lexicographically.
2. Write a function that determines if a string has the same number of 0’s and 1’s using a stack. The function must run in O(N) time. You can assume there already exists a stack class and can just use it
Computers and Technology
1 answer:
sergeinik [125]3 years ago
5 0

Answer:

1)

public class BinarySearch {

// Returns index of x if it is present in arr[l..

// r], else return -1

int binarySearch(char arr[], int l, int r, char x)

{

if (r >= l) {

int mid = l + (r - l) / 2;

 

// If the element is present at the

// middle itself

if (arr[mid] == x)

return mid;

 

// If element is smaller than mid, then

// it can only be present in left subarray

if (arr[mid] > x)

return binarySearch(arr, l, mid - 1, x);

 

// Else the element can only be present

// in right subarray

return binarySearch(arr, mid + 1, r, x);

}

 

// We reach here when element is not present

// in array

return -1;

}

 

// Driver method to test above

public static void main(String args[])

{

BinarySearch ob = new BinarySearch();

char arr[] = {'a','c','e','f','g','h'};

int n = arr.length;

char x = 'g';

int result = ob.binarySearch(arr, 0, n - 1, x);

if (result == -1)

System.out.println("Character not present");

else

System.out.println("Character found at index " + result);

}

}

2)

import java.io.*;

import java.util.*;

public class Test{

public static boolean checksame(String s)

{

 

Stack<Integer> stack= new Stack<Integer>();

for(int i=0;i<s.length();i++)

{

if(s.charAt(i)=='0')

{

if(stack.empty()==false)

{

if((Integer)stack.peek()==1)

stack.pop();

else

stack.push(0);

}

else

{

stack.push(0);

}

}

else if(s.charAt(i)=='1')

{

if(stack.empty()==false)

{

if((Integer)stack.peek()==0)

stack.pop();

 

else

stack.push(1);

}

else

{

stack.push(1);

}

 

}

}

return stack.empty();

}

public static void main(String []args){

System.out.println(checksame("a0w1220"));

}

}

Explanation:

You might be interested in
Which mechanism will move a port into a root-inconsistent state if bpdus coming from a certain direction indicate another switch
erma4kov [3.2K]

A root guard is seen as the  mechanism will move a port into a root-inconsistent state if bpdus coming from a certain direction indicate another switch is trying to become the root bridge.

<h3>What is Root guard?</h3>

Root guard is known to be a term that pertains to the family of STP feature and it is one that is enabled only on a port-by-port basis.

Note that  it hinders a configured port from changing to a root port and as such, a root guard is seen as the  mechanism will move a port into a root-inconsistent state if bpdus coming from a certain direction indicate another switch is trying to become the root bridge.

Learn more about root guard from

brainly.com/question/27780486

#SPJ1

4 0
2 years ago
Which applications run on IHGs private cloud?
Svetlanka [38]

Answer:

Applications CSS and JvaP

Explanation:

6 0
4 years ago
palindrome is a string that reads the same forwards as backwards. Using only a xed number of stacks, and a xed number of int and
bixtya [17]

Solution :

check_palindrome$(string)$

   lower_$case$_string$=$ string$. to$_lower()

   Let stack = new Stack()

   Let queue = new Queue();

   for each character c in lower_case_string:

       stack.push(c);

       queue.enqueue(c);

   let isPalindrome = true;

   while queue is not empty {

       if (queue.remove().equals(stack.pop())) {

           continue;

       } else {

           isPalindrome=false;

           break while loop;

       }

   }

   return isPalindrome

Input = aabb

output = true

input =abcd

output = false

6 0
3 years ago
how old is the letter 3 on its 23rd birthday when your car turns 53 and your dog needs gas and your feet need lave then when is
forsale [732]

Answer:

ummm...idr.k..u got me....wat is it

Explanation:

8 0
3 years ago
Python coding beginners question
Llana [10]

Answer:

i really don't know

4 0
3 years ago
Read 2 more answers
Other questions:
  • In an email, above subject, what does cc mean?
    13·1 answer
  • Paulene is using this table in Word,and she started with the cursor in the box that read “Flavor”. she then hits Alt+End,The the
    7·1 answer
  • What does NVRAM stand for
    8·2 answers
  • Nancy malone works for a california-based computer manufacturer. according to nancy, the time required to develop a new product
    6·1 answer
  • When solving for K, when cell potential is known, what is one of the first steps to follow?
    8·1 answer
  • In Windows, the only was to start/stop MySQL Server is from the Command Prompt.
    7·1 answer
  • What happen if there is no authentication??
    10·2 answers
  • Describe how to create a new folder on the desktop​
    12·2 answers
  • Which very high-speed fiber network was already in place and being used for wide area networking (wan) transmissions, before the
    15·1 answer
  • A student who wants to work with computers but does not have a strong aptitude for math might find a good fit by pursuing a(n)__
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!