Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions python/code_challenges/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

## Table of Content


| Name | Challenge|
| --- | ----------- |
| Reverse Array | [Ch01](https://eslamakram.github.io/data-structures-and-algorithms/python/code_challenges/array-reverse/README) |
| Insert Shift Array | [Ch02](https://eslamakram.github.io/data-structures-and-algorithms/python/code_challenges/array-insert-shift/README) |
| Binary Search Array | [Ch03](https://eslamakram.github.io/data-structures-and-algorithms/python/code_challenges/array-reverse/README) |

| Reverse Array | [Ch01](https://github.com/eslamakram/data-structures-and-algorithms/tree/main/python/code_challenges/array-reverse) |
| Insert Shift Array | [Ch02](https://github.com/eslamakram/data-structures-and-algorithms/tree/main/python/code_challenges/array-insert-shift) |
| Binary Search Array | [Ch03](https://github.com/eslamakram/data-structures-and-algorithms/tree/main/python/code_challenges/array-reverse/README.md) |
11 changes: 7 additions & 4 deletions python/code_challenges/array-binary-search/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
# Code Challange 03

## Insert to Middle of an Array
## Binary Search of Sorted Array

There is an array and value that want to insert it in the middle index in given array and then shift other elements.
Write a function called BinarySearch which takes in 2 parameters: a sorted array and the search key and returns the index of the array’s element that is equal to the value of the search key, or -1 if the element is not in the array.

input: a sorted array and the search key
output: intger number that indicates the index of sreach key , or -1 if that isnt in the array

## Whiteboard Process

![codeCh2](codeChallange2.drawio.png)
![codeCh3](ch2.png)

## Approach & Efficiency

iterations and assign new array
used search algorithm

<https://github.com/eslamakram/data-structures-and-algorithms/pull/22>
16 changes: 16 additions & 0 deletions python/code_challenges/array-binary-search/array-binary-search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

def binary_search(array1, searchKey):
start = 0
end = len(array1) - 1
while(start <= end):
mid = (start + end) // 2
if(array1[mid] > searchKey):
end = mid - 1
elif(array1[mid] < searchKey):
start = mid + 1
else:
return mid
return -1

if __name__ == '__main__':
print(binary_search([11, 23, 36, 47, 51, 66, 73, 83, 92],23))
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.