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
pochemuha
4 years ago
11

Given an N x M matrix and a dictionary containing K distinct words of length between 1 and 30 symbols, the Word Search should re

turn all the words you can get from the matrix that are contained in the dictionary. There are rules: You can start from any cell in the matrix and go up, down, to the left, and to the right (not leaving the matrix) to collect letters for the word. Your "path" should not cross itself, i.e., a cell in the matrix cannot be visited more than once. You need to return the array of words found. There is no need to return the "paths" for them.
Engineering
1 answer:
Ket [755]4 years ago
8 0

Answer:

import java.util.*;

public class Main {

  public static String[] wordSearch(char[][] matrix, String[] words) {

      int N = matrix.length;

      List<String> myList = new ArrayList<String>();

      int pos = 0;

      for(String word : words)

      {

      for (int i = 0; i < N; i++) {

          for (int j = 0; j < N; j++) {

              if (search(matrix, word, i, j, 0, N)) {

              if(!myList.contains(word))

              {

              myList.add(word);

              }

              }

          }

      }

      }

     

      String[] newDict = myList.toArray(new String[myList.size()]);

     

  return newDict;

  }

  public static boolean search(char[][] matrix, String word, int row, int col,

          int index, int N) {

      // check if current cell not already used or character in it is not not

      if (word.charAt(index) != matrix[row][col]) {

          return false;

      }

      if (index == word.length() - 1) {

          // word is found, return true

          return true;

      }

             

      // check if cell is already used

      if (row + 1 < N && search(matrix, word, row + 1, col, index + 1, N)) { // go

                                                                              // down

          return true;

      }

      if (row - 1 >= 0 && search(matrix, word, row - 1, col, index + 1, N)) { // go

                                                                              // up

          return true;

      }

      if (col + 1 < N && search(matrix, word, row, col + 1, index + 1, N)) { // go

                                                                              // right

          return true;

      }

      if (col - 1 >= 0 && search(matrix, word, row, col - 1, index + 1, N)) { // go

                                                                              // left

          return true;

      }

      if (row - 1 >= 0 && col + 1 < N

              && search(matrix, word, row - 1, col + 1, index + 1, N)) {

          // go diagonally up right

          return true;

      }

      if (row - 1 >= 0 && col - 1 >= 0

              && search(matrix, word, row - 1, col - 1, index + 1, N)) {

          // go diagonally up left

          return true;

      }

      if (row + 1 < N && col - 1 >= 0

              && search(matrix, word, row + 1, col - 1, index + 1, N)) {

          // go diagonally down left

          return true;

      }

      if (row + 1 < N && col + 1 < N

              && search(matrix, word, row + 1, col + 1, index + 1, N)) {

          // go diagonally down right

          return true;

      }

      // if none of the option works out, BACKTRACK and return false

         

      return false;

  }

  public static void main(String[] args) {

      char[][] matrix = { { 'j', 'a', 's' },

              { 'a', 'v', 'o'},

              { 'h', 'a', 'n'} };

 

  String[] arr_str = {"a", "java", "vaxn", "havos", "xsds", "man"};

 

     

      arr_str = wordSearch(matrix, arr_str);

     

      for(String str : arr_str)

      {

      System.out.println(str);

      }

  }

}

You might be interested in
Imagine you are designing a new backpack. Which of the following statement(s) about
Hoochie [10]
The answer is D.) both A and C
3 0
4 years ago
Read 2 more answers
A cold storage room is used to keep the temperature inside the room maintain at low temperature.
lianna [129]

Answer:

The power of the brick wall it may be how the soiled ness of the wall too keep in the cold

Explanation:

5 0
3 years ago
Read 2 more answers
The following figures were obtained in a standard tensile test on a specimen of low carbon steel with a circular sectional area:
liq [111]

Answer:

See Explaination

Explanation:

1)here for given stress strain curve graph is given as follows

where for getting stress,S=F/A=4F/(pi*(50*10^-3)^2)

for strain=e=dl/l=dl*10^-3/100 mm/mm or m/m

2)so graph is as follows

3)for getting youngs modulus of elasticity we must know slope of graph stress verses strain and for straight line in elastic region upto 12 point we have elastic region and from that we get E as

E=slope of graph for first 12 points=S/e=14.5665*10^9/.812=17.9390*10^9 N/m2

4)for getting ultimate tensile stress at which specimen bears maximum load without failure so we get UTS as

UTS=maximum load/area=40*10^6/1.9634=20.3728*10^6 N/m2

5)percentage reduction in area is given by

percentage reduction in area=[original area-final area/original area]*100

Percent reduction=[5062-10^2]*100/50^2=96%

6)percentage elongation is given by

percent elongation=[final length-original length/original length]*100

final length at fractureis=14.56+100=114.56 mm

so we get percent elongation as=[114.56-100/100]*100=14.56%

7)true fracture stress is given by load at fracture devided by true area at fracture

Sf=load/(true area)=4*28*10^3/(pi*(10*10^-3)^2)=356.5070*10^6 N/m2

8 0
4 years ago
Which of the following describes the most direct and attainable way to reduce pollution in the environment?
kirill115 [55]

Answer:

i think its A. increasing research to find alternative natural resources for the future

5 0
3 years ago
Read 2 more answers
A square steel bar has a length of 7.2 ft and a 2.5 in by 2.5 in cross section and is subjected to axial tension. The final leng
Nataly_w [17]

Answer:

A) ν = 0.292

B) ν = 0.381

Explanation:

Poisson's ratio = - (Strain in the direction of the load)/(strain in the direction at right angle to the load)

In axial tension, the direction of the load is in the length's direction and the direction at right angle to the load is the side length

Strain = change in length/original length = (Δy)/y or (Δx)/x or (ΔL/L)

A) Strain in the direction of the load = (2.49946 - 2.5)/2.5 = - 0.000216

Strain in the direction at right angle to the load = (7.20532 - 7.2)/7.2 = 0.0007389

Poisson's ratio = - (-0.000216)/(0.0007389) = 0.292

B) Strain in the direction of the load = (2.09929 - 2.1)/2.1 = - 0.0003381

Strain in the direction at right angle to the load = (5.30470 - 5.3)/5.3 = 0.0008868

Poisson's ratio = - (-0.0003381)/(0.0008868) = 0.381

7 0
3 years ago
Other questions:
  • The work done by the system decreases the energy of the system. a)- True b)- False
    6·1 answer
  • A surveyor knows an elevation at Catch Basin to be elev=2156.77 ft. The surveyor takes a BS=2.67 ft on a rod at BM Catch Basin a
    15·1 answer
  • What is the lowest Temperature in degrees C?, In degrees K? in degrees F? in degrees R
    5·1 answer
  • For a ceramic compound, what are the two characteristics of the component ions that determine the crystal structure?
    13·1 answer
  • Air with a mass flow rate of 2.3 kg/s enters a horizontal nozzle operating at steady state at 450 K, 350 kPa, and velocity of 3
    5·1 answer
  • Which of the following identifies one factor that causes conventional tillage to actually be good for the environment?
    7·1 answer
  • What is the name for a program based on the way your brain works?
    13·2 answers
  • Who had launched the highest number of internet satellites as of March 2020?
    14·1 answer
  • Find R subscript C and R subscript B in the following circuit such that BJT would be in the active region with V subscript C E e
    12·1 answer
  • Based on your client's request, you will now create a sketch model of your designed pet toy. You will use your technical sketch
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!