Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Module4_Labs/Lab2_Doubly_Linked_List/Cards/5-CHECKPOINT
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Name: Insertion in list excercise grading
Instruction: Submit your code to be graded
Type: Autograder
3 changes: 3 additions & 0 deletions Module4_Labs/Lab3_File_System/Cards/3-CHECKPOINT
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Name: Lab 4.3 Grading
Instruction: Submit your code to have it graded
Type: Autograder
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
from math import log
from math import sqrt
import csv
def assignRankings(equations):
# rank values descending order
rankings = []
while (not max(equations) == -1):
nextValue = max(equations)
index = equations.index(nextValue) # find index
rankings.append(index)
equations[index] = -1
# get ascending order
rankings.reverse()
return rankings
def bubbleSort(arr):
n = len(arr)
print(arr)
# Traverse through all array elements
for i in range(n):
# Last i elements are already in place
for j in range(0, n-i-1):
# traverse the array from 0 to n-i-1
# Swap if the element found is greater
# than the next element
if (arr[j] > arr[j+1]):
arr[j], arr[j+1] = arr[j+1], arr[j]
print(arr)
# Function to do insertion sort
def insertionSort(arr):
# Traverse through 1 to len(arr)
for i in range(1, len(arr)):
key = arr[i]
# Move elements of arr[0..i-1], that are
# greater than key, to one position ahead
# of their current position
j = i-1
while j >= 0 and key < arr[j] :
arr[j + 1] = arr[j]
j -= 1
arr[j + 1] = key
print(arr)
def selectionSort(arr):
# Traverse through all array elements
for i in range(len(arr)):
# Find the minimum element in remaining
# unsorted array
min_idx = i
for j in range(i+1, len(arr)):
if arr[min_idx] > arr[j]:
min_idx = j
# Swap the found minimum element with
# the first element
arr[i], arr[min_idx] = arr[min_idx], arr[i]
print(arr)
def readFileintoDict():
filename= “Animals.txt”
with open(filename, ‘r’) as file:
result = {}
index = 0
for line in file.read().split(“\n”):
noTabs = line.split(“\t”)
lastElement = noTabs[len(noTabs) - 1]
result[index] = lastElement
index += 1
return result
def main():
n = 1
equations = [
n**2,
20*n**2+5*n+7,
n+log(n)+7,
3**n,
log(n)/(n**2),
(n+1)/(sqrt(1+n**2)),
(n**n)/(sqrt(log(n**4))+10),
n*log(n**2),
6**n,
sqrt(log(n)),
n**n,
n**3*log(n)+100,
sqrt(n**3),
n**3,
(n+1)/(sqrt(1+n**2))
]
animals = readFileintoDict() # animals = {index : animalName}
ranks = assignRankings(equations.copy()) # ranks = {index : rank}
for i in range(len(ranks)):
print(animals[ranks[i]])
invalidInput=True
while (invalidInput):
print(“Please chose a sorting method:“)
print(“1.(Bubble) Sort”)
print(“2.(Insertion) Sort”)
print(“3.(Selection) Sort”)
x=input(“”)
if(x==“1”or x==“bubble”):
bubbleSort(ranks.copy())
invalidInput=False
elif(x==“2”or x==“insertion”):
insertionSort(ranks.copy())
invalidInput=False
elif(x==“3”or x==“selection”):
selectionSort(ranks.copy())
invalidInput=False
else:
print(“Not a valid input, try again.“)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
do stuff
25 changes: 25 additions & 0 deletions Module4_Labs/concepts/introToGraphs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
There are two types of graphs - undirected and directed.

The following is an example of a directed graph:

![alt text](https://computersciencewiki.org/images/c/c6/Directed_graph.png)

Here is an example of an undirected graph:

![alt text](https://pediaa.com/wp-content/uploads/2019/01/Difference-Between-Directed-and-Undirected-Graph_Figure-2.png)

The key difference between these two graphs is that directed graphs have an arrow on their edges which point to the direction of that edge
while undirected graphs do not.

Graphs can be used to represent a variety of things. They are used to represent networks like a newtwork of airplane routes or a network of
water pipes. They are also used in social media like Facebook to represent connections between users.

Graphs are commonly stored in two different ways: adjacency lists and adjacency matrices.

The adjacency list of a given node is the list of all other nodes that are adjacent to that node.
An adjacency matrix is a 2D array of size NxN where N is the number of nodes in the graph. In each cell of the array there is either a
1 or a 0 to represent if the node is adjacent or not.

Adjacency lists take up less space than adjacency matrices, but are slower in determining whether or not a node has an edge to another.