Cs P2 common Flashcards
Examples of sorting algorithms
Bubble, merge, insertion sort
Searching algorithms
linear, binary
MOD and DIV
DIV // whole number
MOD % reminder
File handling
myfile = open(“nameFile.txt” , “r”)
print(myfile,readlines())
myFile.close()
myfile = open(“asdf.txt” , “w”)
myfile.write(“asdfgrad”)
myfile.close()
myfile = open(“filename.txt” , “a”)
myfile.write(“dfsgsg”)
myfile.close()
1D Arrays
Store multiple data values like list X[0] to call on the list
[“fdgdfgh” , “dfsdfgg” , “sdfsgyj”]
X.insert(1,”abcdefg”)
Subprograms
Translators
High level low level
IDE
Bubble sort
Compare first two items in list and swap if not in same order do same for 2nd and 3rd and so on until reached end of list called on pass. Keep doing passes until a pass results in no swaps
Simple but inefficient for large lists
Insertion sort
Compare second item to first item and insert it into the right order then look at 3rd item and insert it into right place and so on until you reach the last item
Merge sort
uses facts that small lists are easier to sort and sorted lists are easier to merge
More efficient than insertion for larger lists
Same run time no matter complexity of list
Slower for short lists compared to others
Takes the same amount of time if the whole list is sorted
What is casting
changing data type
String manipulation
upper(x)
lower(x)
len(x)
2D array
List of list [ [“pine” , “elm”] , [“asd” , “sdfa”] , [“asfl”, “lepd”]]
Call on them with X[0,1] being elm