From 47cd7a21ba94eda95ce2438637f088e1efa76775 Mon Sep 17 00:00:00 2001 From: itai192 <57039405+itai192@users.noreply.github.com> Date: Sat, 10 Oct 2020 17:59:46 +0300 Subject: [PATCH 1/4] added binary search in c# --- Searching Algorithm/Binary Search.cs | 35 ++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 Searching Algorithm/Binary Search.cs diff --git a/Searching Algorithm/Binary Search.cs b/Searching Algorithm/Binary Search.cs new file mode 100644 index 0000000..51b4ebd --- /dev/null +++ b/Searching Algorithm/Binary Search.cs @@ -0,0 +1,35 @@ + +using System; +namespace BinSearch +{ + class BinSearch + { + public static int BinSearch(int[] arr, int val) + { + int min = 0; + int max = arr.Length - 1; + while (min <= max) + { + //find the middle between min and max + int middle = (min + max) / 2; + //if the value is in the middle return it's index + if (arr[middle] == val) + { + return middle; + } + //move max to position where we know there is larger or equal to val + if (arr[middle] > val) + { + max = middle - 1; + } + //move min to position where we know there is smaller or equal to val + else + { + min = middle + 1; + } + } + //if we haven't found the value we return -1 + return -1; + } + } +} \ No newline at end of file From a053618ce2dc644ad78f1903778212ec34790dd5 Mon Sep 17 00:00:00 2001 From: itai192 <57039405+itai192@users.noreply.github.com> Date: Sat, 10 Oct 2020 18:02:03 +0300 Subject: [PATCH 2/4] added my name in the comment --- Searching Algorithm/Binary Search.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Searching Algorithm/Binary Search.cs b/Searching Algorithm/Binary Search.cs index 51b4ebd..af213fc 100644 --- a/Searching Algorithm/Binary Search.cs +++ b/Searching Algorithm/Binary Search.cs @@ -1,4 +1,4 @@ - +//itai192 using System; namespace BinSearch { @@ -32,4 +32,4 @@ public static int BinSearch(int[] arr, int val) return -1; } } -} \ No newline at end of file +} From 13082cb8d4ef601ae7633f06da36f7ed4f108c9a Mon Sep 17 00:00:00 2001 From: itai192 <57039405+itai192@users.noreply.github.com> Date: Thu, 22 Oct 2020 11:39:29 +0300 Subject: [PATCH 3/4] added recursive merge sort in python --- .../MergeSort_Recursively/RecMergeSort.py | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 Sorting Algorithm/MergeSort_Recursively/RecMergeSort.py diff --git a/Sorting Algorithm/MergeSort_Recursively/RecMergeSort.py b/Sorting Algorithm/MergeSort_Recursively/RecMergeSort.py new file mode 100644 index 0000000..3782080 --- /dev/null +++ b/Sorting Algorithm/MergeSort_Recursively/RecMergeSort.py @@ -0,0 +1,41 @@ +#itai192 +#a method that merges two ordered list +def Merge(l1, l2): + l3=[] + #until one list is empty + while(len(l1)>0 and len(l2)>0): + #add the lowest value between the two lists into the third list and remove it from the list it came from + if (l1[0]0): + l3.append(l1.pop(0)) + while(len(l2)>0): + l3.append(l2.pop(0)) + return l3 +#the recursive merge sort method +def MergeSortRec(lis,start,end): + length=end-start+1 + #if the length is one return a list with one item in it + if(length==1): + return [lis[start]] + #if the list has two items, return a list containing the two items in order + if(length==2): + #if the list is in order return it the same way + if(lis[start] Date: Thu, 22 Oct 2020 11:48:18 +0300 Subject: [PATCH 4/4] deleted bin search i've written --- Searching Algorithm/Binary Search.cs | 35 ---------------------------- 1 file changed, 35 deletions(-) delete mode 100644 Searching Algorithm/Binary Search.cs diff --git a/Searching Algorithm/Binary Search.cs b/Searching Algorithm/Binary Search.cs deleted file mode 100644 index af213fc..0000000 --- a/Searching Algorithm/Binary Search.cs +++ /dev/null @@ -1,35 +0,0 @@ -//itai192 -using System; -namespace BinSearch -{ - class BinSearch - { - public static int BinSearch(int[] arr, int val) - { - int min = 0; - int max = arr.Length - 1; - while (min <= max) - { - //find the middle between min and max - int middle = (min + max) / 2; - //if the value is in the middle return it's index - if (arr[middle] == val) - { - return middle; - } - //move max to position where we know there is larger or equal to val - if (arr[middle] > val) - { - max = middle - 1; - } - //move min to position where we know there is smaller or equal to val - else - { - min = middle + 1; - } - } - //if we haven't found the value we return -1 - return -1; - } - } -}