Skip to content

Commit 7bf0cc4

Browse files
authored
Merge pull request codeIIEST#34 from manojkun/master
Made minor changes
2 parents e0c5617 + b7d0568 commit 7bf0cc4

File tree

4 files changed

+7
-5
lines changed

4 files changed

+7
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ From [Wikipedia][quick-wiki]: Quicksort (sometimes called partition-exchange sor
5959
__Properties__
6060
* Worst case performance O(n^2)
6161
* Best case performance O(n log n) or O(n) with three-way partition
62-
* Average case performance O(n^2)
62+
* Average case performance O(n log n)
6363

6464
###### View the algorithm in [action][quick-toptal]
6565

search/Binary_Search.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ int main() {
2121
top = n_terms;
2222

2323
do {
24-
mid = (bottom + top) / 2;
24+
mid = bottom + (top - bottom)/2 ; // same as (bottom + top / 2) but considers overflow condition when bottom + top might be larger than int
2525
if (item < arr[mid])
2626
top = mid - 1; // Here we are dividing the array into two equal parts
2727
else if (item > arr[mid]) /* if target element > mid part of array , we do the search in the upper part of the array

sort/bubble_sort.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33

44
#include <stdio.h>
55

6+
void swap(int*,int*);
67

78
void bubblesort(int arr[], int size)
89
{
910
int i, j;
10-
for (i = 0; i < size; i++) // Function where the actual algorithm is implemented
11+
for (i = 0; i < size - 1; i++) // Function where the actual algorithm is implemented
1112
{
12-
for (j = 0; j < size - i; j++)
13+
for (j = 0; j < size - i - 1; j++)
1314
{
1415
if (arr[j] > arr[j+1])
1516
swap(&arr[j], &arr[j+1]);
@@ -39,6 +40,7 @@ int main()
3940

4041
for (i = 0; i < size; i++)
4142
printf(" %d ", array[i]);
43+
printf(" ");
4244
return 0;
4345

4446
}

sort/insertion_sort.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ int main(){
1616
for(i=1;i<s;i++){
1717
temp=a[i];
1818
j=i-1;
19-
while((temp<a[j])&&(j>=0)){
19+
while((j>=0) && (temp<a[j])){
2020
a[j+1]=a[j];
2121
j=j-1;
2222
}

0 commit comments

Comments
 (0)