Buffer:
In Memory:
A buffer is a container to hold data for a short period of time, when more comes in at any given time than a consumer can use / process.
It's a first-in, first-out situation.
The data comes in, might be buffered, and goes out in the same order it came in, after a while.
A cache is a storage for speeding up certain operations.
Things get put in a cache, and should be retrieved from it multiple times, over and over again.
There's no "flowing through the cache" kind of mechanism - data doesn't come in and go out in the same order - but it's just a holding container.
The order might be anything, really - items are addressed via a key, they don't "flow through" but they are "put in" and stay there (until they're thrown out because of not being used, or because the system goes down)
Definition:
A function that is defined in terms of it's self referential expression.
This means:
A function will continue to call itself until a condition is met to retrun a value.
All rucursive funtions have 2 parts:
def factorial_recursive_function(n):
if n == 0:
return 1
if n == 1:
return 1
return n * factorial_recursive_function(n - 1)
Or a cleaner way to write this would be:
def factorial_recursive_function(n):
if n <= 1:
return 1
return n * factorial_recursive_function(n - 1)
An example problem to solve this would be:
Have the function add up all the numbers from 1 to num.
If the input is 4 then your program should return 10 because 1 + 2 + 3 + 4 = 10.
For the test cases, the parameter num will be any number from 1 to 1000.
Examples:
Input: 12
Output: 78
Input: 140
Output: 9870
def simple_adding(num):
if num <= 1:
return 1
else:
return num + simple_adding(num - 1)
O(n^2)
def selectionSort(lyst):
i = 0
while i < len(lyst) - 1: # Do n - 1 searches
minIndex = i # for the smallest
j = i + 1
while j < len(lyst): # Start a search
if lyst[j] < lyst[minIndex]:
minIndex = j
j += 1
if minIndex != i: # Exchange if needed
swap(lyst, minIndex, i)
i += 1
O(n^2)
def bubbleSort(lyst):
n = len(lyst)
while n > 1: # Do n - 1 bubbles
i = 1 # Start each bubble
while i < n:
if lyst[i] < lyst[i - 1]: # Exchange if needed
swap(lyst, i, i - 1)
i += 1
n -= 1
or
O(n^2)
def bubbleSortWithTweak(lyst):
n = len(lyst)
while n > 1:
swapped = False
i = 1
while i < n:
# Exchange if needed
if lyst[i] < lyst[i - 1]:
swap(lyst, i, i - 1)
swapped = True
i += 1
if not swapped:
# Return if no swaps
return
n -= 1
O(n^2)
def insertionSort(lyst):
i = 1
while i < len(lyst):
itemToInsert = lyst[i]
j = i - 1
while j >= 0:
if itemToInsert < lyst[j]:
lyst[j + 1] = lyst[j]
j -= 1
else:
break
lyst[j + 1] = itemToInsert
i += 1
def quicksort(lyst):
quicksortHelper(lyst, 0, len(lyst) - 1)
def quicksortHelper(lyst, left, right):
if left < right:
pivotLocation = partition(lyst, left, right)
quicksortHelper(lyst, left, pivotLocation - 1)
quicksortHelper(lyst, pivotLocation + 1, right)
def partition(lyst, left, right):
# Find the pivot and exchange it with the last item
middle = (left + right) // 2
pivot = lyst[middle]
lyst[middle] = lyst[right]
lyst[right] = pivot
# Set boundary point to first position
boundary = left
# Move items less than pivot to the left
for index in range(left, right):
if lyst[index] < pivot:
swap(lyst, index, boundary)
boundary += 1
# Exchange the pivot item and the boundary item
swap(lyst, right, boundary)
return boundary
# Earlier definition of the swap function goes here
import random
def main(size = 20, sort = quicksort):
lyst = []
for count in range(size):
lyst.append(random.randint(1, size + 1))
print(lyst)
sort(lyst)
print(lyst)
if __name__ == "__main__":
main()
p. 74
from arrays import Array
def mergeSort(lyst):
# lyst list being sorted
# copyBuffer temporary space needed during merge
copyBuffer = Array(len(lyst))
mergeSortHelper(lyst, copyBuffer, 0, len(lyst) - 1)
def mergeSortHelper(lyst, copyBuffer, low, high):
# lyst list being sorted
# copyBuffer temp space needed during merge
# low, high bounds of sublist
# middle midpoint of sublist
if low < high:
middle = (low + high) // 2
mergeSortHelper(lyst, copyBuffer, low, middle)
mergeSortHelper(lyst, copyBuffer, middle + 1, high)
merge(lyst, copyBuffer, low, middle, high
def merge(lyst, copyBuffer, low, middle, high):
# lyst list that is being sorted
# copyBuffer temp space needed during the merge process
# low beginning of first sorted sublist
# middle end of first sorted sublist
# middle + 1 beginning of second sorted sublist
# high end of second sorted sublist
# Initialize i1 and i2 to the first items in each sublist
i1 = low
i2 = middle + 1
# Interleave items from the sublists into the
# copyBuffer in such a way that order is maintained.
for i in range(low, high + 1):
if i1 > middle:
copyBuffer[i] = lyst[i2] # First sublist exhausted
i2 += 1
elif i2 > high:
copyBuffer[i] = lyst[i1] # Second sublist exhausted
i1 += 1
elif lyst[i1] < lyst[i2]:
copyBuffer[i] = lyst[i1] # Item in first sublist <
i1 += 1
else:
copyBuffer[i] = lyst[i2] # Item in second sublist <
i2 += 1
for i in range(low, high + 1): # Copy sorted items back to
# proper position in lyst
lyst[i] = copyBuffer[i]
By Robert C. Martin
http://blog.cleancoder.com/uncle-bob/2020/10/18/Solid-Relevance.html
https://www.geeksforgeeks.org/domain-driven-design-ddd/
"It is not the customer’s job to know what they want”
– Steve Jobs
Domain used in context of software development refers to business
The business logic of an application is a set of rules and guidelines that explain how business object should interact with each other to process modeled data.
View <-- Model <-- Controller
Divides the related program logic into three interconnected elements.
This is done to separate internal representations of information from the ways information is presented to and accepted from the user.
Model
View
Controller