Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Find an algorithm, develop the data structures, and implement and test a solutio

ID: 656073 • Letter: F

Question

Find an algorithm, develop the data structures, and implement and test a solution in Python.

The problem is simple to state: you will be given the URL for a wikipedia page (e.g., http://en.wikipedia.org/wiki/Philosophy) and a number n. Your job will be to find n loops in the graph of wikipedia pages. Each path must start with the given page and must include a loop that goes back to some node along the path (not necessarily all the way back to the starting page). For example, here is a path starting at 'Philosophy' that includes one loop going back to 'Algorithm':

http://en.wikipedia.org/wiki/Philosophy

http://en.wikipedia.org/wiki/Mathematics

http://en.wikipedia.org/wiki/Algorithm

http://en.wikipedia.org/wiki/Boolean_algebra

http://en.wikipedia.org/wiki/Google

http://en.wikipedia.org/wiki/Gesture_recognition

http://en.wikipedia.org/wiki/Algorithm

Explanation / Answer

algorithm for Insertion sort

def InsertionSort(A)

for j in range(l,len(A))

key=A[j]

i=j-1

while(i>=0)&(A[i]>key)

A[i+1}=A[i]

i=i-1

A[i+1]=key

algorithm for heap sort

def Parent(j) : return j/2

def Left(j) : return 2*j

def Right(j) : return 2*j+1

def Heapify (A,j,n)

l=Left(j)

r=Right(j)

if j<=n & A[l]>A[j] : largest=l

else : largest=j

if j<=n & A[r]>A[j] : largest=r

else : largest=j

if largest !=j

A[j],A[largest]=A[largest],A[j];

Heapify (A,largest,n)

def HeapLength(A): return len(A)-1

def BuildHeap(A)

n=HeapLength(A)

for j in range(n/2,0,-1)

Heapify(A,j,n)

def HeapSort(A)

BuildHeap(A)

HeapSize=HeapLength(A)

for j in range (HeapSize-1);

A[1],A[j]=A[j],A[1]

HeapSize=HeapSize-1

Heapify(a,1,HeapSize)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote