https://github.com/al-ghaly/data-structure-functions
Some basic Algorithms
https://github.com/al-ghaly/data-structure-functions
algorithms data-structures python searching-algorithms sorting-algorithms
Last synced: about 1 year ago
JSON representation
Some basic Algorithms
- Host: GitHub
- URL: https://github.com/al-ghaly/data-structure-functions
- Owner: al-ghaly
- License: mit
- Created: 2023-05-30T15:39:35.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-06-10T09:24:57.000Z (almost 3 years ago)
- Last Synced: 2025-01-22T06:48:06.629Z (about 1 year ago)
- Topics: algorithms, data-structures, python, searching-algorithms, sorting-algorithms
- Language: Python
- Homepage:
- Size: 16.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Data-Structure-Functions
## Some basic Algorithms
```python
# function "1" to check if num is prime
def isprime(x):
#Implementation
# function "2" to get all factors of a num
def factors(n):
# function "3" to get the square root for perfect square numbers
def sqrt(x):
# function "4" to print first n prime nums
def ppns(n):
# function "5" to get square root of ana num by bisiction method
def square_root(x,n):
# function "6" to get square root of any num by newten method
def Square_root(x,n):
# function "7" a simple ex to solve 2 eq in 2 variables
def guessANDcheck(heads,legs):
# function "8" to check if pallindrome or not
def isPalindrome(s):
# function "9" calculate triangle hypotenuse
import math
def caculate():
# function "10" binary search increase by log2 of lists size
def search(v, k):
def search1(l,v):
# the same but with recursion
# function "11" examples on recursion
def factorial(a):
def factorial2(a):
def mult(a,b):
def towers(size,frome,to,spare):
def pallindrome(s):
def tochars(s):
def ispal(s):
def rabbits(n):
def rabbits2(n,d):
# very efficient and have a limit of 1000
# if we tried to put dic in local scope in every
# recursive step dic values will be ste to default
# and we will be redo the previous code with the same
# efficiency
def rabbits3(n):
# linear rabbits solution with 100000 limit
if n == 0 :
def fib(n):
def fib1(n):
# function "12" sorting & searchind
def binary_search(list1, value):
def linear_search(list1, value):
def sel_sort(list1):
def bubble_sort(list1):
def insertion_sort(A):
"""
Sort list A into order, in place.
From Cormen/Leiserson/Rivest/Stein,
Introduction to Algorithms (second edition), page 17,
modified to adjust for fact that Python arrays use
0-indexing.
"""'
def merging_sub_lists(left, right):
def merge(l1, l2):
def merge_sort(list1):
##def merge_sort(list1):
# function "13" to reverse list
def rev_list_(L):
# function "14" to get the abs value
def abs(x):
# function "15" an application on dynamic programming with knapsack problem
def max_value(w, v, i, aw, memo):
"""
its an application on dynamic programming its called knapsack problem in which we take items with values
and weights and a maximum allowed weight we want to get a maximum value under the weight constrain
we use dictionary as a memorization element to save previously calculated pairs of available weight and
level or index
"""
# we use global counter to get number of calls must be global not to be reset every call
def max_value_test():
def max_vaslue(w, v, vo, i, aw, av):
def max_vaslue_test():
# function "16" to generate subsets of a set
def gen_subsets(n):
# function "17" iterative fibonicci
def fib_iter(n):
# function "17" Sort Method
def sort(l1, l):
# Implementation
```