SophiaPretty

(5)

$14/per page/Negotiable

About SophiaPretty

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Accounting,Algebra See all
Accounting,Algebra,Applied Sciences,Architecture and Design,Art & Design,Biology,Business & Finance,Calculus,Chemistry,Communications,Computer Science,Economics,Engineering,English,Environmental science,Essay writing Hide all
Teaching Since: Jul 2017
Last Sign in: 304 Weeks Ago, 2 Days Ago
Questions Answered: 15833
Tutorials Posted: 15827

Education

  • MBA,PHD, Juris Doctor
    Strayer,Devery,Harvard University
    Mar-1995 - Mar-2002

Experience

  • Manager Planning
    WalMart
    Mar-2001 - Feb-2009

Category > Computer Science Posted 04 Dec 2017 My Price 8.00

document that is attached is a guidance document expected output.

YOU ONLY HAVE TO PLACE THE CODE WHERE IT SAYS <your code> in useGraph.py document that is attached. Written is a guidance document and an expected output.


Programming Activity 8 - Guidance
=================================

Files in the same folder
------------------------
Depending on which implementation you use for part 1,
you may need to include other files in the same folder.

Imports
-------
Depending on which implementation you use for part 1,
you may need to include additional import statement(s).

Part 1
------
This week's example files include 2 different implementations of this function.
Choose one and copy that implementation here.

Part 2
------
The courses and their prerequisites are shown in a comment.
The courses are each named with a single capital letter.

Part 3
------
The courses and their prerequisites are shown in a comment.

Part 4
------
Use an appropriate graph iterator.

Part 5
------
Use an appropriate graph iterator.

Part 6
------
If you used the stack-based implementation of the topologicalSort() function,
it can produce a different, correct ordering for each run of your program.

The following are some of the possible correct orderings:
B A C E D F G H
A C E B D F G H
A B C E D F G H
A B C D F E G H
B A C D F E G H

++++++++++++++++++++++++++++++++++++++++++++++++++++

++++++++++++++++++++++++++++++++++++++++++++++++++++

THIS IS THE EXPECTED OUTPUT
Graph:
8 Vertices:  H A B C E D F G
12 Edges:  A>C:0 A>D:0 B>D:0 B>F:0 C>D:0 C>E:0 C>H:0 E>G:0 D>F:0 F>G:0 F>H:0 G>H:0

Courses:
H
A
B
C
E
D
F
G

Prerequisites:
A>C:0
A>D:0
B>D:0
B>F:0
C>D:0
C>E:0
C>H:0
E>G:0
D>F:0
F>G:0
F>H:0
G>H:0

One possible order to take the courses:
B A C E D F G H
 

"""
File: abstractcollection.py
Copyright 2015 by Ken Lambert

"""

class AbstractCollection(object):
    """An abstract collection implementation."""

    # Constructor
    def __init__(self, sourceCollection = None):
        """Sets the initial state of self, which includes the
        contents of sourceCollection, if it's present."""
        self._size = 0
        self._modCount = 0
        if sourceCollection:
            for item in sourceCollection:
                self.add(item)

    # Accessor methods
    def isEmpty(self):
        """Returns True if len(self) == 0, or False otherwise."""
        return len(self) == 0
   
    def __len__(self):
        """Returns the number of items in self."""
        return self._size

    def __str__(self):
        """Returns the string representation of self, using []
        as delimiters."""
        return "[" + ", ".join(map(str, self)) + "]"

    def __eq__(self, other):
        """Returns True if self equals other,
        or False otherwise.
        Compares pairs of items in the two sequences
        generated by the iterators on self and other."""
        if self is other: return True
        if type(self) != type(other) or \
           len(self) != len(other):
            return False
        otherIter = iter(other)
        for item in self:
            if item != next(otherIter):
                return False
        return True

    def __add__(self, other):
        """Returns a new collection containing the contents
        of self and other."""
        result = type(self)(self)
        for item in other:
            result.add(item)
        return result

    def count(self, item):
        """Returns the number of instance of item in self."""
        counter = 0
        for nextItem in self:
            if item == nextItem: counter += 1
        return counter

    # These methods track and update the modCount, which is used to
    # prevent mutations within the context of an iterator (for loop)

    def getModCount(self):
        """Returns the number of modifications to the collection."""
        return self._modCount

    def incModCount(self):
        """Increments the number of modifications to the collection."""
        self._modCount += 1



 

# This program exercises graphs.

 

# Replace any "<your code>" comments with your own code statement(s)

# to accomplish the specified task.

# Do not change any other code.

 

# The following files must be in the same folder:

#  abstractcollection.py

#  graph.py

 

from graph import LinkedDirectedGraph

 

# Part 1:

# Complete the following function:

def topologicalSort(graph): 

    # <your code>

 

graph = LinkedDirectedGraph()

 

# The graph represents the following course prerequisites:

# A requires nothing

# B requires nothing

# C requires A

# D requires A, B, and C

# E requires C

# F requires B and D

# G requires E and F

# H requires C, F, and G

 

# Part 2:

# Add the vertices:

# <your code>

 

# Part 3:

# Add the edges:

# <your code>

 

print("Graph:")

print(graph)

print()

 

print("Courses:")

# Part 4:

# Display each vertex on a separate line:

# <your code>

print()

 

print("Prerequisites:")

# Part 5:

# Display each edge on a separate line:

# <your code>

print()

 

print("One possible order to take the courses:")

# Part 6:

# Display the courses in prerequisite (topological) order:

# <your code>

print()

 

Answers

(5)
Status NEW Posted 04 Dec 2017 11:12 AM My Price 8.00

-----------  ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly

Not Rated(0)