hw3
.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-Fall 2020
Homework 3
Due Date: Feb 29, 2024 at 11:59PM on Gradescope.
Instructors: Jeremiah Blocki and Simina Branzi
Name:
Purdue ID:
Learning Objectives
The homework is relevant to the following learning objectives:
•
LO 1.1 Students are able to provide examples of divide-and-conquer algorithms to
solve fundamental problems (e.g., Sorting, Multiplication, Skyline, Finding the Mean)
and identify the three main components of a divide-and-conquer algorithm (Divide,
Conquer and Merge). Students should be able to design their own divide-and-conquer
algorithms to solve problems.
•
LO 1.2 Students are able to provide examples of greedy algorithms and design their
own greedy algorithms to solve problems when applicable. Students should be able to
provide counter-examples when a proposed greedy algorithm is incorrect.
•
LO 3.1 Students are able to use induction/invariants to prove that a divide-and-conquer
algorithm is correct.
•
LO 3.2 Students are able to prove that a greedy algorithm is correct using exchange
arguments, contradiction and structural arguments.
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 1 (25 points)
(Double Inversions) Given an array
A
with
n
positive integers
a
1
, . . . , a
n
≥
1 we say that a
pair (
i, j
) forms a double inversion if
i < j
but
a
i
>
2
a
j
. If
j
=
i
+ 1 we call the pair (
i, j
) a
consecutive double inversion.
(a)
(7 points) Alice claims that if the array contains a double inversion (
i, j
) then the array
must contain a consecutive double inversion. Do you agree with Alice’s claim? If so
prove that Alice’s claim is true. If not provide a counterexample.
(b)
(18 points) Give an efficient algorithm to count the number of double inversions. Prove
that your algorithm is correct and analyze the running time of your algorithm.
Collaborators:
Resources:
2
Question 2 (25 points)
There are
n
seals that live in igloos along Arctic Road which is 100
n
meters long. As input
we are given
n
positive integers 0
≤
a
1
≤
. . .
≤
a
n
≤
100
n
indicating the location of seal
i
’s igloo (You may assume that the list
a
1
≤
a
2
≤
. . . a
n
is given in sorted order). The seals
are worried about polar bear attacks. Fortunately, there is a new amazing device called the
Polar Bear Repeller 9000 which has been scientifically proven to scare off polar bears. In
particular, if the Polar Bear Repeller 9000 is installed at location
x
on Artic Road then one
can be sure that there will be no Polar Bear attacks within a
√
n
meter radius i.e., any igloo
a
i
∈
[
x
−
√
n, x
+
√
n
] is guaranteed to be a safe location. The seals want to guarantee that
every seal igloo is safe from polar bear attacks. Unfortunately, the Polar Bear Repeller 9000
is expensive to purchase and maintain.
Thus, the seals want to minimize the number of
Polar Bear Repeller’s that they install in order to protect all of the igloos.
(a)
(5 points) How many Repeller’s are necessary in the worst case? Give an example of
a worst case input
a
1
≤
. . .
≤
a
n
which maximizes the number of Polar Bear Repeller
9000’s nececessary to protect all of the seals.
(b)
(10 points) Gulliver seal proposes the following greedy algorithm: find a location
x
which covers the maximum number of previously uncovered seal houses and install
a Repeller at location
x
.
Repeat until all seal houses are covered.
Does Gulliver’s
algorithm minimize the total number of Polar Bear Repeller 9000’s that are installed? If
not you should give a counter-example. If so you should prove that Gulliver’s algorithm
works and analyze the running time.
(c)
(10 points) Oliver seal proposes the following greedy algorithm: find the minimum
i
such that igloo
i
is currently uncovered and install a Repeller at location
a
i
+
√
n
.
Repeat until all seal houses are covered. Does Oliver’s algorithm minimize the total
number of Polar Bear Repeller 9000’s that are installed?
If not you should give a
counter-example. If so you should prove that Oliver’s algorithm works and analyze the
running time.
Collaborators:
Resources:
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
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
Python Knapsack Problem: imagine you are carrying a knapsack with capacity to hold a total of weight C. You are selecting among n items with values A={a_1, a_2, ... , a_n} and associated weights W={w_1, w_2, ... , w_n}. Here the weights and values are all positive. You wish to maximize the total value of the items you select not exceeding the given weight capacity, example, maximize sum_{a in A} such that sum_{w in W} <= C. Note that you can only select your items once.
Reformulate this as a bottom-up dynamic programming problem as follows. Define K_{i,j} as the highest possible value sum considering items 1 through i and total weight capacity j (j <= C). What is the base case i.e. K_{0,j} for all j and K_{i,0} for all i. What is the loop statement?
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
Solve these questions
arrow_forward
Make a 4x4 crossword puzzle for the picture below.
Words that should be searchable are
joy
bob
sun
bow
Letters that are searchable are f,k,s,s,b,j,o,u,b,o,b,n,x,y,w,y
{'f', 'k', 's','s'}
{'b', 'j', 'o','u'}
{'b', 'o', 'b', 'n'}
{'x', 'y', 'w', 'y'}
Do not use the string library
Call upon using the main function and all values will be stored in the class. There should be three menu options a search word, search letter and exit. Output word and letter if it exist and put not found it DNE.
Use the given code as a template
#include
using namespace std;
class Puzzle
{
private:
char arr[4][4]
public:
// constructor
Puzzle()
{
char arr[4][2] = {'f', 'k', 's','s'}
{'b', 'j', 'o','u'}
{'b', 'o', 'b', 'n'}
{'x', 'y', 'w', 'y'}
}
~Puzzle(){
}
search(){
}
void print_all()
{
for (int row = 0; row < n; row++)
for (int column = 0; c…
arrow_forward
Graph Theory:
Graph theory in computer science uses a graphical matrix with nodes and edges to describe a data structure. These can be used for search trees, game theory, shortest path, and many other applications in math and computer science.
An example of an application of a graph in computer science is the data structure used to hole the moves for a checkers game program. Each move can be represented by a node. The edges connecting the nodes are determined by the rules of the game, basically how to get to the node. This is a directed graph, because a player cannot take a move back. So the flow is always in one direction towards the end of the game.
Cycles in a graph is when a node can go back to itself. This is not possible in this graph, because a move can only go to another position on the board. The only case where this would be correct is if a player were allowed to skip his turn, or move to the same spot that he is already in.
A graph is said to be connected if there is a path…
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 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
Part A – Develop the algorithms
The challenge in the project is developing algorithms that accomplishes basic operations over an array of integer numbers.
The three operations are:
Find the minimum (smallest) value that appears in the array
Find the maximum (largest) value that appears in the array
Determine the number of unique values that appear in the array
Develop an algorithm for each of those tasks. The algorithms should work for any size of array. If the array is empty (i.e., doesn't include any elements/values) the algorithm should output a zero.
Keep in mind that like any computational problem there are several approaches to achieve a solution. For this programming checkpoint your will need to utilize loops and conditional statements.
Write the pseudocode or flowchart for the algorithm and store it in a file (file format can be text, pdf or doc) with the name arrayUtilSteps.
Part B - Implement the class
The goal for this part is to implement a class with the…
arrow_forward
Mini-Case Google’s PageRank:
Google’s PageRank is an algorithm that attempts to inform you where people are coming from when they land on your website and which sources are the most frequent. Note that, as its name suggests, a page rank is an index estimated page by page; it’s not an overall website assessment. Think of the Internet as a big network (duh), where the links aren’t all equal. Just as with people, some of your connections are “more important” (in achieving whatever goals) than others. With clickstreams, if you’re getting a lot of web traffic, is it coming from somewhere impressive like Amazon or from Joe’s-Shoes-and-Tshirts.com? The algorithm weights the more important (more connected) links more than the less important (less connected) links.
Say you’re trying to determine the rank of your home page. You figure that’s a good start, and customers can navigate more precisely once they’re in your domain. The ranking model begins by checking all the incoming links to the…
arrow_forward
Correct answer will be upvoted else Multiple Downvoted. Computer science.
Berland local ICPC challenge has quite recently finished. There were m members numbered from 1 to m, who contended on a problemset of n issues numbered from 1 to n.
Presently the article is going to happen. There are two issue creators, every one of them will tell the instructional exercise to precisely k back to back errands of the problemset. The creators pick the section of k continuous errands for themselves autonomously of one another. The sections can correspond, meet or not cross by any means.
The I-th member is keen on paying attention to the instructional exercise of all continuous errands from li to ri. Every member consistently decides to pay attention to just the issue creator that tells the instructional exercises to the most extreme number of assignments he is keen on. Leave this greatest number alone artificial intelligence. No member can pay attention to both of the creators, regardless of…
arrow_forward
help fin the corret ansewr fo this
arrow_forward
topic: Divide and conquerCreating decagons There are 1000 points in the plane, no three of them on the same line. Devise an algorithm to construct 100 decagons with their vertices at these points. The decagons need not be convex, but each of them has to be simple, i.e., its boundary should not cross itself, and no two decagons may have a common point.
arrow_forward
Boolean Satisfaction Problem
Boolean Satisfiability Problem (SAT) (https://en.wikipedia.org/wiki/Boolean_satisfiability_problem) is one of the most important problems in Computer Science. SAT is a problem that has NP-Complete complexity, where the only way to solve the problem is to try all the possibilities and check which one is correct.
[LO 1, LO 2, LO 3 & LO 4,] Briefly describe how you used Backtracking to solve the Boolean Satisfiability Problem. Note that your solution must have exponential complexity.
[LO 1, LO 2, LO 3 & LO 4,] Briefly explain how you use Strongly Connected Component (SCC) to solve the special case of the Boolean Satisfiability Problem, namely 2-SAT (https://en.wikipedia. org/wiki/2-SAT) . This solution has linear complexity.
Solve the Subparts A&B thank u
NOTE
LO1: Explain fundamental concept of analysis arithms.
LO2: Apply algorithm techniques and methods.
LO3: Solve a problem using specific algorithm.
LO4: Compare several algorithm design…
arrow_forward
neural networks
Program to generate random numbers from 11 to 21 as class 1 and generate random numbers from 9 to 55 as class append them to the lists. Take 8 data in each list and plot it.
arrow_forward
Algorithm Design and Analysis
arrow_forward
profile-image
Time remaining:
00
:
09
:
49
Computer Science
Design a greedy algorithm according to the scenario below and answer the following question (We don't need a code here just a complete explanation considering the facts below)
We have an L feet long tree which has n branches. We have a list of branch's height [h1, h2, h3, ..., hn] where hi
arrow_forward
Self Grouping Program
arrow_forward
Computer Science Algorithms
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
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
euclids algorithm tracing
arrow_forward
Q1. GCD-Euclidean Algorithm
Execute the Euclidean Algorithm to compute the greatest common divisor of the numbers:
1050 317
Show the steps of the algorithm. For numbers X and Y (X> Y), each step should be in the form
Answer:
x=qxY+r
(0≤r
arrow_forward
Heapsort analysis
in python or java implement the Heapsort algorithm. Include a counter so at the end of the execution of the algorithm the number of operations carried out is displayed. also design two test cases: best and worst case. Explain why they represent these cases.
Run the implemented algorithm for the best case and display the number of operations performed.
Run the implemented algorithm for the worst case and display the number of operations performed.
You must implement the algorithm, do not use a pre-implemented function.
Thanks in advance!
arrow_forward
Provide answer in C language please
You are tasked with creating a program that takes in an array of integers and sorts them in ascending order using a custom sorting algorithm. The custom sorting algorithm should be based on the following rules:
The sorting algorithm must use a divide-and-conquer approach.
The sorting algorithm must be recursive.
The sorting algorithm must have an average case time complexity of O(n log n).
The sorting algorithm must have a worst case time complexity of O(n^2).
The sorting algorithm must be stable, meaning that the relative order of equal elements should be preserved.
arrow_forward
SEE MORE QUESTIONS
Recommended textbooks for you
Operations Research : Applications and Algorithms
Computer Science
ISBN:9780534380588
Author:Wayne L. Winston
Publisher:Brooks Cole
Fundamentals of Information Systems
Computer Science
ISBN:9781305082168
Author:Ralph Stair, George Reynolds
Publisher:Cengage Learning
Related Questions
- 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 linearrow_forwardPython Knapsack Problem: imagine you are carrying a knapsack with capacity to hold a total of weight C. You are selecting among n items with values A={a_1, a_2, ... , a_n} and associated weights W={w_1, w_2, ... , w_n}. Here the weights and values are all positive. You wish to maximize the total value of the items you select not exceeding the given weight capacity, example, maximize sum_{a in A} such that sum_{w in W} <= C. Note that you can only select your items once. Reformulate this as a bottom-up dynamic programming problem as follows. Define K_{i,j} as the highest possible value sum considering items 1 through i and total weight capacity j (j <= C). What is the base case i.e. K_{0,j} for all j and K_{i,0} for all i. What is the loop statement?arrow_forwardComplete 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
- Solve these questionsarrow_forwardMake a 4x4 crossword puzzle for the picture below. Words that should be searchable are joy bob sun bow Letters that are searchable are f,k,s,s,b,j,o,u,b,o,b,n,x,y,w,y {'f', 'k', 's','s'} {'b', 'j', 'o','u'} {'b', 'o', 'b', 'n'} {'x', 'y', 'w', 'y'} Do not use the string library Call upon using the main function and all values will be stored in the class. There should be three menu options a search word, search letter and exit. Output word and letter if it exist and put not found it DNE. Use the given code as a template #include using namespace std; class Puzzle { private: char arr[4][4] public: // constructor Puzzle() { char arr[4][2] = {'f', 'k', 's','s'} {'b', 'j', 'o','u'} {'b', 'o', 'b', 'n'} {'x', 'y', 'w', 'y'} } ~Puzzle(){ } search(){ } void print_all() { for (int row = 0; row < n; row++) for (int column = 0; c…arrow_forwardGraph Theory: Graph theory in computer science uses a graphical matrix with nodes and edges to describe a data structure. These can be used for search trees, game theory, shortest path, and many other applications in math and computer science. An example of an application of a graph in computer science is the data structure used to hole the moves for a checkers game program. Each move can be represented by a node. The edges connecting the nodes are determined by the rules of the game, basically how to get to the node. This is a directed graph, because a player cannot take a move back. So the flow is always in one direction towards the end of the game. Cycles in a graph is when a node can go back to itself. This is not possible in this graph, because a move can only go to another position on the board. The only case where this would be correct is if a player were allowed to skip his turn, or move to the same spot that he is already in. A graph is said to be connected if there is a path…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_forwardCrossover 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_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_forward
- Part A – Develop the algorithms The challenge in the project is developing algorithms that accomplishes basic operations over an array of integer numbers. The three operations are: Find the minimum (smallest) value that appears in the array Find the maximum (largest) value that appears in the array Determine the number of unique values that appear in the array Develop an algorithm for each of those tasks. The algorithms should work for any size of array. If the array is empty (i.e., doesn't include any elements/values) the algorithm should output a zero. Keep in mind that like any computational problem there are several approaches to achieve a solution. For this programming checkpoint your will need to utilize loops and conditional statements. Write the pseudocode or flowchart for the algorithm and store it in a file (file format can be text, pdf or doc) with the name arrayUtilSteps. Part B - Implement the class The goal for this part is to implement a class with the…arrow_forwardMini-Case Google’s PageRank: Google’s PageRank is an algorithm that attempts to inform you where people are coming from when they land on your website and which sources are the most frequent. Note that, as its name suggests, a page rank is an index estimated page by page; it’s not an overall website assessment. Think of the Internet as a big network (duh), where the links aren’t all equal. Just as with people, some of your connections are “more important” (in achieving whatever goals) than others. With clickstreams, if you’re getting a lot of web traffic, is it coming from somewhere impressive like Amazon or from Joe’s-Shoes-and-Tshirts.com? The algorithm weights the more important (more connected) links more than the less important (less connected) links. Say you’re trying to determine the rank of your home page. You figure that’s a good start, and customers can navigate more precisely once they’re in your domain. The ranking model begins by checking all the incoming links to the…arrow_forwardCorrect answer will be upvoted else Multiple Downvoted. Computer science. Berland local ICPC challenge has quite recently finished. There were m members numbered from 1 to m, who contended on a problemset of n issues numbered from 1 to n. Presently the article is going to happen. There are two issue creators, every one of them will tell the instructional exercise to precisely k back to back errands of the problemset. The creators pick the section of k continuous errands for themselves autonomously of one another. The sections can correspond, meet or not cross by any means. The I-th member is keen on paying attention to the instructional exercise of all continuous errands from li to ri. Every member consistently decides to pay attention to just the issue creator that tells the instructional exercises to the most extreme number of assignments he is keen on. Leave this greatest number alone artificial intelligence. No member can pay attention to both of the creators, regardless of…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Operations Research : Applications and AlgorithmsComputer ScienceISBN:9780534380588Author:Wayne L. WinstonPublisher:Brooks ColeFundamentals of Information SystemsComputer ScienceISBN:9781305082168Author:Ralph Stair, George ReynoldsPublisher:Cengage Learning
Operations Research : Applications and Algorithms
Computer Science
ISBN:9780534380588
Author:Wayne L. Winston
Publisher:Brooks Cole
Fundamentals of Information Systems
Computer Science
ISBN:9781305082168
Author:Ralph Stair, George Reynolds
Publisher:Cengage Learning