
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Answer 12....
![can you please convert this python code into java?
Python code is as shown below:
# recursive function
def row_puzzle_rec(row, pos, visited):
# if the element at the current position is o we have reached
our goal
if row[pos] == 0:
possible = True
else:
# make a copy of the visited array
visited visited[:]
# if the element at the current position has been already
visited then it's a loop.
# as then its not possible to reach the last element, set
possible to False
if visited[pos]:
possible = False
else:
#set visitied for the element as True
visited[pos] = True
possible = False
# if its possible to move left then recurse in the left
direction
if pos - row[pos]>o and row_puzzle_rec(row, pos -
row[pos], visited):
# return immediately if the goal is reached
return True
# if its possible to move right then recurse in the right
direction
if pos + row[pos] < len(row) and row_puzzle_rec(row, pos +
row[pos], visited):
# return immediately if the goal is reached.
return True
return possible
def row_puzzle(row):
#visited array will be used to check if a particular element was
visited
# initialize the array to False
visited = [False for item in range(len(row))]
#second argument is the token position initialized to o
return row_puzzle_rec(row, o, visited)
possible = row_puzzle([2, 4, 5, 3, 1, 3, 1, 4, ol)
print(possible)
possible = row_puzzle([1, 3, 2, 1, 3, 4, 0])
print(possible)](https://content.bartleby.com/qna-images/question/ff8bc427-4dd5-458f-a0de-0d1350ec468a/e7d98e7d-6879-4d1b-b807-1f98255937db/wz8k9p7_thumbnail.jpeg)
Transcribed Image Text:can you please convert this python code into java?
Python code is as shown below:
# recursive function
def row_puzzle_rec(row, pos, visited):
# if the element at the current position is o we have reached
our goal
if row[pos] == 0:
possible = True
else:
# make a copy of the visited array
visited visited[:]
# if the element at the current position has been already
visited then it's a loop.
# as then its not possible to reach the last element, set
possible to False
if visited[pos]:
possible = False
else:
#set visitied for the element as True
visited[pos] = True
possible = False
# if its possible to move left then recurse in the left
direction
if pos - row[pos]>o and row_puzzle_rec(row, pos -
row[pos], visited):
# return immediately if the goal is reached
return True
# if its possible to move right then recurse in the right
direction
if pos + row[pos] < len(row) and row_puzzle_rec(row, pos +
row[pos], visited):
# return immediately if the goal is reached.
return True
return possible
def row_puzzle(row):
#visited array will be used to check if a particular element was
visited
# initialize the array to False
visited = [False for item in range(len(row))]
#second argument is the token position initialized to o
return row_puzzle_rec(row, o, visited)
possible = row_puzzle([2, 4, 5, 3, 1, 3, 1, 4, ol)
print(possible)
possible = row_puzzle([1, 3, 2, 1, 3, 4, 0])
print(possible)
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 3 images

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Q3: The wave path can be predicted using Snell's law n, sin 0₁ = n₂ sin 0₂ Prove that at the lower edge of the ionosphere the Snell's law reduces to sin 0 = √√ sin 0 Earrow_forwardNote: Answer five question only. 9/3/2023 علي صغير نية QI/A-If a current of 40 A exists for 1 min, how many coulombs and electrons of charge have passed through the wire? B-What is the resistance of a 30 m length of copper wire with a diameter of 0.5mm.the resistivity of copper is 1.72 x 108 22.m?arrow_forward#6arrow_forward
- (1 point) Alice and Bob are conducting Diffie-Hellman key exchange with the parameters p = 67 and a = and Bob selects private key b = 55. 2. Suppose Alice selects private key a = 25 a) What is Alice's public key? b) What is Bob's public key? c) What is the shared secret?arrow_forwardb Mra. Q5. A cylinder is 150 mm mean diameter and 750 mm long with a wall 2 mm thick. It has an internal pressure 0.8 MPa greater than the outside pressure. Calculate the following. E=200 GPa H i. The circumferential strain. ii. The longitudinal strain. EL iii. The change in diameter. iv. The change in length. L iv. The change in volume v 2:0.3 أطلبوها من مكتب لكلمات Q6. The thin walled cylinder can be supported in one of the two ways as shown. Determine the state of stress in the wall of the cylinder for both cases if the piston P causes the internal pressure to be 500 KPa. The wall has a thickness of 5 mm and the inner diameter of the cylinder is 200 mm. 2) Piston Piston 百货arrow_forwardI need matlab codes please. the one in blue box is the answer and also I need the graph.arrow_forward
- 2. (a) Compute and simplify f = (xz+ (y+t)' + (xz)'y')' Encircle final answer! (b) Prove or disprove that in any Boolean algebra, B: (i) 0' = 1 (ii) 1' = 0arrow_forward2. calculates the trajectory r(t) and stores the coordinates for time steps At as a nested list trajectory that contains [[xe, ye, ze], [x1, y1, z1], [x2, y2, z2], ...]. Start from time t = 0 and use a time step At = 0.01; the last data point in the trajectory should be the time when the oscillator "hits the ground", i.e., when z(t) ≤ 0; 3. stores the time for hitting the ground (i.e., the first time t when z(t) ≤ 0) in the variable t_contact and the corresponding positions in the variables x_contact, y_contact, and z_contact. Print t_contact = 1.430 X_contact = 0.755 y contact = -0.380 z_contact = (Output floating point numbers with 3 decimals using format (), e.g., "t_contact = {:.3f}" .format(t_contact).) The partial example output above is for ze = 10. 4. calculates the average x- and y-coordinates 1 y = Yi N where the x, y, are the x(t), y(t) in the trajectory and N is the number of data points that you calculated. Store the result as a list in the variable center = [x_avg, y_avg]…arrow_forwardEXAMPLE: The sum of any two even integers is even. Answer: Proof. (direct) Suppose x and y are even integers. By definition of even, let x = 2k and y = 2j for some integers j and k. Then, x+y=2k+2j = 2(k + j) Note that k+j is an integer because it is the sum of integers. Therefore, by definition of even, x + y is even.arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education