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 gene form of a trait is called a(n) ​
Rom4ik [11]

Answer:

alleles

Explanation:

7 0
3 years ago
Which password attack method uses long lists of words that have been predefined and can be quickly downloaded for use to break a
vova2212 [387]

Answer:

A dictonary attack.

Explanation:

Dictionaries hold many words that can be downloaded and used. Word or name passwords are usually just one word or maybe two. In other words, predefined words being used as a password? Not safe. When someone attempts to crack it, they use brute force attacks. Among these are dictionary attacks, which focus on the actual words rather than numbers.

3 0
2 years ago
The BaseballPlayer class stores the number of hits and the number of at-bats a player has. You will complete this class by writi
Rzqust [24]

Answer:

Answered below

Explanation:

Class BaseballPlayer{

//Instance variables

string name;

int hits;

int bats;

//Constructor

BaseballPlayer (string a, int b, int c){

name = a;

hits = b;

bats = c

}

public void printBattingDetails( ){

System.out.print(name, hits, bats)

}

}

//Demo class

Class BaseballTester{

public static void main (String args []){

BaseballPlayer player = new BaseballPlayer("Joe", 8, 4)

player.printBattingDetails( )

}

}

8 0
2 years ago
What are the XML technologies used in SOA?
saw5 [17]

Answer:

There are three technologies used for implementing the SOA most commonly with Web services are UDDI (Universal Description, Discovery & Integration) , WSDL (Web Services Description Language) and  SOAP (Simple Object Access Protocol) .

Out of them XML technologies are Web Services Description Language (WSDL) and Simple Object Access Protocol (SOAP).

WSDL is an XML language that describes a Web service.

SOAP is an XML Protocol and it is used by client application to communicate with web services.

8 0
3 years ago
A​ ________ is a person or organization that seeks to obtain or alter data or other IS assets​ illegally, without the​ owners' p
Mamont248 [21]

Answer: Threat

Explanation:

 Threat is one of the type of possible danger occur in the computer system security and also also exploit the security system that cause various types of possible harms.

Threat is alter any type of data in an organization without the permission of the owner.  

The threat can be classified into the different types are as follows:

  • Computer worm
  • DOS attack
  • Rootkit
  • Computer viruses

3 0
3 years ago
Other questions:
  • Which is a copyright
    5·1 answer
  • For which of the following careers is technology’s connectivity factor most important?
    13·2 answers
  • How can software be used to protect against hardware failures in systems that embody both? Give two examples of how software can
    14·1 answer
  • A report has a column of totals, with each total adding to the cell above it. What kind of calculated figure is this?
    15·1 answer
  • Which of the following describes the line spacing feature? Select all that apply. adds space between words adds space between li
    8·1 answer
  • dash is a set of communication standard using for transferring file information between computers in a network​
    5·1 answer
  • Your task is to build a palindrome from an input string.A palindrome is a word that readsthe same backward or forward. Your code
    12·1 answer
  • Give three general reasons for the importance of computer networking.
    9·1 answer
  • Which of the following best describes a hotspot as
    10·1 answer
  • in a block in a blockchain what represents the transactional data, sender, receiver, and number of coins? group of answer choice
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!