Flowchart
Flowchart
int size = 5;
int array[size] = {5, 1, 3, 2, 4};
bool trade;
while
false int i = 0;
(trade = true)
i<
true
i++
trade = false;
cout<<array[i]<<", ";
int i = 1;
false
i<
END
i
//output 1, 2, 3, 4, 5
true
++i
If
(arr[i - 1]
false
true
trade = true;
``cpp Bubble Sort
#include <iostream>
using namespace std;
void bubbleSort(int arr[], int size){
bool trade = true;
while(trade){
trade = false;
for(int i = 1; i < size; ++i){
if (arr[i - 1] > arr[i]){
int temp = arr[i];
arr[i] = arr[i - 1];
arr[i - 1] = temp;
trade = true;
}
}
};
}
int main ()
{
int size = 5;
int array[size] = {5, 1, 3, 2, 4};
bubbleSort(array,size);
for(int i = 0; i < size; i++)
{
cout<<array[i]<<", ";
}
return 0;
}
START
Selection Sorting Flowchart
int i = 0;
int i = 0;
i<n i<n
i++
i++
int minimum = i;
cout<<array[i]<<", ";
int j = i + 1;
j<n
false END
true //output 1, 4, 6, 9, 10
j++
false
if (arr[j] <
arr[minimum])
minimum = j;
``cpp Selection Sort
#include <iostream>
using namespace std;
void selectionSort(int arr[], int n){
for(int i = 0; i < n - 1; i++)
{
int minimum = i;
for(int j = i + 1; j < n; j++){
if(arr[j] < arr[minimum]){
minimum = j;
}
}
int temp = arr[i];
arr[i] = arr[minimum];
arr[minimum] = temp;
}
}
int main()
{
int n = 5;
int array[n] = {9, 10, 4, 1, 6};
selectionSort(array,n);
for(int i = 0; i < n; i++){
cout<<array[i]<<", ";
}
return 0;
}
START Sequential Search Flowchart
cout
<<"The target found in
index: "<<result<<endl;
END
int i = 0; //output:
The target found in index: 9
i<
size
i++
false
If
(arr[i] == target)
true
return i;
If true
cout<<"The target isn't
(result != false
found in the set :( ";
``cpp Sequential Search
#include <iostream>
using namespace std;
int sequentialSearch(int arr[],int size, int target)
{
for(int i = 0; i < size; i++){
if(arr[i] == target){
return i;
}
}
}
int main()
{
int size = 10;
int array[size] = {2,4,6,8,10,12,14,16,18,20};
int target = 20;
int result = sequentialSearch(array,size,target);
if(result != -1){
cout<<"The target found in index: "<<result<<endl;
}
else{
cout<<"The target isn't found in the set :( ";
}
return 0;
}
START
Binary Search Flowchart
//mid is the return value
return
false
while
cout
(left <= right)
<<"The target is found
in index:
"<<index<<endl;
true
true
if
(arr[mid] == target)
false
left = mid + 1; END
true //output:
true
else
false
``cpp Binary Search
#include <iostream>
using namespace std;
int binarySearching(int arr[], int size, int target)
{
int left = 0;
int right = size - 1;