You are on page 1of 18

pseudo code and

python for different


functions
computer science
AS and A2
all papers

paper 1, 2 & 3 → pseudocode


paper 4 → programing [python]
By Layan Alateeq (hope it’s useful 💜)
linear search:

pseudocode python
DECLARE myList : ARRAY[0:9] of INTEGER myList = [4, 2, 8, 17, 9, 3, 7, 12,
34, 21]
DECLARE upperBound : INTEGER

DECLARE lowerBound : INTEGER #enter an item

DECLARE index : INTEGER print(“please input the item you


want to find”)
DECLARE item : INTEGER

DECLARE found : BOOLEAN item = int(input())

upperBound ← 9 found = False

lowerBound ← 0 for x in range(len(myList))


OUTPUT (“please enter item to be
found”)
if myList[x] == item

INPUT item found = true

found ← false if found is true:


index ← lowerBound print (“item found”)
REPEAT
else:
IF item = myList[index]
print(“item not found”)
THEN

found ← TRUE

ENDIF

index ← index + 1

UNTIL (found = true) OR (index >


upperBound)

IF found

THEN

OUTPUT “item found”

ELSE

OUTPUT “item not found”

ENDIF
binary search

pseudocode python
DECLARE myList : ARRAY[0:9] of INTEGER
List = [16, 19, 21, 27, 36, 42, 55, 67, 76]
DECLARE UB : INTEGER
max = 8
DECLARE LB : INTEGER
DECLARE index : INTEGER min = 0
DECLARE item : INTEGER
print("please input the item you want to
DECLARE found : BOOLEAN find")
upperbound ← 9
itemFind = int(input())
lowerBound ← 0
OUTPUT “please enter item to find” found = False
INPUT item
index = 0
found ← False
REPEAT while found is False and min != max:

index ← INT((UB + LB)/2) index = int((max + min)/2)


IF item = myList[index]
if itemFind == List[index]:
THEN
found ← TRUE found = True
ENDIF
if itemFind < List[index]:
IF item > myList[index]
THEN max = index - 1

LB ← index + 1 if itemFind > List[index]:


ENDIF
min = index + 1
IF item < myList[index]
THEN if found is True:
UB ← index - 1
print("your item has been found in
UNTIL found = TRUE OR LB = UB this list")
IF found
if found is False:
THEN
OUTPUT “item found” print("your item was not found
in this list")
ELSE
OUTPUT “item not found”
ENDIF
bubble sort

pseudocode python
DECLARE myList : ARRAY def bubbleSort():

myList =[70,46,43,27,57,41,45,21,14]
DECLARE UB : INTEGER
top = len(myList)#9
DECLARE LB : INTEGER
swap = True
DECLARE index : INTEGER
while swap or top > 0:
DECLARE swap : BOOLEAN
swap = False

DECLARE temp : INTEGER for i in range(top - 1):

DECLARE top : INTEGER if myList[i]>myList[i+1]:

UB = 8 temp = myList[i]

myList[i] = myList[i +
LB = 0 1]

top ← UB myList[i + 1] = temp

REPEAT swap = True

top = top - 1
FOR index = LB to top-1
print(myList)
swap ← false
bubbleSort()
IF myList > myList[index +1]

myList[index +1] ← temp

swap ← true

ENDIF

NEXT

top ← top - 1

UNTIL NOT swap OR top = 0


insertion sort

pseudocode python
DECLARE myList : ARRAY[0:9] of INTEGER for index in range(LB+1, UB):

-key = myList[index]
DECLARE UB : INTEGER
-place = index - 1
DECLARE LB : INTEGER
-if myList[place] > key:
DECLARE index : INTEGER
--while place >= LB AND myList[index] > myList[index]
DECLARE key : BOOLEAN
---temp ← myList[place +1]

DECLARE place : INTEGER ---mylist[index + 1] = myList[index]

UB ← 8 ---myList[index] = temp

LB ← 0 ---index= index- 1

--myList[index + 1] = myList[index]
for index ← LB + 1 to UB:

key ← myList[index]

place ← place - 1

IF myList[place] > key

THEN

WHILE place >= LB AND myList[place]


> key

temp ← myList[place+1]

myList[place+1] ←
myList[place]

myList[place] ← temp

place = place - 1

ENDWHILE

myList[place + 1]

ENDIF

NEXT index
def menu():
MenuOption = 0
print("choose one option of the menu")
print("1. search in file")
print("2. add to file")
case format,
print("3. change from file")
print("delete from file")
print("-1. to exit menu")
searching in a
MenuOption = int(input())
if (MenuOption == 1):
def search():
liner file [python]
print("which user do you want to find?")
userID = input()
input(userID)
file = open("EMPLOYEE.txt" , "rt")
for x in file:
file(x.read(7))
list = ["ID" , "family name" , "first name" , "job description" , elif (MenuOption == 2):
"salary" , "office ID" , "contractor"] def Add():
print(list[1]) print("pleases enter the user ID")
print(list[2]) userID = input()
file.close("EMPLOYEE.txt") input(userID)
search()
file = open("EMPLOYEE.txt" , "rt")
elif (MenuOpption == 3):
def change():
for x in file:
print("which user do you want to edit?") file(x.read(7))
userID = input() while userID != file(x.read(7)):
input(userID) print(True)
OldFile = open("EMPLOYEE.txt" , "rt") file.close("EMPLOYEE.txt")
open(OldFile) folder = open("EMPLOYEE.txt" , "a")
for x in OldFile:
open(folder.write("EMPLOYEE.txt"))
line = file(x.read(7))
while userID == line:
input(line)
print(True) print("input the new userID")
print("what do you want to change from this user?") userID = input()
print("1. change family name") input(userID)
print("2. change the first name") line = (line + userID + ",")
print("3. change job description") print("input the family name")
print("4. change the salary") FamilyName = input()
print("5. change office ID")
input(FamilyName)
print("6. change if they are a contractor")
choice = int(input())
line = (line + FamilyName + ",")
if choice >= 7: print("input the first name")
print("please input your choice") FirstName = input()
elif choice <= 0: input(FirstName)
print("please input your choice") line = (line + FirstName + ",")
print("what is the new value?") print("input the job description")
NewValue = input()
JobDescription = input()
list = ["userID" , "family name" , "first name" , "job description"
, "salary" , "office ID" , "contractor"]
input(JobDescription)
NewFile = open("EMPLOYEE.txt" , "wt") line = (line + Job Description + ",")
for line in OldFile: print("input the salary")
NewFile.write(line.replace(list[choice] , NewValue) salary = int(input())
OldFile.close() input(salary)
NewFile.close() line = (line + salary + ",")
change()
print("input the office ID")
elif (MenuOption == 4)
def delete():
officeID = input()
userID = input() input(officeID)
input(userID) line = (line + officeID + ",")
file = open("EMPLOYEE.txt" , "rt") print("is the user a contractor")
for line in file: answer = input("yes" or "no")
if userID in file: if answer == ("yes"):
file.next() line = (line + "0")
else:
elif answer == ("no"):
NewFile = open("NewFile.txt" , "w")
print(line) in NewFile
line = (line + "-1")
file.close("EMPLOYEE.txt") elif answer != ("yes" or "no"):
remove("EMPLOYEE.txt") print("please enter yes or no")
os.rename("NewFile"): print(line)
rename("EMPLOYEE.txt") folder.close("EMPLOYEE.txt")
delete() Add()
Menu()
stack

pseudocode python in class format


DECLARE myStack : ARRAY[1:10] OF INTEGER class Stack:

def __init__(self, StackFull):


DECLARE topPointer : INTEGER
self.BasePointer = 0
DECLARE basePointer : INTEGER
self.TopPointer =-1

DECLARE stackFull : INTEGER self.StackFull = StackFull

self.item = ""
basePointer ← 1
self.stack = []
topPointer ← 0
for i in range (StackFull):

stackFull ← 10 self.stack.append(0)

#insert: [push] #insert: [push]

def push(self, item):


IF topPointer < stackfull
if self.TopPointer < self.StackFull - 1:
THEN
self.TopPointer = self.TopPointer + 1

topPointer ← topPointer + 1 self.stack[self.TopPointer] = item

myStack[topPointer] ← item else:

print("stack is full, you cannot push more


ELSE values")

#remove: [pop]
OUTPUT “stack is full, cannot push”
def pop(self):
ENDIF
if self.TopPointer == self.BasePointer - 1:

#remove: [pop] print("stack is empty, you cannot pop more


values")

IF topPointer = basePointer - 1 else:

THEN self.stack[self.TopPointer] = 0

self.TopPointer = self.TopPointer - 1
OUTPUT “stack is empty< cannot pop”
def Print(self):
ELSE
for i in range (self.StackFull):

item ← myStack[topPointer] print (self.stack[i])

MyStack = Stack(9)
topPointer ← topPointer - 1
MyStack.Print()
ENDIF
Mypop(5)
Queue

pseudocode python in class format


DECLARE queue ARRAY[1:10] OF INTEGER class Queue:

DECLARE rearPointer : INTEGER def __init__(self, QueueFull):

self.queue = []
DECLARE frontPointer : INTEGER
self.FrontPointer = 0
DECLARE queueFull : INTEGER
self.Rearpointer = -1
DECLARE queueLength : INTEGER
self.QueueFull = QueueFull
frontPointer ← 1
self.QueueLength = 0
endPointer ← 0
for i in range (QueueFull):
UB ← 10 self.queue.append(0)
queueFull ← 10 def EnQueue(self, item):
queueLength ← 0 if self.QueueLength < self.QueueFull:

#insert: [enqueue] if self.Rearpointer < self.QueueLength + 1:

IF queueLength < queueFull self.Rearpointer = self.Rearpointer + 1

THEN else:

self.Rearpointer = 0
IF rearPointer < upperBound
self.QueueLength = self.QueueLength + 1
rearPointer ← rearPointer + 1
self.queue[self.Rearpointer] = item
ELSE
else:
rearPointer ← 1
it's full") print("you cannot en-queue the queue because
ENDIF
def DeQueue(self):
queueLength ← queueLength + 1
if self.QueueLength == 0:
queue[rearPointer] ← item
print("the queue is empty you cannot dequeue")
ELSE else:
OUTPUT “queue is full, cannot enqueue” item = self.queue[self.FrontPointer]
ENDIF self.queue[self.FrontPointer] = 0

#remove: [dequeue] if self.FrontPointer == self.QueueLength - 1:

IF queueLength = 0 self.FrontPointer = 0

else:
THEN
self.FrontPointer = self.FrontPointer +1
OUTPUT “queue empty, cannot dequeue”
self.QueueLength = self.QueueLength -1
ELSE
return item
item ← queue[frontPointer]
def Print(self):
IF frontPointer = UB
for i in range (self.QueueFull):
THEN print (self.queue[i])
frontPointer ← 1 MyQueue = Queue(10)
ELSE MyQueue.EnQueue(10)

frontPointer ← frontPointer + 1 Value = My Queue.DeQueue()

ENDIF MyQueue.Print()

queueLength ← queueLength - 1 print("deleted item:", Value)

ENDIF
bubble sort
DECLARE myList : ARRAY[0:8] OF INTEGER #bubble sort function

DECLARE UB : INTEGER def bubbleSort(myList):

DECLARE LB : INTEGER for i in range (0, 10):

DECLARE index : INTEGER for n in range(0, 9):

DECLARE swap : BOOLEAN if theArray[n] > theArray[n + 1]:

DECLARE temp : INTEGER temp = theArray[n]

DECLARE top : INTEGER myList[n] = theArray[n + 1]

UB ← 8 myList[n + 1] = temp

LB ← 0

top ← UB #sort from smallest to biggest

REPEAT def SmallToBig(NumberList,number):

FOR index = LB TO TOP - 1 #DECLARE Swapped as BOOLEAN

swap ← FALSE Swapped = False

IF myList[index] > myList[index + 1] while Swapped == False:

THEN Swapped = True

temp ← myList[index] #DECALRE i as INTEGER

myList[index] ← myList[index +1] for i in range(0,number-1):

myList[index] ← temp if NumberList[i]>NumberList[i+1]:

ENDIF Swapped = False

NEXT #DECALRE TempPosition as INTEGER

top ← top - 1 TempPosition = NumberList[i]

UNTIL NOT swap OR top = 0 NumberList[i] = NumberList [i + 1]

NumberList[i + 1] = TempPosition

print("Sorted numbers: ", NumberList)

#sorts from largest to smallest

def BigToSmall(NumberList,number):

Swapped = False

while Swapped == False:

Swapped = True

#DECALRE i as INTEGER

for i in range(0,number-1):

if NumberList[i]< NumberList[i+1]:

Swapped = False

#DECALRE TempPosition as INTEGER

TempPosition = NumberList[i+1]

NumberList[i+1] = NumberList [i]

NumberList[i] = TempPosition

print("Sorted numbers: ", NumberList)


binary tree #adding to the leftPointer

elif self.myTree[self.index].Data > itemAdd:

if self.myTree[self.index].leftPointer == -1:#checks if its empty

class node: self.myTree[self.itemPointer].upPointer = self.index

def __init__ (self, itemAdd): self.myTree[self.index].leftPointer = self.itemPointer#changes the

self.leftPointer = -1 #its empty and its pointing at the right element self.added = True

self.Data = itemAdd #if there is an item in the left pointer

self.rightPointer = -1 #its empty and its pointing to the left element else:

self.upPointer = -1
else:
self.checkedLeft = False
self.index = self.myTree[self.index].leftPointer #moves it to the
self.checkedRight = False next left element

class tree:
#if the item already exists
def __init__(self, itemAdd,):
elif self.myTree[self.index].Data == itemAdd:
self.oldPointer = 0 #pointer pointing at the last data
self.added = True
self.myTree = [] #binary tree

self.length = 8 #how long the binary tree can be print("this item already exists")

self.rootPointer = 0 #pointing at the very first element


else:
self.itemPointer = 0 #pointing at the inserted item
print("sorry this item already exisits")
itemData = node(itemAdd)
else:
self.index = 0 #where it moves next to check where to add

self.freePointer = 1 #where the next empty space is print("cannot add anymore items because the list is full")

self.treeFull = 9 #how long till it stops


#finding an item from the leaf
self.myTree.append(itemData)
def search(self, itemFind):

self.found = False
#adding an item into the leaf

def addLeaf(self, itemAdd): self.index = 0

if self.freePointer < self.treeFull - 1: #check i fthe tree is full


while self.found is False:
self.stop = False
if self.myTree[self.index].Data == itemFind:
for i in range(len(self.myTree)):
print("the item: ", itemFind, " was found in the tree")
if self.myTree[i].Data == itemAdd:

self.stop = True self.found = True

if self.stop is False: elif self.myTree[self.index].Data < itemFind:


itemData = node(itemAdd)
if self.myTree[self.index].rightPointer == -1:
self.myTree.append(itemData)
print("the item: ", itemFind, " was NOT found in the tree")
self.itemPointer = self.freePointer #adds the new item in the free pointer position

self.freePointer = self.freePointer + 1 self.found = True

self.added = False else:


self.index = 0
self.index = self.myTree[self.index].rightPointer
self.LastPointer = 0
elif self.myTree[self.index].Data > itemFind:

while self.added is False:#a loop that stops when the item is added or repeated if self.myTree[self.index].leftPointer == -1:
{the two have to be obayed otherwise }

#adding to the right pointer print("that item: ", itemFind, " was NOT found in the tree")

if self.myTree[self.index].Data < itemAdd: self.found = True

else:
if self.myTree[self.index].rightPointer == -1:
self.index = self.myTree[self.index].leftPointer
self.myTree[self.itemPointer].upPointer = self.index

self.myTree[self.index].rightPointer = self.itemPointer

self.added = True

#if there is an item in the right pointer

else:

self.index = self.myTree[self.index].rightPointer #moves it to the right


Binary tree continuation
#ordering a leaf from smallest to largest
def find(self):
def ordering(self):

self.found = False
self.stop = False

self.index = 0 self.index = 0

while self.stop is False:


while self.found is False:

if self.myTree[self.index].Data == itemAdd:
#[3 5 ? F]

self.found = True if self.myTree[self.index].leftPointer != -1 and self.myTree[self.index].checkedLeft is False:

self.myTree[self.index].checkedLeft = True
elif self.myTree[self.index].Data < itemAdd:
self.index = self.myTree[self.index].leftPointer

if self.myTree[self.index].rightPointer == -1:

self.found = True #[-1 5 ? F/T]

else:
else:
if self.myTree[self.index].checkedRight is False:

self.index = self.myTree[self.index].leftPointer print(self.myTree[self.index].Data)

elif self.myTree[self.index].Data > itemAdd:


#[-1 5 3 F]
self.found = True
if self.myTree[self.index].rightPointer != -1 and self.myTree[self.index].checkedRight is False:

self.myTree[self.index].checkedRight = True

self.index = self.myTree[self.index].rightPointer

#[-1 5 -1 F/T]

else:

self.index = self.myTree[self.index].upPointer

if self.index == 0 and self.myTree[self.index].checkedRight is True:

self.stop = True

def printTree(self):

for i in range(len(self.myTree)):

print(self.myTree[i].leftPointer, self.myTree[i].Data, self.myTree[i].rightPointer, self.myTree[i].upPointer)


elif self.list[self.index].Pointer == -1 and itemAdd > self.list[self.index].Data:#last #correct

linked list self.list[self.index].Pointer = self.itemPointer

self.added = True
#defining my node
else:
class node():
self.backPointer = self.index
def __init__(self, itemAdd):
self.index = self.list[self.index].Pointer
self.Data = itemAdd
#deleting an item
self.Pointer = -1
def delete(self, itemDelete):
#making my class
self.deleted = False #deleted - to stop the loop
class linkedList():
self.tempPointer = 0 #temp pointer
def __init__(self, itemAdd):
self.index = self.startPointer
itemData = node(itemAdd)
while self.deleted is False:
self.list = [] #the linked list
if itemDelete == self.list[self.index].Data:

self.index = 0 #the one thats moving{changing constantly}


if self.index == self.startPointer:#first

self.itemPointer = 0 #pointing at the item added


self.startPointer = self.list[self.index].Pointer

self.nextEmptyPointer = 0 #the next place thats they can add an element to


self.list[self.index].Pointer = -1

self.list.append(itemData) #adding the first element


self.deleted =True

self.startPointer = 0
elif self.list[self.index].Pointer == -1:#last

#adding an inserting an item


self.list[self.index].Pointer = -1 #make it empty

def adding(self, itemAdd):


self.list[self.backPointer].Pointer = -1 #stop pointing at it

self.added = False #added - is to stop the loop


self.deleted =True

self.index = self.startPointer
else: #middle

itemData = node(itemAdd)
self.tempPointer = self.list[self.index].Pointer

self.list.append(itemData)
self.list[self.backPointer ].Pointer = self.tempPointer

self.nextEmptyPointer = self.nextEmptyPointer + 1
self.list[self.index].Pointer = -1

self.itemPointer = self.nextEmptyPointer
self.deleted = True

else:

while self.added is False:


if self.index == -1:#if the item doesnt exisit

if self.index == self.startPointer and itemAdd <


self.list[self.startPointer].Data:#first print("you cannot delete an item that doesn't exist")

self.list[self.itemPointer].Pointer = self.index self.deleted =True

self.startPointer = self.itemPointer# else:

self.added = True self.backPointer = self.index

self.index = self.list[self.index].Pointer

elif itemAdd < self.list[self.index].Data:#middle #printing in order

self.index = self.backPointer def printList(self):

self.tempPointer = self.list[self.index].Pointer self.index = self.startPointer

while self.index != -1:


self.list[self.index].Pointer = self.itemPointer

print(self.list[self.index].Data)
self.list[self.itemPointer].Pointer = self.tempPointer

self.index = self.list[self.index].Pointer
self.added = True

print(self.list[self.index].Data)
binary search in recursion
class node:
def __init__(self):
self.data = 0
self.leftPointer = -1
self.rightPointer = -1

class tree:
def __init__(self):
self.freePointer = 0
self.rootPointer = -1
self.max = 10
self.binaryTree = [node() for i in range(self.max)]

def insert(self, item):


if self.freePointer >= self.max:
print("Tree is full.")
else:
if self.rootPointer == -1 :
self.rootPointer += 1
self.binaryTree[self.rootPointer].data = item
else:
Placed = False
index = self.rootPointer
while Placed == False:
if item < self.binaryTree[index].data:
if self.binaryTree[index].leftPointer == -1:
self.binaryTree[index].leftPointer = self.freePointer
self.binaryTree[self.freePointer].data = item

Placed = True
else:
index = self.binaryTree[index].leftPointer
else:
if self.binaryTree[index].rightPointer == -1:
self.binaryTree[index].rightPointer = self.freePointer
self.binaryTree[self.freePointer].data = item

Placed = True
else:
index = self.binaryTree[index].rightPointer
self.freePointer += 1

def search(self, searchItem):


while self.item != searchItem:
if searchItem < self.item:
self.item = self.leftPointer
else:
self.item = self.rightPointer
if self.item is None:
return None
return self.item

def printData(self):
line = ""
leftPointer = 0
rightPointer = 0
nodeData = 0
for n in range(0, self.max):
leftPointer = self.binaryTree[n].leftPointer
nodeData = self.binaryTree[n].data
rightPointer = self.binaryTree[n].rightPointer
line += str(leftPointer) + "," + str(nodeData) + "," + str(rightPointer)
print(line)
line = ""
binary search in recursion continuation
def getRootPointer(self):
return self.rootPointer

def getBinaryTree(self):
return self.binaryTree

#in order: left node right

def inOrder(self,Pointer):
if Pointer == -1:
return
if self.binaryTree[Pointer].leftPointer != -1:
self.inOrder(self.binaryTree[Pointer].leftPointer)
print(self.binaryTree[Pointer].data)
if self.binaryTree[Pointer].rightPointer != -1:
self.inOrder(self.binaryTree[Pointer].rightPointer)

myTree = tree()

myTree.insert(15)
myTree.insert(4)
myTree.insert(27)
myTree.insert(20)
myTree.insert(2)
myTree.insert(20)
myTree.insert(25)
myTree.insert(1)
myTree.insert(3)
myTree.insert(16)

myTree.printData()

rootPointer = myTree.getRootPointer()
print("Binary Tree in order: ")
myTree.inOrder(rootPointer)

credits to mellissa for the binary tree using recursion


pseudocode
IF - for single choice w alternative CASE - for multiple choices w alternative
IF Value1 > Value2 CASE OF direction
THEN “N” ← Y + 1
OUTPUT “V1 “S” ← Y - 1
ELSE OTHERWISE : OUTPUT “error”
OUTPUT “V2”
ENDIF

REPEAT, UNTIL - happens at least once FOR, NEXT - repeats for certain number of
REPEAT times
OUTPUT ”please enter a positive value” FOR counter ← TO 10 STEP 2
INPUT number OUTPUT counter
UNTIL number > 0 NEXT counter

WHILE, DO - can not happen at all record format:


number ← 0 TYPE
WHILE number = 0 DO <type neme>
OUTPUT “please enter negative value” DECLARE <identifier> : <data type>
INPUT number DECLARE <identifier> : <data type>
ENDWHILE ENDTYPE

data type:
BOOLEAN → true or false statement
CHAR → single alphanumeric value
DATE → value to represent date
INTEGER → whole number with positive or negative
REAL → positive or negative number with a decimal point
STRING → sequence of alphanumeric values

OPEN <file identifier> FOR <file mode>

file modes:
READ → only reads from the file
WRITE → writes data in the file and any other data can be overwritten
APPEND → adds data to the end of the file
EOF(<file identifier>) → end of your selected file
CLOSEFILE(<file identifier>) → closes the file

to declare a statement:
DECLARE <suitable name> : <data type>

READFILE <file identifier>, Variable

WRITEFILE <file identifier>, <variable>


python
if - for single choice w alternative Try and except format:
Try:
if Value1 > Value2: File.open(“file.txt”, “r”)
print(“Value1”) File.readline() =0
else: except:
print(“Value2”) FileNotFoundError
Print(“file not found”)

while - can not happen at all

number ← 0
while number = 0 :
print(“please enter negative value”) for - repeats for certain number of times
int(input(number))
for counter in range(9):
print(counter)

data type:
class format:
bool → true or false statement
class AppleTree
class date → value to represent date[in class format]
def __init__ (self):
int → whole number with positive or negative
self.red = 0
float → positive or negative number with a decimal point
self.yellow = 0
str → sequence of alphanumeric values
subclass format:
[] → array / list
def tree1(self):
Making attribute privet:
open(“file name”,w+)append.file
Def __init__applw(self)
Self._yellow =yellow
file.readline() inheritance of class:
class kitchen:
def __init__(self, food, water):
file.append(<what you want to add>)
self._Food = food
self._Water = water
how to set a value to something: class house(kitchen):
value = value + 1 def__init__(self, food, water,
table):
super().__init__(water, food):
eof(<fthe name file.txt>) → end of your selected file
self._table = Table
close.(<the name file.txt>) → closes the file
recursion:
file modes: function(a):
readline→ only reads from the file if a = b:
w+→ writes data in the file and any other data can be overwritten return
append→ adds data to the end of the file else:
return function(a)
remember to declare things as comments
SQL
SQL maintenance commands [DML]:
INSERT INTO → adds new rows in the table
DELETE FROM → removes rows from the table
UPDATE → edits rows in the table

SQL query command [DML]:


SELECT FROM → fetches data from the database
WHERE → includes only rows in a query that match a given condition
ORDER BY → sorts the result from a query either alphabetically or numerically
GROUP BY → arrange data into groups
INNER JOIN → Combines rows from different tables if the join condition is true
SUM → Returns the sum of all values in the column
COUNT → Counts the number of rows where the column is not NUL
AVG → returns the average value for a column

data types:
CHARACTER → fixed length text
VARCHAR → variable length text
BOOLEAN → true or false, SQL uses the 0’s and 1’s
REAL → number with decimal places
INTEGER → number with decimal places
DATE → a date usually formatted YYYY-MM-DD
TIME → a time format as HH:MM:SS

SQL commands [DDL]:


CREATE DATABASE → creates a database
CREATE TABLE → creates a table definition
ALTER TABLE → changes the definition of the table
PRIMARY KEY → adds a primary key to a table
FORIEGN KEY … REFERENCES … → a foigian key to add to the table

SELECT SUM (number) DELETE FROM letters the order:


FROM NumberList WHERE letter = b
SELECT something
the sum part means you are FROM ItsList
selecting the whole of the INSERT INTO letters(a, b, c) WHERE TheirPointer = 0
database. VALUES (d, e, f) ORDER BY
describe what happens in bubble sort:

1. a method of sorting data in an array into alphabetical or numerical order


2. each array element is compared with the next element and swapped if their in the wrong
order
3. this is repeated with one less element until it has one element left then there is no swaps
made
4. we can use a FOR loop to use bubble sort

describe linked lists:

1. its a list containing several items in which each item in the list points to the next item in the
list
2. we can create a linked this using 2 1D arrays, one for the list of items and the other for
their pointer
3. we should be able to add and remove items
4. the empty positions in the array should be managed usually called heap

what is recursion
its basically calling a function within a function as a loop

You might also like