CS381_PSO_HW_Spring_2024
.pdf
keyboard_arrow_up
School
Purdue University *
*We aren’t endorsed by this school
Course
381
Subject
Computer Science
Date
Feb 20, 2024
Type
Pages
5
Uploaded by BailiffKangaroo6144
CS 381-Spring 2024
Homework 2
Due Date: Feb 13 at 11:59PM on Gradescope.
Instructors: Jeremiah Blocki and Simina Branzei
Name:
Purdue ID:
Learning Objectives
The homework is relevant to the following learning objectives:
•
LO 1.1 Students are able to devise randomized algorithms (including but not limited
to divide-and-conquer style of algorithms) and analyze their behavior.
•
LO 2.2 Students are able to extract the recurrence relationship from divide-and-conquer
algorithms.
•
LO 3.1 Students are able to use induction/invariant to prove that a divide-and-conquer
algorithm is correct.
•
Understanding the role of randomization in the design and analysis of algorithms.
Homework Guideline Reminders
•
Assignments must be typed. Submit one pdf file to Gradescope by 11:59PM, or else
late penalties will apply. The pdf file can include hand-drawn images of figures.
•
Each question needs to start with the resources and collaborator (RC) statement. You
will not be penalized for using resources or having collaborators if your answers are
expressed in your own words. If you consulted no resources outside of course material or
had no collaborators, you must state so. A question without a complete RC statement
will not be graded.
1
Question 0 (5 points)
Write the names of all your study group members, both here and in the file online:
https://
docs.google.com/document/d/1nx5sdsN_k1Kpf74-xGO3UFuQj5gvQQ4iE-HMksYJo2c/edit
.
This should include your own name.
Question 1 (25 points)
3-Coloring is a yes/no question, but we can phrase it as an optimization problem as follows.
Suppose we are given a graph
G
= (
V, E
), and we want to color each node with one of three
colors (red, green or blue) such that for each edge
{
u, v
} ∈
E
the endpoints
u
and
v
have a
different color. We say that an edge (
u, v
) is satisfied if the colors
c
(
u
) and
c
(
v
) assigned to
u
and
v
respectively are different i.e.,
c
(
u
)
̸
=
c
(
v
). Even if we aren’t necessarily able to give
different colors to every pair of adjacent edges we may still want to find a 3-Coloring that
satisfies as many edges as we can.
1. Suppose that we partition V into two parts
V
1
and
V
2
.
Let
E
1
(resp.
E
2
) denote
the set of edges
e
=
{
u, v
}
between two nodes in
V
1
(resp.
V
2
) and let
E
3
denote
the set of crossing edges with one endpoint in
V
1
and one endpoint in
V
2
.
See the
footnote
1
below for a formal definition of
E
1
, E
2
and
E
3
. Suppose that Alice finds a
coloring
c
Alice
:
V
1
→ {
R, G, B
}
of the nodes in
V
1
which satisfies at least
z
1
edges
from
E
1
and that Bob finds a coloring
c
Bob
:
V
2
→ {
R, G, B
}
of the nodes in
V
2
which
satisfies at least
z
2
edges. Show that there is a coloring
c
:
V
→ {
R, B, G
}
of the entire
graph which satisfies at least
z
1
+
z
2
+
2
3
|
E
3
|
edges in
E
. (
Hint:
It may help to use a
probabilistic argument involving linearity of expectation).
2. Give a deterministic divide and conquer style algorithm which outputs a coloring that
satisfies at least 2
|
E
|
/
3 edges. Analyze the running time of your algorithm and prove
that your algorithm satisfies at least 2
|
E
|
/
3 of the edges in the graph.
Collaborators:
Resources:
Solution:
1
Formally,
E
1
=
{{
u, v
}
∈
E
:
u, v
∈
V
1
}
and
E
2
=
{{
u, v
}
∈
E
:
u, v
∈
V
2
}
and
E
3
=
{{
u, v
} ∈
E
:
(
u
∈
V
1
∧
v
∈
V
2
)
∨
(
u
∈
V
2
∧
v
∈
V
1
)
}
.
2
Question 2 (25 points)
Consider the following gambling strategy to use in a casino: on the first play, stake
$
1; on
the second play
$
2; on the third play
$
4; on the
k
-th play
$
2
k
−
1
. Stop (i.e. leave the casino)
when winning for the first time. Assume each play to be fair: that is, you win or lose with
probability 1
/
2.
(Note: Betting
$
y dollars means that if you lose the bet, you pay the casino
$
y
dollars, while if you win, you receive
$
y dollars.)
•
(Part a. 13 points) Show that, if you follow this strategy, you will eventually leave the
casino
$
1 richer with probability 1. Justify your answers.
•
(Part b. 12 points) Let
X
be the random variable that measures your maximum loss
before winning (that is, the amount of money you have lost before the play on which
you win).
What is
E
[
X
]?
What does this tell about your ability to implement the
strategy? Justify your answers.
Collaborators:
Resources:
Solution:
3
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Related Questions
1
in java write code:
in java write code for particle swarm optimization which has adds a forth force closer to nest. calculate the direction the particles must move to be in the centre.
arrow_forward
Correct answer will be upvoted else downvoted. Computer science.
example of a chainword is the accompanying triple:
a line of m lowercase Latin letters;
the main clue: an arrangement of fragments with the end goal that the letters that compare to each portion spell a word from the word reference;
the subsequent clue: one more succession of portions with the end goal that the letters that relate to each section spell a word from the word reference.
Note that the successions of portions don't really need to be unmistakable.
Two occasions of chainwords are considered unique on the off chance that they have various strings, diverse first clues or distinctive second clues.
Count the number of various examples of chainwords. Since the number may be really huge, output it modulo 998244353.
Input
The primary line contains two integers n and m (1≤n≤8, 1≤m≤109) — the number of words in the word reference and the number of letter cells.
Every one of the following n…
arrow_forward
no Ai please
arrow_forward
Complete the task using the return search algorithm:
Task: The labyrinth is represented by a Boolean square matrix A8x8. The cell (i, j) is considered passable if the element ai, j is true and otherwise impassable. Write a program that checks if there is a path from adjacent horizontally and vertically passable cells of the maze, which starts in its upper left corner (0.0) and ends in its lower right corner (7.7).
Operating instructions:
1) Compose a Boolean function Path (i, j), called with initial parameters (0,0);
2) If cell (i, j) is outside the matrix Path returns false;
3) If cell (i, j) coincides with (7,7) a path is found and Path returns true;
4) If cell (i, j) is impassable Path returns false (because it cannot exit the cell), otherwise (if the cell is passable) there is a path from it to cell (7,7), if there is a path from any of the cells adjacent to (i, j) next to cell (7,7). Adjacent cells per cell (i, j) are cells (i + 1, j), (i, j + 1), (i-1, j), (i, j-1).
arrow_forward
:
|:
Section 3 - Random Forests
Decision Trees on their own are effectiev classifiers. The true power, though, comes from a forest of trees -- multiple decision trees working together as an
ensemble learner. We create multiple trees, each using a subset of the available attributes, let them each make a guess at the correct classification, and
then take the majority vote as the predicted class. Sounds tricky, right? Once again, sklearn to the rescue.
We are going to see if a random forest can improve on our decision tree accuracy for the bank data. To begin, we are going to create a Random Forest
using the wheat training and test data from the previous section. First, reload our data.
1 # reload the wheat dataset from UCI
2
3 df = pd. read_csv ("seeds_dataset.txt", sep='\\t', engine='python')
4
6
7
df.columns =
['a', 'p', 'compactness', 'length', 'width', 'coeff', 'length_g', 'type']
print (f'Our data has {df.shape [0]} rows and {df.shape [1]} columns')
8 #Mark 70% of the data for…
arrow_forward
Binning methods sorted data value by consulting its “neighbor- hood,” that is, the values around it.
Apply also the equal distance binning method in the sorted values
The sorted values are distributed into a number of “buckets,” or bins.
Price = 4, 8, 15, 21, 21, 24, 25, 28, 34, 36, 40, 50
In smoothing by bin means, each value in a bin is replaced by the mean value of the bin.
Smoothing by bin means:
Bin a:
Bin b:
Bin c:
arrow_forward
def solve_n_queens(n):
def is_safe(board, row, col):
# Verificar la columna
for i in range(row):
if board[i][col] == 1:
return False
# Verificar la diagonal izquierda
i, j = row, col
while i >= 0 and j >= 0:
if board[i][j] == 1:
return False
i -= 1
j -= 1
# Verificar la diagonal derecha
- Tell me Tree, termination conditions of a branch, in this code, in simple words, please.
-
arrow_forward
def solve_n_queens(n):
def is_safe(board, row, col):
# Verificar la columna
for i in range(row):
if board[i][col] == 1:
return False
# Verificar la diagonal izquierda
i, j = row, col
while i >= 0 and j >= 0:
if board[i][j] == 1:
return False
i -= 1
j -= 1
# Verificar la diagonal derecha
i, j = row, col
while i >= 0 and j < n:
if board[i][j] == 1:
return False
i -= 1
j += 1
return True
def solve(board, row):
if row >= n:
solution = []
for r in board:
solution.append("".join(['R' if x == 1 else '.' for x in r]))
solutions.append(solution)
return
for col in range(n):
if is_safe(board, row, col):
board[row][col] = 1
solve(board, row + 1)…
arrow_forward
Please don't use ai to answer I will report your answer please solve it with proper calculation and explanation
arrow_forward
Subject: Design & Analysis of algorithms
Questions:
Write your theoretical analysis for the brute force case
Write your theoretical analysis for the divide-and-conquer case
Note: The algorithms of both techniques are both answered before but I need to know their theoretical analysis.
arrow_forward
algorithm LeveledGraphWithAdvice(G, s, vi, birdAdvice) pre- & post-cond : Same as LeveledGraph except with advice.
arrow_forward
A Topological Sorting AlgorithmThe basic algorithm for topological sorting is straightforward:1. Locate a vertex with no successors.2. Insert the vertex into the list of vertices.3. Subtract the vertex from the graph.4. Repetition Step 1 until all vertices have been deleted.
Implement the algorithm by writing code.
arrow_forward
Question 12 kana.in pseudo code
Full explain this question and text typing work only We should answer our question within 2 hours takes more time then we will reduce Rating Dont ignore this line
arrow_forward
Hints
Master Method
Use recursion tree to give you the intuition
Formulate a hypothesis and use Induction or Strong Induction to prove it
Use change of variables to simpilify the recurrence
arrow_forward
Crossover and Mutation The two main operations in evolutionary computing are crossover and mutation. Crossover works like this: Randomly choose two parents from the population. Let’s say these: Parent 1: T F T F T T F Parent 2: T T T F F T T Those two parents will create a child whose DNA is related to the parents’. It works like this: for each of the seven genes in the chromosome, we will randomly pick a number between 1 and 10 and use it to choose which parents’ value the child will get. If the random number is 1 through 5, we will use Parent 1’s included value for the child; if it is 6…
arrow_forward
Crossover and Mutation The two main operations in evolutionary computing are crossover and mutation. Crossover works like this: Randomly choose two parents from the population. Let’s say these: Parent 1: T F T F T T F Parent 2: T T T F F T T Those two parents will create a child whose DNA is related to the parents’. It works like this: for each of the seven genes in the chromosome, we will randomly pick a number between 1 and 10 and use it to choose which parents’ value the child will get. If the random number is 1 through 5, we will use Parent 1’s included value for the child; if it is 6…
arrow_forward
Correct answer will be upvoted else Multiple Downvoted. Don't submit random answer. Computer science.
every cell of the network contains a non-negative integer. Each turn, a player should play out every one of the accompanying activities all together.
Pick a beginning cell (r1,c1) with non-zero worth.
Pick a completing cell (r2,c2) to such an extent that r1≤r2 and c1≤c2.
Lessening the worth of the beginning cell by some sure non-zero integer.
Pick any of the most limited ways between the two cells and either increment, lessening or leave the upsides of cells on this way unaltered. Note that:
a most limited way is one that goes through the most un-number of cells;
all cells on this way barring the beginning cell, yet the completing cell might be altered;
the subsequent worth of every cell should be a non-negative integer;
the cells are changed freely and not really by a similar worth.
On the off chance that the beginning and finishing cells are something very…
arrow_forward
implementalgorithm AdaptiveGreedy( set of objects ) pre-cond: The input consists of a set of objects. post-cond: The output consists of an optimal subset of them.
arrow_forward
Correct answer will be upvoted else Multiple Downvoted. Don't submit random answer. Computer science.
Two cells are adjoining in the event that they share a side. Thusly, every cell (x, y) has precisely three neighbors:
(x+1, y)
(x−1, y)
(x+1, y−1) in case x is even and (x−1, y+1) in any case.
At first a few cells are contaminated, all the others are sound. The course of recuperation starts. Each second, for precisely one cell (despite the fact that there may be different cells that could change its state) one of the accompanying occurs:
A sound cell with something like 2 contaminated neighbors likewise becomes tainted.
A contaminated cell with something like 2 solid neighbors likewise becomes sound.
In the event that no such cell exists, the course of recuperation stops. Patient is considered recuperated if the course of recuperation has halted and every one of the cells are solid.
We're keen on a most dire outcome imaginable: is it conceivable that the patient…
arrow_forward
Set Proofs Discrete Math Computer Science
arrow_forward
code in python
GAME SEARCH
One of the biggest areas of research in modern Artificial Intelligence is in making computer players for popular games. Make your own four depth binary tree. Solve the decision tree by applying gaming theory of your own choice (either apply Minimax or Alpha beta pruning etc. or any other technique), make a choice of your own values ranging from 0 to 50:
The game will be two player game, one will be user and other will be AI agent
Name and design of levels must be distinct for each student‟s game binary tree
arrow_forward
No image and no hand written solution
arrow_forward
SEE MORE QUESTIONS
Recommended textbooks for you
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
Related Questions
- 1 in java write code: in java write code for particle swarm optimization which has adds a forth force closer to nest. calculate the direction the particles must move to be in the centre.arrow_forwardCorrect answer will be upvoted else downvoted. Computer science. example of a chainword is the accompanying triple: a line of m lowercase Latin letters; the main clue: an arrangement of fragments with the end goal that the letters that compare to each portion spell a word from the word reference; the subsequent clue: one more succession of portions with the end goal that the letters that relate to each section spell a word from the word reference. Note that the successions of portions don't really need to be unmistakable. Two occasions of chainwords are considered unique on the off chance that they have various strings, diverse first clues or distinctive second clues. Count the number of various examples of chainwords. Since the number may be really huge, output it modulo 998244353. Input The primary line contains two integers n and m (1≤n≤8, 1≤m≤109) — the number of words in the word reference and the number of letter cells. Every one of the following n…arrow_forwardno Ai pleasearrow_forward
- Complete the task using the return search algorithm: Task: The labyrinth is represented by a Boolean square matrix A8x8. The cell (i, j) is considered passable if the element ai, j is true and otherwise impassable. Write a program that checks if there is a path from adjacent horizontally and vertically passable cells of the maze, which starts in its upper left corner (0.0) and ends in its lower right corner (7.7). Operating instructions: 1) Compose a Boolean function Path (i, j), called with initial parameters (0,0); 2) If cell (i, j) is outside the matrix Path returns false; 3) If cell (i, j) coincides with (7,7) a path is found and Path returns true; 4) If cell (i, j) is impassable Path returns false (because it cannot exit the cell), otherwise (if the cell is passable) there is a path from it to cell (7,7), if there is a path from any of the cells adjacent to (i, j) next to cell (7,7). Adjacent cells per cell (i, j) are cells (i + 1, j), (i, j + 1), (i-1, j), (i, j-1).arrow_forward: |: Section 3 - Random Forests Decision Trees on their own are effectiev classifiers. The true power, though, comes from a forest of trees -- multiple decision trees working together as an ensemble learner. We create multiple trees, each using a subset of the available attributes, let them each make a guess at the correct classification, and then take the majority vote as the predicted class. Sounds tricky, right? Once again, sklearn to the rescue. We are going to see if a random forest can improve on our decision tree accuracy for the bank data. To begin, we are going to create a Random Forest using the wheat training and test data from the previous section. First, reload our data. 1 # reload the wheat dataset from UCI 2 3 df = pd. read_csv ("seeds_dataset.txt", sep='\\t', engine='python') 4 6 7 df.columns = ['a', 'p', 'compactness', 'length', 'width', 'coeff', 'length_g', 'type'] print (f'Our data has {df.shape [0]} rows and {df.shape [1]} columns') 8 #Mark 70% of the data for…arrow_forwardBinning methods sorted data value by consulting its “neighbor- hood,” that is, the values around it. Apply also the equal distance binning method in the sorted values The sorted values are distributed into a number of “buckets,” or bins. Price = 4, 8, 15, 21, 21, 24, 25, 28, 34, 36, 40, 50 In smoothing by bin means, each value in a bin is replaced by the mean value of the bin. Smoothing by bin means: Bin a: Bin b: Bin c:arrow_forward
- def solve_n_queens(n): def is_safe(board, row, col): # Verificar la columna for i in range(row): if board[i][col] == 1: return False # Verificar la diagonal izquierda i, j = row, col while i >= 0 and j >= 0: if board[i][j] == 1: return False i -= 1 j -= 1 # Verificar la diagonal derecha - Tell me Tree, termination conditions of a branch, in this code, in simple words, please. -arrow_forwarddef solve_n_queens(n): def is_safe(board, row, col): # Verificar la columna for i in range(row): if board[i][col] == 1: return False # Verificar la diagonal izquierda i, j = row, col while i >= 0 and j >= 0: if board[i][j] == 1: return False i -= 1 j -= 1 # Verificar la diagonal derecha i, j = row, col while i >= 0 and j < n: if board[i][j] == 1: return False i -= 1 j += 1 return True def solve(board, row): if row >= n: solution = [] for r in board: solution.append("".join(['R' if x == 1 else '.' for x in r])) solutions.append(solution) return for col in range(n): if is_safe(board, row, col): board[row][col] = 1 solve(board, row + 1)…arrow_forwardPlease don't use ai to answer I will report your answer please solve it with proper calculation and explanationarrow_forward
- Subject: Design & Analysis of algorithms Questions: Write your theoretical analysis for the brute force case Write your theoretical analysis for the divide-and-conquer case Note: The algorithms of both techniques are both answered before but I need to know their theoretical analysis.arrow_forwardalgorithm LeveledGraphWithAdvice(G, s, vi, birdAdvice) pre- & post-cond : Same as LeveledGraph except with advice.arrow_forwardA Topological Sorting AlgorithmThe basic algorithm for topological sorting is straightforward:1. Locate a vertex with no successors.2. Insert the vertex into the list of vertices.3. Subtract the vertex from the graph.4. Repetition Step 1 until all vertices have been deleted. Implement the algorithm by writing code.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
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