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 of the following website is arguably considered the best site to search for scholarships
monitta
There is no way to define the 'best' site. Each site offers a unique experience along with the fact it might not display the same information as the other ones. The APEX site (As far as I know, it is a school test site) Won't really be able to help unless you are willing to do a few tests. I would go for Scholarshipexperts.com
3 0
3 years ago
Read 2 more answers
Question 5 of 10
Ostrovityanka [42]
Hello!

Answer:
B. Analyze data from the car’s external cameras.

I hope that this helps you!
3 0
2 years ago
A good algorithm should have which three components?
DiKsa [7]

A good algorithm should have these three components: C. steps, order, and outcomes.

<h3>What is an algorithm?</h3>

An algorithm simply refers to a standard formula which is made up of a set of finite steps and instructions that are executed on a computer system, in order to enable a software solve a particular problem under appropriate conditions.

In Computer technology, there are three (3) components that a good algorithm should have these include the following:

  • Steps
  • Order
  • Outcomes

Read more on algorithm here: brainly.com/question/24793921

#SPJ1

5 0
2 years ago
Test unit 8 edhesive answers ​
True [87]
What are the questions
7 0
3 years ago
List of steps to apply bold and italic formatting to a word​
ch4aika [34]
To make text bold, select and highlight the text first. Then hold down Ctrl (the control key) on the keyboard and press B on the keyboard. To make text italic, select and highlight the text first. Then hold down Ctrl (the control key) on the keyboard and then press the I on the keyboard
5 0
3 years ago
Read 2 more answers
Other questions:
  • 9. The best way to insert an existing Excel chart into a document is to A. use the Object command. B. click the Insert tab and c
    6·2 answers
  • A broadband router is used to do which of the following? run the programs on a computer locate lost files on a computer manage a
    6·1 answer
  • Purpose Your goal is to create a design for a software interface. You will experience the scope of the design process from brain
    7·1 answer
  • Which best describes a hybrid drive?
    11·1 answer
  • What do level meters show?
    8·1 answer
  • PLEASE HELP!!!!! WILL MARK BEST ANSWER BRAINLIEST!!!~~~
    11·2 answers
  • What is the working principle of computer?​
    10·1 answer
  • What is the difference between skew and rotate in the MS Paint application?
    14·2 answers
  • Which two components are configured via software in order for a PC to participate in a network environment
    5·1 answer
  • Pleasee helpppppppppppppppppppppp me!
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!