SlideShare a Scribd company logo
1 of 17
For any help regarding Computer Network Assignment Help
Visit :- https://computernetworkassignmenthelp.com/ ,
Email :- support@computernetworkassignmenthelp.com or
Call us at :- +1 678 648 4277
Problem 1
For each question, choose all correct answers.
(a) Which of the following are true of thread confinement?
A.all privatefinalfields are confined
B.all immutable values are confined
C.the values of all local variables are confined
D.a BlockingQueueused to implement message passing should be confined
E.the view tree in a Swing GUI should be confined
Solution. E.
(b) Select all the strings below where the entire string is
matched by the regular expression:
([a-z]+[1-9]+)*[1-9]
A.bb8b8b
B.r2d222
C.c3po000
D.8
E.r5d4
Solution. B, D.
computernetworkassignmenthelp.com
(c) Consider an immutable class ComplexNumfor representing
complex numbers:
private final double realPart;
private final double imaginaryPart;
// AF: represents (realPart + i * imaginaryPart)
// RI: true
// ... other creators, producers, observers ...
public double absoluteValue() {
return Math.sqrt(realPart*realPart +
imaginaryPart*imaginaryPart)
}
@Override public boolean equals(Object other) {
if (!(other instanceof ComplexNum)) { return false; }
ComplexNum that = (ComplexNum)other;
return this.absoluteValue() == that.absoluteValue();
}
computernetworkassignmenthelp.com
This implementation of equals...
A.is reflexive
B.is symmetric
C.is transitive
D.returns true for ComplexNum pairs that should not be equal according to
the AF
E.returns false for ComplexNum pairs that should be equal according to the
AF
Solution. A, B, C, D. □
(d) Since ServerSocket.accept() is a blocking method, we can conclude
that...
A.accept()will not return until a client makes a connection
B.accept()will throw an exception if called when no clients are connecting
C.calling accept()could prevent the program from terminating
D.it is safe to call accept()simultaneously from multiple threads
E.while accept() is blocking, calling other methods on the same
ServerSocketinstance from other threads will block
Solution. A, C. □
computernetworkassignmenthelp.com
Problem 2 (Map/Filter/Reduce)
Ben Bitdiddle is trying to select a new password for his social media accounts. Given the
following interface for representing passwords:
public interface Password { public String
plainText(); public int strength();
}
For each method below, fill in the blanks to implement the specification using map, filter,
and reduce. You must use exactly two operations, but you may use the same operation
twice. On each line, fill in the first blank with map, filter, or reduce, and fill in the second
blank with a lambda expression. Solutions will be graded for correctness and clarity.
(a) /**
* @param passwords the passwords to consider
* @param minStrength the minimum strength a password should have
* @return the plaintext strings of passwords that have strength at least minStrength
*/
public static List<String> strongEnough(List<Password> passwords, int minStrength) {
return passwords.stream()
. ( )
. ( )
.collect(toList());
}
computernetworkassignmenthelp.com
(b) /**
* @param passwords the passwords to consider
* @param substring required substring
* @return the plaintext strings of passwords that contain substring
*/
public static List<String> containing(List<Password> passwords, String
substring) {
return passwords.stream()
. ( )
. ( )
.collect(toList());
}
(c) /**
* @param passwords the passwords to consider
* @return the average strength of the passwords
*/
public static double averageStrength(List<Password> passwords) {
return passwords.stream()
. ( )
computernetworkassignmenthelp.com
. (0, )
/ (double)passwords.size();
}
Solution.
(a).filter(p -> p.strength() >= minStrength)
.map(p -> p.plainText())
(b).map(p -> p.plainText())
.filter(p -> p.contains(substring))
(c).map(p -> p.length())
.reduce(0, (a,b) -> a+b)
Problem 3 (Abstract Data Types)
A tree is a data structure that consists of a root node and zero or more
children which themselves are also trees. A binary tree is a tree in which
each node has at most two children, designated left and right. For example:
computernetworkassignmenthelp.com
Simon Straightforward is an enthusiastic 6.005 student who just learned about ADTs
and wants to build a class to represent binary trees of positive integers. He comes up
with this internal representation:
/** A binary tree of positive integers. */
public class PosIntBinaryTree {
private final List<List<Integer>> nodes;
}
Simon wants each sub-list in nodes to represent a level in the binary tree, using 0 in
place of missing elements. For example, the binary tree shown above is represented by
the following list of lists:
[ [ 1 ]
[ 3, 5 ]
[ 0, 2, 6, 4 ] ]
(a) Silly Simon forgot to document his abstraction function and rep invariant!
Select statements to put into the AF and RI of PosIntBinaryTree by circling the letters of
all statements to include from the list below. Include all good statements that are
compatible with Simon’s design.
AF: A B C D E F G
RI: A B C D E F G
A.all 0 <= i < nodes.size(), nodes.get(i).get(0) > 0
B.if nodes.size() == 0, represents the empty tree
computernetworkassignmenthelp.com
Rob Recursive, an even more enthusiastic student, wants to represent binary trees of
any integers.
(b)What bad practice in Simon’s rep prevents Rob from easily extending it?
Solution. Magic number 0. □
(c)Rob decides to implement the binary trees recursively, using an interface
IntBinaryTree with two concrete variants, one of which represents the empty tree.
He also decides the type will be immutable.
/** An immutable binary tree of integers. */
public interface IntBinaryTree { ... }
Write a recursive datatype definition for IntBinaryTree:
Solution. IntBinaryTree = Empty() + Tree(value: int, left,right: IntBinaryTree) □
C.if nodes.size() > 0, nodes.get(0).get(0) is the root node
D.nodes.get(i).size() == 2^I
E.nodes.size() == 2^k for some nonnegative integer k
F.for node nodes.get(i).get(j),
its left child (if any) is nodes.get(i+1).get(j*2)
G.for node nodes.get(i).get(j),
its right child (if any) is nodes.get(i+1).get(j*2+1)
Solution. AF: B, C, F, and G. RI:
D.
computernetworkassignmenthelp.com
(d) Start implementing the concrete variant that represents the empty tree by
writing its field declarations, abstraction function, and rep invariant. If parts of the
AF or RI would normally be assumed in 6.005, write them explicitly.
Fields:
AF:
RI:
Solution.
No fields
AF: represents the empty immutable
binary tree of integers RI: true
□
(e) Start implementing the other concrete variant by writing its field declarations,
abstraction function, and rep invariant. If parts of the AF or RI would normally be
assumed in 6.005, write them explicitly.
Fields:
AF:
RI:
Solution.
private final int value;
private final IntBinaryTree left, right;
AF: represents the immutable binary tree of integers with root node value, left
subtree left, and right subtree right
computernetworkassignmenthelp.com
RI: left,right != null □
Problem 4 (Recursive Data Types) (20 points).
A Boolean formula is a propositional expression consisting of variables, ∧
(and) and ∨ (or) binary operators, and ¬ (not) unary operators.
For example, the following expression means “either P or Q is true, and
either P is false or R is true”:
(P ∨ Q) ∧ (¬P ∨ R)
A formula is in negation normal form if the negation operator (¬) is only
applied directly to variables. For example, P ∧ (¬Q ∨ R) is in negation
normal form, but P ∧ ¬(Q ∨ R) and ¬(P ∧ (¬Q ∨ R)) are not.
Here is a datatype definition for an ADT to represent negation normal form
Boolean formulas:
NegNormFormula = Variable(name: String, isNegated: boolean)
+ And(left: NegNormFormula, right:
NegNormFormula) + Or(left: NegNormFormula,
right: NegNormFormula)
Now consider this specification:
// returns a negation of the input formula
negate : NegNormFormula -> NegNormFormula
(a) Classify this operation according to our types of ADT operations:
computernetworkassignmenthelp.com
□
(b) Implement the operation. Use De Morgan’s laws and the
rule for double negation:
¬(P ∧ Q) = ¬P ∨ ¬Q and
¬(P ∨ Q) = ¬P ∧ ¬Q and
public class Variable implements NegNormFormula {
private final String name;
private final boolean isNegated;
public Variable(String name, boolean isNegated) {
... } @Override public NegNormFormula negate() {
¬¬P = P
Solution.
return new Variable(name, ! isNegated);
□
}
}
public class And implements
NegNormFormula { private final
NegNormFormula left; private final
NegNormFormula right;
public And(NegNormFormula left, NegNormFormula
right) { ... } @Override public NegNormFormula negate() {
Soluti
on.
return new Or(left.negated(),
right.negated());
□
computernetworkassignmenthelp.com
}
}
public class Or implements
NegNormFormula { private final
NegNormFormula left; private final
NegNormFormula right;
public Or(NegNormFormula left, NegNormFormula right)
{ ... } @Override public NegNormFormula negate() {
Solution.
return new And(left.negated(),
right.negated());
□
}
}
Problem 5 (Thread Safety)
It’s election season! With the tight race for president of Fictional Dystopia,
you’ve been asked to develop a secure online voting system.
In Fictional Dystopian elections, each voter has exactly two votes. Each
voter can vote twice for the same candidate, or split their vote between two
different candidates.
computernetworkassignmenthelp.com
public class TwoVotesEachElection {
private final AtomicInteger[] voteCounts;
private final Set<String> voters;
// ... constructor initializes voteCounts to an array of AtomicIntegers,
// each with value zero, and initializes voters to a threadsafe Set ...
public int getNumberOfCandidates() { return voteCounts.length; }
// requires: 0 <= can1, can2 < getNumberOfCandidates()
// effects: if and only if the voter hasn’t already voted, casts both votes
public void vote(final String voterID, final int can1, final int can2) {
if (voters.contains(voterID)) { return; }
voters.add(voterID);
// use the atomic incrementAndGet operation
// (we don’t need the "get" part, but there is no plain "increment")
voteCounts[can1].incrementAndGet();
voteCounts[can2].incrementAndGet();
}
// ...
}
Suppose election is a TwoVotesEachElection with 4 candidates (so voteCounts.length
= 4).
(a) Unfortunately, even though TwoVotesEachElection uses threadsafe datatypes, the
vote() opera- tion is not threadsafe. Explain clearly an interleaving that violates thread
safety for TwoVotesEachElection.
computernetworkassignmenthelp.com
Solution. Two threads enter votewith the same voterIDnot yet in voters.
Both threads call voters.containsand obtain false, then both call voters.addsuccessfully.
At this point, both threads will increment the vote counts for their can1 and can2, giving this
voter 4 votes instead of 2, in violation of the postcondition. □
Louis Reasoner is convinced that using AtomicInteger is unnecessary, so he changes the
code to use primitive integers instead:
public class LouisTwoVotesEachElection {
private final int[] voteCounts;
private final Set<String> voters;
// ... constructor initializes voteCounts to an array of zeros,
// and initializes voters to a threadsafe Set ...
public int getNumberOfCandidates() { return voteCounts.length; }
// requires: 0 <= can1, can2 < getNumberOfCandidates()
// effects: if and only if the voter hasn’t already voted, casts both votes
public void vote(final String voterID, final int can1, final int can2) {
if (voters.contains(voterID)) { return; }
computernetworkassignmenthelp.com
voters.add(voterID); voteCounts[can1]++;
voteCounts[can2]++;
}
// ...
}
Of course, this just makes the problem worse.
(b) Suppose 100 voters, each using a different thread, participate in our 4-candidate
election by concur- rently calling Louis’ vote(). Every voter uses a unique ID, and no one
casts both of their votes for the same candidate. The value of the sum
voteCounts[0] + voteCounts[1] + voteCounts[2] + voteCounts[3]
could be which of the following? Choose all that apply.
A.0
B.1
C.2
D.4
E. 100
F. 200
G. 400
Solution. C, D, E, F.
□
computernetworkassignmenthelp.com
Solution. A, C, D.
Locking on different voterID strings doesn’t help. voteCounts[0] is a primitive in Louis’
code.
At least one thread will successfully increment the count for its first candidate; same
for some thread and its second candidate. With no races at all, 200 votes will be
counted.
(c) Louis wants to fix the thread safety problems by putting all the code inside vote()
in a synchronized block. Of the following objects in Louis’ version of the code,
which are suitable for us to synchronize on in order to ensure thread safety for
concurrent calls to vote()? Choose all that apply.
A.this
B.voterID
C.voters
D.voteCounts
E.voteCounts[0]
computernetworkassignmenthelp.com

More Related Content

What's hot

C programming & data structure [arrays & pointers]
C programming & data structure   [arrays & pointers]C programming & data structure   [arrays & pointers]
C programming & data structure [arrays & pointers]MomenMostafa
 
Function Composition - forward composition versus backward composition
Function Composition - forward composition versus backward compositionFunction Composition - forward composition versus backward composition
Function Composition - forward composition versus backward compositionPhilip Schwarz
 
Introduction to c++
Introduction to c++Introduction to c++
Introduction to c++somu rajesh
 
Functions in C++
Functions in C++Functions in C++
Functions in C++home
 
C interview question answer 2
C interview question answer 2C interview question answer 2
C interview question answer 2Amit Kapoor
 
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part ...
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part ...Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part ...
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part ...Philip Schwarz
 
C aptitude scribd
C aptitude scribdC aptitude scribd
C aptitude scribdAmit Kapoor
 
C programming session 01
C programming session 01C programming session 01
C programming session 01Dushmanta Nath
 
Advanced Programming C++
Advanced Programming C++Advanced Programming C++
Advanced Programming C++guestf0562b
 
Game of Life - Polyglot FP - Haskell - Scala - Unison - Part 3
Game of Life - Polyglot FP - Haskell - Scala - Unison - Part 3Game of Life - Polyglot FP - Haskell - Scala - Unison - Part 3
Game of Life - Polyglot FP - Haskell - Scala - Unison - Part 3Philip Schwarz
 
C++ Function
C++ FunctionC++ Function
C++ FunctionHajar
 
Game of Life - Polyglot FP - Haskell, Scala, Unison - Part 2 - with minor cor...
Game of Life - Polyglot FP - Haskell, Scala, Unison - Part 2 - with minor cor...Game of Life - Polyglot FP - Haskell, Scala, Unison - Part 2 - with minor cor...
Game of Life - Polyglot FP - Haskell, Scala, Unison - Part 2 - with minor cor...Philip Schwarz
 
C++ Overview
C++ OverviewC++ Overview
C++ Overviewkelleyc3
 

What's hot (20)

C programming & data structure [arrays & pointers]
C programming & data structure   [arrays & pointers]C programming & data structure   [arrays & pointers]
C programming & data structure [arrays & pointers]
 
Function Composition - forward composition versus backward composition
Function Composition - forward composition versus backward compositionFunction Composition - forward composition versus backward composition
Function Composition - forward composition versus backward composition
 
Introduction to c++
Introduction to c++Introduction to c++
Introduction to c++
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
C interview question answer 2
C interview question answer 2C interview question answer 2
C interview question answer 2
 
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part ...
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part ...Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part ...
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part ...
 
C aptitude scribd
C aptitude scribdC aptitude scribd
C aptitude scribd
 
C programming session 01
C programming session 01C programming session 01
C programming session 01
 
Advanced Programming C++
Advanced Programming C++Advanced Programming C++
Advanced Programming C++
 
Tutorial2
Tutorial2Tutorial2
Tutorial2
 
C++ Functions
C++ FunctionsC++ Functions
C++ Functions
 
Computer Programming- Lecture 3
Computer Programming- Lecture 3Computer Programming- Lecture 3
Computer Programming- Lecture 3
 
Game of Life - Polyglot FP - Haskell - Scala - Unison - Part 3
Game of Life - Polyglot FP - Haskell - Scala - Unison - Part 3Game of Life - Polyglot FP - Haskell - Scala - Unison - Part 3
Game of Life - Polyglot FP - Haskell - Scala - Unison - Part 3
 
C++ Function
C++ FunctionC++ Function
C++ Function
 
Computer Programming- Lecture 6
Computer Programming- Lecture 6Computer Programming- Lecture 6
Computer Programming- Lecture 6
 
Game of Life - Polyglot FP - Haskell, Scala, Unison - Part 2 - with minor cor...
Game of Life - Polyglot FP - Haskell, Scala, Unison - Part 2 - with minor cor...Game of Life - Polyglot FP - Haskell, Scala, Unison - Part 2 - with minor cor...
Game of Life - Polyglot FP - Haskell, Scala, Unison - Part 2 - with minor cor...
 
C++ Language
C++ LanguageC++ Language
C++ Language
 
C++ Overview
C++ OverviewC++ Overview
C++ Overview
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
Adobe
AdobeAdobe
Adobe
 

Similar to Computer Network Assignment Help

Class 12 computer sample paper with answers
Class 12 computer sample paper with answersClass 12 computer sample paper with answers
Class 12 computer sample paper with answersdebarghyamukherjee60
 
B61301007 matlab documentation
B61301007 matlab documentationB61301007 matlab documentation
B61301007 matlab documentationManchireddy Reddy
 
C++ Programming Homework Help
C++ Programming Homework HelpC++ Programming Homework Help
C++ Programming Homework HelpC++ Homework Help
 
Consider this code using the ArrayBag of Section 5.2 and the Locat.docx
Consider this code using the ArrayBag of Section 5.2 and the Locat.docxConsider this code using the ArrayBag of Section 5.2 and the Locat.docx
Consider this code using the ArrayBag of Section 5.2 and the Locat.docxmaxinesmith73660
 
Matlab Functions
Matlab FunctionsMatlab Functions
Matlab FunctionsUmer Azeem
 
Java concepts and questions
Java concepts and questionsJava concepts and questions
Java concepts and questionsFarag Zakaria
 
Q1 Consider the below omp_trap1.c implantation, modify the code so t.pdf
Q1 Consider the below omp_trap1.c implantation, modify the code so t.pdfQ1 Consider the below omp_trap1.c implantation, modify the code so t.pdf
Q1 Consider the below omp_trap1.c implantation, modify the code so t.pdfabdulrahamanbags
 
C cheat sheet for varsity (extreme edition)
C cheat sheet for varsity (extreme edition)C cheat sheet for varsity (extreme edition)
C cheat sheet for varsity (extreme edition)Saifur Rahman
 
Gsp 215 Effective Communication / snaptutorial.com
Gsp 215  Effective Communication / snaptutorial.comGsp 215  Effective Communication / snaptutorial.com
Gsp 215 Effective Communication / snaptutorial.comHarrisGeorg21
 
Introduction to c
Introduction to cIntroduction to c
Introduction to camol_chavan
 
please help me with this and explain in details also in the first qu.pdf
please help me with this and explain in details also in the first qu.pdfplease help me with this and explain in details also in the first qu.pdf
please help me with this and explain in details also in the first qu.pdfnewfaransportsfitnes
 

Similar to Computer Network Assignment Help (20)

Stacks.ppt
Stacks.pptStacks.ppt
Stacks.ppt
 
Stacks.ppt
Stacks.pptStacks.ppt
Stacks.ppt
 
Revision1 C programming
Revision1 C programmingRevision1 C programming
Revision1 C programming
 
Class 12 computer sample paper with answers
Class 12 computer sample paper with answersClass 12 computer sample paper with answers
Class 12 computer sample paper with answers
 
B61301007 matlab documentation
B61301007 matlab documentationB61301007 matlab documentation
B61301007 matlab documentation
 
C++ Programming Homework Help
C++ Programming Homework HelpC++ Programming Homework Help
C++ Programming Homework Help
 
Consider this code using the ArrayBag of Section 5.2 and the Locat.docx
Consider this code using the ArrayBag of Section 5.2 and the Locat.docxConsider this code using the ArrayBag of Section 5.2 and the Locat.docx
Consider this code using the ArrayBag of Section 5.2 and the Locat.docx
 
C Programming
C ProgrammingC Programming
C Programming
 
Matlab Functions
Matlab FunctionsMatlab Functions
Matlab Functions
 
Java concepts and questions
Java concepts and questionsJava concepts and questions
Java concepts and questions
 
Q1 Consider the below omp_trap1.c implantation, modify the code so t.pdf
Q1 Consider the below omp_trap1.c implantation, modify the code so t.pdfQ1 Consider the below omp_trap1.c implantation, modify the code so t.pdf
Q1 Consider the below omp_trap1.c implantation, modify the code so t.pdf
 
C++ Homework Help
C++ Homework HelpC++ Homework Help
C++ Homework Help
 
Programming Exam Help
 Programming Exam Help Programming Exam Help
Programming Exam Help
 
C cheat sheet for varsity (extreme edition)
C cheat sheet for varsity (extreme edition)C cheat sheet for varsity (extreme edition)
C cheat sheet for varsity (extreme edition)
 
CPP Homework Help
CPP Homework HelpCPP Homework Help
CPP Homework Help
 
functions
functionsfunctions
functions
 
Functions
FunctionsFunctions
Functions
 
Gsp 215 Effective Communication / snaptutorial.com
Gsp 215  Effective Communication / snaptutorial.comGsp 215  Effective Communication / snaptutorial.com
Gsp 215 Effective Communication / snaptutorial.com
 
Introduction to c
Introduction to cIntroduction to c
Introduction to c
 
please help me with this and explain in details also in the first qu.pdf
please help me with this and explain in details also in the first qu.pdfplease help me with this and explain in details also in the first qu.pdf
please help me with this and explain in details also in the first qu.pdf
 

More from Computer Network Assignment Help

Elevate Your Networking Game with Expert Computer Network Assignment Help
Elevate Your Networking Game with Expert Computer Network Assignment HelpElevate Your Networking Game with Expert Computer Network Assignment Help
Elevate Your Networking Game with Expert Computer Network Assignment HelpComputer Network Assignment Help
 

More from Computer Network Assignment Help (20)

Elevate Your Networking Game with Expert Computer Network Assignment Help
Elevate Your Networking Game with Expert Computer Network Assignment HelpElevate Your Networking Game with Expert Computer Network Assignment Help
Elevate Your Networking Game with Expert Computer Network Assignment Help
 
Get 15% off on Computer Network Assignment Help
Get 15% off on Computer Network Assignment HelpGet 15% off on Computer Network Assignment Help
Get 15% off on Computer Network Assignment Help
 
Computer Network Assignment Help
Computer Network Assignment HelpComputer Network Assignment Help
Computer Network Assignment Help
 
Advanced Computer Network Assignment Help
Advanced Computer Network Assignment HelpAdvanced Computer Network Assignment Help
Advanced Computer Network Assignment Help
 
Computer Network Assignment Help.pptx
Computer Network Assignment Help.pptxComputer Network Assignment Help.pptx
Computer Network Assignment Help.pptx
 
Computer Network Homework Help
Computer Network Homework HelpComputer Network Homework Help
Computer Network Homework Help
 
Computer Network Homework Help
Computer Network Homework HelpComputer Network Homework Help
Computer Network Homework Help
 
Online Computer Network Security Assignment Help
Online Computer Network Security Assignment HelpOnline Computer Network Security Assignment Help
Online Computer Network Security Assignment Help
 
Computer Network Homework Help
Computer Network Homework HelpComputer Network Homework Help
Computer Network Homework Help
 
Computer Network Assignment Help
Computer Network Assignment HelpComputer Network Assignment Help
Computer Network Assignment Help
 
Computer Network Assignment Help
Computer Network Assignment HelpComputer Network Assignment Help
Computer Network Assignment Help
 
Networking Assignment Help
Networking Assignment HelpNetworking Assignment Help
Networking Assignment Help
 
Computer Network Assignment Help
Computer Network Assignment HelpComputer Network Assignment Help
Computer Network Assignment Help
 
Design & Analysis of Algorithms Assignment Help
Design & Analysis of Algorithms Assignment HelpDesign & Analysis of Algorithms Assignment Help
Design & Analysis of Algorithms Assignment Help
 
Computer Network Assignment Help
Computer Network Assignment HelpComputer Network Assignment Help
Computer Network Assignment Help
 
Proficient Computer Network Assignment Help
Proficient Computer Network Assignment HelpProficient Computer Network Assignment Help
Proficient Computer Network Assignment Help
 
Network Design Assignment Help
Network Design Assignment HelpNetwork Design Assignment Help
Network Design Assignment Help
 
Computer Networking Assignment Help
Computer Networking Assignment HelpComputer Networking Assignment Help
Computer Networking Assignment Help
 
Computer Network Assignment Help
Computer Network Assignment HelpComputer Network Assignment Help
Computer Network Assignment Help
 
Computer Network Assignment Help
Computer Network Assignment HelpComputer Network Assignment Help
Computer Network Assignment Help
 

Recently uploaded

This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIShubhangi Sonawane
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 

Recently uploaded (20)

This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 

Computer Network Assignment Help

  • 1. For any help regarding Computer Network Assignment Help Visit :- https://computernetworkassignmenthelp.com/ , Email :- support@computernetworkassignmenthelp.com or Call us at :- +1 678 648 4277
  • 2. Problem 1 For each question, choose all correct answers. (a) Which of the following are true of thread confinement? A.all privatefinalfields are confined B.all immutable values are confined C.the values of all local variables are confined D.a BlockingQueueused to implement message passing should be confined E.the view tree in a Swing GUI should be confined Solution. E. (b) Select all the strings below where the entire string is matched by the regular expression: ([a-z]+[1-9]+)*[1-9] A.bb8b8b B.r2d222 C.c3po000 D.8 E.r5d4 Solution. B, D. computernetworkassignmenthelp.com
  • 3. (c) Consider an immutable class ComplexNumfor representing complex numbers: private final double realPart; private final double imaginaryPart; // AF: represents (realPart + i * imaginaryPart) // RI: true // ... other creators, producers, observers ... public double absoluteValue() { return Math.sqrt(realPart*realPart + imaginaryPart*imaginaryPart) } @Override public boolean equals(Object other) { if (!(other instanceof ComplexNum)) { return false; } ComplexNum that = (ComplexNum)other; return this.absoluteValue() == that.absoluteValue(); } computernetworkassignmenthelp.com
  • 4. This implementation of equals... A.is reflexive B.is symmetric C.is transitive D.returns true for ComplexNum pairs that should not be equal according to the AF E.returns false for ComplexNum pairs that should be equal according to the AF Solution. A, B, C, D. □ (d) Since ServerSocket.accept() is a blocking method, we can conclude that... A.accept()will not return until a client makes a connection B.accept()will throw an exception if called when no clients are connecting C.calling accept()could prevent the program from terminating D.it is safe to call accept()simultaneously from multiple threads E.while accept() is blocking, calling other methods on the same ServerSocketinstance from other threads will block Solution. A, C. □ computernetworkassignmenthelp.com
  • 5. Problem 2 (Map/Filter/Reduce) Ben Bitdiddle is trying to select a new password for his social media accounts. Given the following interface for representing passwords: public interface Password { public String plainText(); public int strength(); } For each method below, fill in the blanks to implement the specification using map, filter, and reduce. You must use exactly two operations, but you may use the same operation twice. On each line, fill in the first blank with map, filter, or reduce, and fill in the second blank with a lambda expression. Solutions will be graded for correctness and clarity. (a) /** * @param passwords the passwords to consider * @param minStrength the minimum strength a password should have * @return the plaintext strings of passwords that have strength at least minStrength */ public static List<String> strongEnough(List<Password> passwords, int minStrength) { return passwords.stream() . ( ) . ( ) .collect(toList()); } computernetworkassignmenthelp.com
  • 6. (b) /** * @param passwords the passwords to consider * @param substring required substring * @return the plaintext strings of passwords that contain substring */ public static List<String> containing(List<Password> passwords, String substring) { return passwords.stream() . ( ) . ( ) .collect(toList()); } (c) /** * @param passwords the passwords to consider * @return the average strength of the passwords */ public static double averageStrength(List<Password> passwords) { return passwords.stream() . ( ) computernetworkassignmenthelp.com
  • 7. . (0, ) / (double)passwords.size(); } Solution. (a).filter(p -> p.strength() >= minStrength) .map(p -> p.plainText()) (b).map(p -> p.plainText()) .filter(p -> p.contains(substring)) (c).map(p -> p.length()) .reduce(0, (a,b) -> a+b) Problem 3 (Abstract Data Types) A tree is a data structure that consists of a root node and zero or more children which themselves are also trees. A binary tree is a tree in which each node has at most two children, designated left and right. For example: computernetworkassignmenthelp.com
  • 8. Simon Straightforward is an enthusiastic 6.005 student who just learned about ADTs and wants to build a class to represent binary trees of positive integers. He comes up with this internal representation: /** A binary tree of positive integers. */ public class PosIntBinaryTree { private final List<List<Integer>> nodes; } Simon wants each sub-list in nodes to represent a level in the binary tree, using 0 in place of missing elements. For example, the binary tree shown above is represented by the following list of lists: [ [ 1 ] [ 3, 5 ] [ 0, 2, 6, 4 ] ] (a) Silly Simon forgot to document his abstraction function and rep invariant! Select statements to put into the AF and RI of PosIntBinaryTree by circling the letters of all statements to include from the list below. Include all good statements that are compatible with Simon’s design. AF: A B C D E F G RI: A B C D E F G A.all 0 <= i < nodes.size(), nodes.get(i).get(0) > 0 B.if nodes.size() == 0, represents the empty tree computernetworkassignmenthelp.com
  • 9. Rob Recursive, an even more enthusiastic student, wants to represent binary trees of any integers. (b)What bad practice in Simon’s rep prevents Rob from easily extending it? Solution. Magic number 0. □ (c)Rob decides to implement the binary trees recursively, using an interface IntBinaryTree with two concrete variants, one of which represents the empty tree. He also decides the type will be immutable. /** An immutable binary tree of integers. */ public interface IntBinaryTree { ... } Write a recursive datatype definition for IntBinaryTree: Solution. IntBinaryTree = Empty() + Tree(value: int, left,right: IntBinaryTree) □ C.if nodes.size() > 0, nodes.get(0).get(0) is the root node D.nodes.get(i).size() == 2^I E.nodes.size() == 2^k for some nonnegative integer k F.for node nodes.get(i).get(j), its left child (if any) is nodes.get(i+1).get(j*2) G.for node nodes.get(i).get(j), its right child (if any) is nodes.get(i+1).get(j*2+1) Solution. AF: B, C, F, and G. RI: D. computernetworkassignmenthelp.com
  • 10. (d) Start implementing the concrete variant that represents the empty tree by writing its field declarations, abstraction function, and rep invariant. If parts of the AF or RI would normally be assumed in 6.005, write them explicitly. Fields: AF: RI: Solution. No fields AF: represents the empty immutable binary tree of integers RI: true □ (e) Start implementing the other concrete variant by writing its field declarations, abstraction function, and rep invariant. If parts of the AF or RI would normally be assumed in 6.005, write them explicitly. Fields: AF: RI: Solution. private final int value; private final IntBinaryTree left, right; AF: represents the immutable binary tree of integers with root node value, left subtree left, and right subtree right computernetworkassignmenthelp.com
  • 11. RI: left,right != null □ Problem 4 (Recursive Data Types) (20 points). A Boolean formula is a propositional expression consisting of variables, ∧ (and) and ∨ (or) binary operators, and ¬ (not) unary operators. For example, the following expression means “either P or Q is true, and either P is false or R is true”: (P ∨ Q) ∧ (¬P ∨ R) A formula is in negation normal form if the negation operator (¬) is only applied directly to variables. For example, P ∧ (¬Q ∨ R) is in negation normal form, but P ∧ ¬(Q ∨ R) and ¬(P ∧ (¬Q ∨ R)) are not. Here is a datatype definition for an ADT to represent negation normal form Boolean formulas: NegNormFormula = Variable(name: String, isNegated: boolean) + And(left: NegNormFormula, right: NegNormFormula) + Or(left: NegNormFormula, right: NegNormFormula) Now consider this specification: // returns a negation of the input formula negate : NegNormFormula -> NegNormFormula (a) Classify this operation according to our types of ADT operations: computernetworkassignmenthelp.com
  • 12. □ (b) Implement the operation. Use De Morgan’s laws and the rule for double negation: ¬(P ∧ Q) = ¬P ∨ ¬Q and ¬(P ∨ Q) = ¬P ∧ ¬Q and public class Variable implements NegNormFormula { private final String name; private final boolean isNegated; public Variable(String name, boolean isNegated) { ... } @Override public NegNormFormula negate() { ¬¬P = P Solution. return new Variable(name, ! isNegated); □ } } public class And implements NegNormFormula { private final NegNormFormula left; private final NegNormFormula right; public And(NegNormFormula left, NegNormFormula right) { ... } @Override public NegNormFormula negate() { Soluti on. return new Or(left.negated(), right.negated()); □ computernetworkassignmenthelp.com
  • 13. } } public class Or implements NegNormFormula { private final NegNormFormula left; private final NegNormFormula right; public Or(NegNormFormula left, NegNormFormula right) { ... } @Override public NegNormFormula negate() { Solution. return new And(left.negated(), right.negated()); □ } } Problem 5 (Thread Safety) It’s election season! With the tight race for president of Fictional Dystopia, you’ve been asked to develop a secure online voting system. In Fictional Dystopian elections, each voter has exactly two votes. Each voter can vote twice for the same candidate, or split their vote between two different candidates. computernetworkassignmenthelp.com public class TwoVotesEachElection { private final AtomicInteger[] voteCounts; private final Set<String> voters;
  • 14. // ... constructor initializes voteCounts to an array of AtomicIntegers, // each with value zero, and initializes voters to a threadsafe Set ... public int getNumberOfCandidates() { return voteCounts.length; } // requires: 0 <= can1, can2 < getNumberOfCandidates() // effects: if and only if the voter hasn’t already voted, casts both votes public void vote(final String voterID, final int can1, final int can2) { if (voters.contains(voterID)) { return; } voters.add(voterID); // use the atomic incrementAndGet operation // (we don’t need the "get" part, but there is no plain "increment") voteCounts[can1].incrementAndGet(); voteCounts[can2].incrementAndGet(); } // ... } Suppose election is a TwoVotesEachElection with 4 candidates (so voteCounts.length = 4). (a) Unfortunately, even though TwoVotesEachElection uses threadsafe datatypes, the vote() opera- tion is not threadsafe. Explain clearly an interleaving that violates thread safety for TwoVotesEachElection. computernetworkassignmenthelp.com
  • 15. Solution. Two threads enter votewith the same voterIDnot yet in voters. Both threads call voters.containsand obtain false, then both call voters.addsuccessfully. At this point, both threads will increment the vote counts for their can1 and can2, giving this voter 4 votes instead of 2, in violation of the postcondition. □ Louis Reasoner is convinced that using AtomicInteger is unnecessary, so he changes the code to use primitive integers instead: public class LouisTwoVotesEachElection { private final int[] voteCounts; private final Set<String> voters; // ... constructor initializes voteCounts to an array of zeros, // and initializes voters to a threadsafe Set ... public int getNumberOfCandidates() { return voteCounts.length; } // requires: 0 <= can1, can2 < getNumberOfCandidates() // effects: if and only if the voter hasn’t already voted, casts both votes public void vote(final String voterID, final int can1, final int can2) { if (voters.contains(voterID)) { return; } computernetworkassignmenthelp.com
  • 16. voters.add(voterID); voteCounts[can1]++; voteCounts[can2]++; } // ... } Of course, this just makes the problem worse. (b) Suppose 100 voters, each using a different thread, participate in our 4-candidate election by concur- rently calling Louis’ vote(). Every voter uses a unique ID, and no one casts both of their votes for the same candidate. The value of the sum voteCounts[0] + voteCounts[1] + voteCounts[2] + voteCounts[3] could be which of the following? Choose all that apply. A.0 B.1 C.2 D.4 E. 100 F. 200 G. 400 Solution. C, D, E, F. □ computernetworkassignmenthelp.com
  • 17. Solution. A, C, D. Locking on different voterID strings doesn’t help. voteCounts[0] is a primitive in Louis’ code. At least one thread will successfully increment the count for its first candidate; same for some thread and its second candidate. With no races at all, 200 votes will be counted. (c) Louis wants to fix the thread safety problems by putting all the code inside vote() in a synchronized block. Of the following objects in Louis’ version of the code, which are suitable for us to synchronize on in order to ensure thread safety for concurrent calls to vote()? Choose all that apply. A.this B.voterID C.voters D.voteCounts E.voteCounts[0] computernetworkassignmenthelp.com