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
The power ratio 1.774 is equivalent to how many dB?
kvv77 [185]

Answer:

2.489 dB

Solution:

As per the question:

Power ratio, \frac{P'}{P} = 1.774

The Equivalent of this power ratio in decibel or dB is calculated by taking the log of the power ratio as below:

\frac{P'}{P}_{dB} = 10log_{10}\frac{P'}{P}

\frac{P'}{P}_{dB} = 10log_{10}\times 1.774 = 10\times 0.2489 = 2.489 dB

Thus the value of the power ration in decibel comes out to be 2.489 dB

3 0
3 years ago
EASY QUESTION EASY POINTS!!!!! WILL MARK BRAINLIEST!!!!!
TEA [102]

The program is an illustration of loops and conditional statements

<h3>Loops</h3>

Loops are used to perform repetitive operations.

<h3>Conditional statement</h3>

Conditional statements are used to make decisions

<h3>The python program</h3>

The program in Python, where comments are used to explain each line is as follows.

#The following is repeated 5 times; i.e. the rows

for i in range(5):

   #The following is repeated 5 times; i.e. the columns

   for j in range(5):

       #For rows 2 and 5

       if i == 1 or i== 3:

           #For columns 1 and 5

           if j == 0 or j == 4:

               #This prints *

               print('*',end='')

           #For other columns

           else:

               #This prints an empty space

               print('',end=' ')

       #For other rows

       else:

           #This prints *

           print('*',end='')

   #This prints a new line

   print()

Read more about loops at:

brainly.com/question/19344465

5 0
2 years ago
Benefits of etherchannel
Mariana [72]
An ether channel can give you high speed interface if it is successfully engineered. Combining 2 or more ethernet lets you create a logical ethernet link providing high speed links between switches. Also having etherchannel gives you a higher band width than what you costumed for.
5 0
3 years ago
41. Which is NOT a valid statement to initialize a variable?
ollegr [7]

I think its c I hope I'm not wrong about this If I am I'm sorry

5 0
2 years ago
The attribute that comes naturally to a person, such as manual dexterity, is called
Effectus [21]
The answer is Ability. 
7 0
2 years ago
Read 2 more answers
Other questions:
  • Write the half function. A function call and the functionprototype
    12·1 answer
  • What are the different components of the cloud architecture?
    5·2 answers
  • A group of students want to create an educational online game for computer laboratory in their school which type of network will
    6·1 answer
  • Int a=10 int b=20<br> A=b<br> The new values for a and b are
    11·2 answers
  • A technician receives an invalid certificate error when visiting a website with port 443 enabled. Other computers on the same LA
    8·1 answer
  • Alice and Bob decide to communicate using NTRUEncrypt with parameters (N, p, q) = (7, 3, 29). Alice’s public key is h(x) = 3 + 1
    15·1 answer
  • Why is it generally a good idea to set the font size to at least 30 points in presentations?
    6·2 answers
  • The 0-1 knapsack problem is the following. A thief robbing a store finds n items. The ith item is worth vi dollars and weighs wi
    14·1 answer
  • burger hut is trying to decide if it can receive money from the government for providing employees with insurance .
    6·1 answer
  • What was Ada Lovelace's contribution to computer science?
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!