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
If the executives for Office Max LLC, a chain of office supply stores, developed the chain's objectives by asking buyers and sto
love history [14]

Answer:

It would be an example of bottom-up planning

Explanation:

Bottom-Up Planning is a method of planning that defines objectives and ways to achieve them through the bottom up. It relatively narrows goals that are initially set at the lower levels of the organizational hierarchy. First, relatively close targets at lower levels of the organizational hierarchy are set. They are then gradually integrated into the framework of global goals and global strategy at higher and higher levels. It is therefore a convergent approach.

With bottom-up planning, you give your project deeper focus because you have a larger number of employees involved in the project, each with their own area of expertise. Team members work side-by-side and have input during each stage of the process. Plans are developed at the lowest levels and are then passed on to each next higher level. It then reaches senior management for approval.

8 0
4 years ago
Which technique emphasizes the participative development among system owners, users, designers, and builders?A) Rapid applicatio
tekilochka [14]

Answer:

The correct option to the following question is option (D).

Explanation:

Rapid Application Building is also known as the RAD(Rapid Application Development) and it is one of the important functions of software development.

It is the concept that gives special importance in working on software and get more flexible as compared with the first development methods.

JAD(Joint Application Development) which is referred to as designing in the computers based systems and it the one of the important function of the software development.

5 0
4 years ago
Web Services: a. Is a hardware application b. Is a software application c. Is an enterprise system d. Is a single database
Simora [160]

Answer:

9qoqoqoqoqooq0qqqqqqqq

7 0
3 years ago
Earthquakes _____.
rosijanka [135]
<span>B: can be caused by volcanic eruptions</span>
7 0
3 years ago
Read 2 more answers
What are the five types of alignment in word?
valentinak56 [21]
I know of four,
Left-aligned
Center-aligned
right-aligned
justified

5 0
4 years ago
Read 2 more answers
Other questions:
  • Patrick Stafford's article argues that the growth of mobile phone usage "has given developers the ability to great robust and en
    7·1 answer
  • What is an icon or animation used to represent a participant in an internet chat referred to as
    15·2 answers
  • Which can be inserted using the insert panel in dreamweaver cc?
    9·1 answer
  • __________ refers to the idea that eachemployee should report
    14·1 answer
  • What is infinite recursion?
    7·1 answer
  • What kind of software program delivers advertising content in a manner that is unexpected and unwanted by the user, and is typic
    14·1 answer
  • Write a program that asks the user how many numbers will be entered and then has the user enter those numbers. When this is done
    7·1 answer
  • A studio camera is generally small and lightweight enough to be taken out into the
    11·1 answer
  • After Sally adds the Print Preview and Print command to the Quick Access Toolbar, which icon would she have added? the icon that
    6·2 answers
  • It's in Python, everything sort of explained in the image below,
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!