From 7151dbda13f5940f4931bd6a81d981c2cf4b972e Mon Sep 17 00:00:00 2001 From: RoyalTaterYeeter <86218183+RoyalTaterYeeter@users.noreply.github.com> Date: Fri, 29 Sep 2023 22:14:34 +0530 Subject: [PATCH 01/12] Uploaded questions 1 to 4 --- 1/ACM_DSA_01.c | 127 +++++++++++++++++++++++++++++++++++++++++++ 2/ACM_DSA_02.c | 132 +++++++++++++++++++++++++++++++++++++++++++++ 3/ACM_DSA_03.c | 105 ++++++++++++++++++++++++++++++++++++ 4/ACM_DSA_04.c | 133 ++++++++++++++++++++++++++++++++++++++++++++++ DSA_QUESTIONS.txt | 21 ++++++++ 5 files changed, 518 insertions(+) create mode 100644 1/ACM_DSA_01.c create mode 100644 2/ACM_DSA_02.c create mode 100644 3/ACM_DSA_03.c create mode 100644 4/ACM_DSA_04.c create mode 100644 DSA_QUESTIONS.txt diff --git a/1/ACM_DSA_01.c b/1/ACM_DSA_01.c new file mode 100644 index 0000000..8f83a80 --- /dev/null +++ b/1/ACM_DSA_01.c @@ -0,0 +1,127 @@ +#include + +/* Implement a binary search algorithm to find the index of a given element in a sorted array. */ + +int binsrch(int arr_len, int arr[]) { + + int l_index = 0, r_index = arr_len - 1, t, m_index; + + printf("\nPlease Enter Value To Be Searched For Using The Binary Search Algorithm:\n\n=>\tTARGET\t:\t"); + scanf("%d", &t); + + while (l_index <= r_index) { + + m_index = (l_index + r_index)/2; + + if (arr[m_index] == t) { return m_index; } + + if (arr[m_index] < t) { l_index = m_index + 1; continue; } + else if (arr[m_index] > t) { r_index = m_index - 1; continue; } + + } + + return -1; + +} + +void main() { + + int arr_ch, t_index; + + printf("\nHello!\n\nPlease Select An Option:\n\n\t1. Enter Elements To Populate Custom Array, Then Use Binary Search.\n\t2. Test Binary Search Using Pre-Defined Array.\n\n"); + + printf("=>\t"); scanf("%d", &arr_ch); + + while (1) { + + if (arr_ch == 1) { + + printf("\n\nPlease Enter The Number Of Elements You Wish To Add To The Array:\n\n"); + + int n, i, j; + + printf("=>\tn\t:\t"); scanf("%d", &n); + + int num_arr[n]; + + printf("\nPlease Enter Elements:\n\n"); + + for (i = 0; i < n; i++) { printf("=>\tELEMENT-%d\t:\t", i + 1); scanf("%d", &num_arr[i]); } + + // sorting + for (i = 0; i < n; i++) { + + for (j = i + 1; j < n; ++j) { + + if (num_arr[i] > num_arr[j]) { + + num_arr[i] ^= num_arr[j]; + num_arr[j] = num_arr[i] ^ num_arr[j]; + num_arr[i] ^= num_arr[j]; + + } + + } + + } + + printf("\nSorted Array:\n\n{ %d", num_arr[0]); + + for (i = 1; i < n; i++) { printf(", %d", num_arr[i]); } + + printf(" }\n\n"); + + t_index = binsrch(n, num_arr); + + break; + + } + else if (arr_ch == 2) { + + int n = 100, num_arr[100] = { + + 1, 2, 4, 5, 6, 7, 10, 11, 14, 16, + 19, 20, 21, 24, 25, 26, 29, 31, 32, 33, + 34, 35, 37, 43, 45, 46, 47, 51, 52, 53, + 56, 58, 59, 62, 63, 66, 67, 71, 72, 74, + 76, 77, 79, 83, 84, 86, 88, 89, 91, 93, + 95, 96, 97, 101, 123, 143, 150, 158, 172, 184, + 221, 224, 232, 235, 245, 279, 299, 304, 306, 315, + 318, 330, 363, 366, 402, 408, 516, 535, 551, 553, + 558, 562, 567, 583, 586, 627, 640, 675, 693, 719, + 728, 756, 769, 784, 820, 838, 855, 867, 871, 897 + + }; + + printf("\n\nHere Is An Array Of 100 Elements (Read Left-to-Right, Top-to-Bottom, Sequentially.):\n\n"); + + int i, j; + + printf("{"); + + for (j = 0; j < n / 10; j++) { + + printf("\t%d", num_arr[j]); + + for (i = j + (n / 10); i < n; i += n / 10) { printf(",\t%d", num_arr[i]); } + + if (j == (n / 10) - 1) { printf("\t}\n"); continue; } + + printf("\n"); + + } + + t_index = binsrch(n, num_arr); + + break; + + } + else { t_index = -2; break; } + + } + + if (t_index >= 0) { printf("\n\nThe element is present at the index %d.\n\n\n", t_index); } + else if (t_index == -1) { printf("\n\nThe element was not found in the array.\n\n\n"); } + else { printf("\n\nInvalid Argument For Choice, Exiting...\n\n\n"); } + +} diff --git a/2/ACM_DSA_02.c b/2/ACM_DSA_02.c new file mode 100644 index 0000000..11c2660 --- /dev/null +++ b/2/ACM_DSA_02.c @@ -0,0 +1,132 @@ +#include + +/* Implement the bubble sort algorithm to sort an array of integers. */ + +void switch_vars(int* a, int* b) { *a ^= *b; *b = *a ^ *b; *a ^= *b; } + +void bubble_sort(int length_arr, int num_arr[]) { + + int i = 0, j, k; + + while (i < length_arr) { + + for (j = 0; j < length_arr - (i + 1); j++) { + + if (num_arr[j] > num_arr[j + 1]) { switch_vars(&num_arr[j], &num_arr[j + 1]); } + + } + + i++; + + } + + if (length_arr != 100) { + + printf("\nSorted Array:\n\n{ %d", num_arr[0]); + + for (i = 1; i < length_arr; i++) { printf(", %d", num_arr[i]); } + + printf(" }\n\n"); + + } + else { + + printf("\nSorted Array:\n\n"); + + printf("{"); + + for (j = 0; j < length_arr / 10; j++) { + + printf("\t%d", num_arr[j]); + + for (i = j + (length_arr / 10); i < length_arr; i += length_arr / 10) { printf(",\t%d", num_arr[i]); } + + if (j == (length_arr / 10) - 1) { printf("\t}\n"); continue; } + + printf("\n"); + + } + + } +} + +void main() { + + int arr_choice; + + printf("\nHello!\n\nPlease Select An Option:\n\n\t1. Enter Elements To Populate Custom Array, Then Use Bubble Sort.\n\t2. Test Bubble Sort Using Pre-Defined Unsorted Array.\n\n"); + + printf("=>\t"); scanf("%d", &arr_choice); + + switch (arr_choice) { + + case 1: { + + printf("\n\nPlease Enter The Number Of Elements You Wish To Add To The Array:\n\n"); + + int n, i, j; + + printf("=>\tn\t:\t"); scanf("%d", &n); + + int num_arr[n]; + + printf("\nPlease Enter Elements:\n\n"); + + for (i = 0; i < n; i++) { printf("=>\tELEMENT-%d\t:\t", i + 1); scanf("%d", &num_arr[i]); } + + printf("\nUnsorted Array:\n\n{ %d", num_arr[0]); + + for (i = 1; i < n; i++) { printf(", %d", num_arr[i]); } + + printf(" }\n\n"); + + bubble_sort(n, num_arr); + + break; + + } + + case 2: { + + int n = 100, num_arr[100] = { + + 0, 260, 267, 268, 13, 14, 16, 277, 278, 24, + 26, 27, 282, 29, 284, 31, 34, 291, 36, 294, + 39, 298, 44, 45, 46, 306, 51, 310, 55, 56, + 57, 59, 60, 318, 321, 324, 69, 71, 77, 337, + 338, 86, 87, 342, 89, 90, 346, 348, 98, 355, + 100, 356, 102, 357, 359, 105, 361, 363, 109, 365, + 366, 112, 368, 370, 371, 372, 117, 118, 120, 122, + 124, 130, 133, 137, 138, 141, 149, 153, 154, 157, + 159, 160, 168, 171, 178, 181, 183, 184, 194, 197, + 202, 205, 213, 214, 223, 224, 225, 231, 232, 236 + + }; + + printf("\n\nHere Is An Array Of 100 Elements (Read Left-to-Right, Top-to-Bottom, Sequentially):\n\n"); + + int i, j; + + printf("{"); + + for (j = 0; j < n / 10; j++) { + + printf("\t%d", num_arr[j]); + + for (i = j + (n / 10); i < n; i += n / 10) { printf(",\t%d", num_arr[i]); } + + if ( j == (n / 10) - 1) { printf("\t}\n"); continue; } + + printf("\n"); + + } + + bubble_sort(n, num_arr); + + break; + + } + + } + +} \ No newline at end of file diff --git a/3/ACM_DSA_03.c b/3/ACM_DSA_03.c new file mode 100644 index 0000000..ae56117 --- /dev/null +++ b/3/ACM_DSA_03.c @@ -0,0 +1,105 @@ +#include + +/* Implement a linear search algorithm to find the index of a given element in an array. */ + +int linsrch(int arr_len, int arr[]) { + + int target, i; + + printf("\nPlease Enter Value To Be Searched For Using The Linear Search Algorithm:\n\n=>\tTARGET\t:\t"); + scanf("%d", &target); + + for (i = 0; i < arr_len; i++) { + + if (target == arr[i]) { return i; } + + } + + return -1; + +} + +void main() { + + int arr_ch, t_index; + + printf("\nHello!\n\nPlease Select An Option:\n\n\t1. Enter Elements To Populate Custom Array, Then Use Linear Search.\n\t2. Test Linear Search Using Pre-Defined Array.\n\n"); + + printf("=>\t"); scanf("%d", &arr_ch); + + while (1) { + + if (arr_ch == 1) { + + printf("\n\nPlease Enter The Number Of Elements You Wish To Add To The Array:\n\n"); + + int n, i, j; + + printf("=>\tn\t:\t"); scanf("%d", &n); + + int num_arr[n]; + + printf("\nPlease Enter Elements:\n\n"); + + for (i = 0; i < n; i++) { printf("=>\tELEMENT-%d\t:\t", i + 1); scanf("%d", &num_arr[i]); } + + printf("\nArray:\n\n{ %d", num_arr[0]); + + for (i = 1; i < n; i++) { printf(", %d", num_arr[i]); } + + printf(" }\n\n"); + + t_index = linsrch(n, num_arr); + + break; + + } + else if (arr_ch == 2) { + + int n = 100, num_arr[100] = { + + 0, 260, 267, 268, 13, 14, 16, 277, 278, 24, + 26, 27, 282, 29, 284, 31, 34, 291, 36, 294, + 39, 298, 44, 45, 46, 306, 51, 310, 55, 56, + 57, 59, 60, 318, 321, 324, 69, 71, 77, 337, + 338, 86, 87, 342, 89, 90, 346, 348, 98, 355, + 100, 356, 102, 357, 359, 105, 361, 363, 109, 365, + 366, 112, 368, 370, 371, 372, 117, 118, 120, 122, + 124, 130, 133, 137, 138, 141, 149, 153, 154, 157, + 159, 160, 168, 171, 178, 181, 183, 184, 194, 197, + 202, 205, 213, 214, 223, 224, 225, 231, 232, 236 + + }; + + printf("\n\nHere Is An Array Of 100 Elements (Read Left-to-Right, Top-to-Bottom, Sequentially.):\n\n"); + + int i, j; + + printf("{"); + + for (j = 0; j < n / 10; j++) { + + printf("\t%d", num_arr[j]); + + for (i = j + (n / 10); i < n; i += n / 10) { printf(",\t%d", num_arr[i]); } + + if (j == (n / 10) - 1) { printf("\t}\n"); continue; } + + printf("\n"); + + } + + t_index = linsrch(n, num_arr); + + break; + + } + else { t_index = -2; break; } + + } + + if (t_index >= 0) { printf("\n\nThe element is present at the index %d.\n\n\n", t_index); } + else if (t_index == -1) { printf("\n\nThe element was not found in the array.\n\n\n"); } + else { printf("\n\nInvalid Argument For Choice, Exiting...\n\n\n"); } + +} \ No newline at end of file diff --git a/4/ACM_DSA_04.c b/4/ACM_DSA_04.c new file mode 100644 index 0000000..017b9a9 --- /dev/null +++ b/4/ACM_DSA_04.c @@ -0,0 +1,133 @@ +#include + +/* Implement the selection sort algorithm to sort an array of integers. */ + +void switch_vars(int* a, int* b) { *a ^= *b; *b = *a ^ *b; *a ^= *b; } + +void selection_sort(int length_arr, int num_arr[]) { + + int i = 0, j, k; + + while (i < length_arr - 1){ + + int min_index = i; + + for (j = i; j < length_arr ; j++) { if (num_arr[j] < num_arr[min_index]) { min_index = j; } } + + switch_vars(&num_arr[i], &num_arr[min_index]); + + i++; + + } + + if (length_arr != 100) { + + printf("\nSorted Array:\n\n{ %d", num_arr[0]); + + for (i = 1; i < length_arr; i++) { printf(", %d", num_arr[i]); } + + printf(" }\n\n"); + + } + else { + + printf("\nSorted Array:\n\n"); + + printf("{"); + + for (j = 0; j < length_arr / 10; j++) { + + printf("\t%d", num_arr[j]); + + for (i = j + (length_arr / 10); i < length_arr; i += length_arr / 10) { printf(",\t%d", num_arr[i]); } + + if (j == (length_arr / 10) - 1) { printf("\t}\n"); continue; } + + printf("\n"); + + } + + } + +} + +void main() { + + int arr_choice; + + printf("\nHello!\n\nPlease Select An Option:\n\n\t1. Enter Elements To Populate Custom Array, Then Use Selection Sort.\n\t2. Test Selection Sort Using Pre-Defined Unsorted Array.\n\n"); + + printf("=>\t"); scanf("%d", &arr_choice); + + switch (arr_choice) { + + case 1: { + + printf("\n\nPlease Enter The Number Of Elements You Wish To Add To The Array:\n\n"); + + int n, i, j; + + printf("=>\tn\t:\t"); scanf("%d", &n); + + int num_arr[n]; + + printf("\nPlease Enter Elements:\n\n"); + + for (i = 0; i < n; i++) { printf("=>\tELEMENT-%d\t:\t", i + 1); scanf("%d", &num_arr[i]); } + + printf("\nUnsorted Array:\n\n{ %d", num_arr[0]); + + for (i = 1; i < n; i++) { printf(", %d", num_arr[i]); } + + printf(" }\n\n"); + + selection_sort(n, num_arr); + + break; + + } + + case 2: { + + int n = 100, num_arr[100] = { + + 0, 260, 267, 268, 13, 14, 16, 277, 278, 24, + 26, 27, 282, 29, 284, 31, 34, 291, 36, 294, + 39, 298, 44, 45, 46, 306, 51, 310, 55, 56, + 57, 59, 60, 318, 321, 324, 69, 71, 77, 337, + 338, 86, 87, 342, 89, 90, 346, 348, 98, 355, + 100, 356, 102, 357, 359, 105, 361, 363, 109, 365, + 366, 112, 368, 370, 371, 372, 117, 118, 120, 122, + 124, 130, 133, 137, 138, 141, 149, 153, 154, 157, + 159, 160, 168, 171, 178, 181, 183, 184, 194, 197, + 202, 205, 213, 214, 223, 224, 225, 231, 232, 236 + + }; + + printf("\n\nHere Is An Array Of 100 Elements (Read Left-to-Right, Top-to-Bottom, Sequentially):\n\n"); + + int i, j; + + printf("{"); + + for (j = 0; j < n / 10; j++) { + + printf("\t%d", num_arr[j]); + + for (i = j + (n / 10); i < n; i += n / 10) { printf(",\t%d", num_arr[i]); } + + if (j == (n / 10) - 1) { printf("\t}\n"); continue; } + + printf("\n"); + + } + + selection_sort(n, num_arr); + + break; + + } + + } + +} \ No newline at end of file diff --git a/DSA_QUESTIONS.txt b/DSA_QUESTIONS.txt new file mode 100644 index 0000000..5eb36f2 --- /dev/null +++ b/DSA_QUESTIONS.txt @@ -0,0 +1,21 @@ + +DATA STRUCTURE ALGORITHMS - ACM TECHNICAL MENTORSHIP + +Questions: + +1. Implement a binary search algorithm to find the index of a given element in a sorted array. + +2. Implement the bubble sort algorithm to sort an array of integers. + +3. Implement a linear search algorithm to find the index of a given element in an array. + +4. Implement the selection sort algorithm to sort an array of integers. + +5. Write a recursive function to generate series of Fibonacci numbers up to some value n. + +6. Implement a function to determine whether a given string is a palindrome. + +7. Write a recursive function to calculate the result of raising a number to a positive integer exponent. + +8. Write a program in C to count the number of vowels and consonants in a string. + From ae997a89655331bb0221841916db1f7925970e0d Mon Sep 17 00:00:00 2001 From: RoyalTaterYeeter <86218183+RoyalTaterYeeter@users.noreply.github.com> Date: Fri, 29 Sep 2023 22:15:24 +0530 Subject: [PATCH 02/12] Delete README.md --- README.md | 1 - 1 file changed, 1 deletion(-) delete mode 100644 README.md diff --git a/README.md b/README.md deleted file mode 100644 index e270a7e..0000000 --- a/README.md +++ /dev/null @@ -1 +0,0 @@ -# Technical-2023 \ No newline at end of file From 790b9a1e9eef6087d888883236f2da6a018bc25b Mon Sep 17 00:00:00 2001 From: RoyalTaterYeeter <86218183+RoyalTaterYeeter@users.noreply.github.com> Date: Fri, 29 Sep 2023 22:17:05 +0530 Subject: [PATCH 03/12] Add files via upload --- Data Structure Algorithms/1/ACM_DSA_01.c | 127 ++++++++++++++++++++++ Data Structure Algorithms/2/ACM_DSA_02.c | 132 ++++++++++++++++++++++ Data Structure Algorithms/3/ACM_DSA_03.c | 105 ++++++++++++++++++ Data Structure Algorithms/4/ACM_DSA_04.c | 133 +++++++++++++++++++++++ 4 files changed, 497 insertions(+) create mode 100644 Data Structure Algorithms/1/ACM_DSA_01.c create mode 100644 Data Structure Algorithms/2/ACM_DSA_02.c create mode 100644 Data Structure Algorithms/3/ACM_DSA_03.c create mode 100644 Data Structure Algorithms/4/ACM_DSA_04.c diff --git a/Data Structure Algorithms/1/ACM_DSA_01.c b/Data Structure Algorithms/1/ACM_DSA_01.c new file mode 100644 index 0000000..8f83a80 --- /dev/null +++ b/Data Structure Algorithms/1/ACM_DSA_01.c @@ -0,0 +1,127 @@ +#include + +/* Implement a binary search algorithm to find the index of a given element in a sorted array. */ + +int binsrch(int arr_len, int arr[]) { + + int l_index = 0, r_index = arr_len - 1, t, m_index; + + printf("\nPlease Enter Value To Be Searched For Using The Binary Search Algorithm:\n\n=>\tTARGET\t:\t"); + scanf("%d", &t); + + while (l_index <= r_index) { + + m_index = (l_index + r_index)/2; + + if (arr[m_index] == t) { return m_index; } + + if (arr[m_index] < t) { l_index = m_index + 1; continue; } + else if (arr[m_index] > t) { r_index = m_index - 1; continue; } + + } + + return -1; + +} + +void main() { + + int arr_ch, t_index; + + printf("\nHello!\n\nPlease Select An Option:\n\n\t1. Enter Elements To Populate Custom Array, Then Use Binary Search.\n\t2. Test Binary Search Using Pre-Defined Array.\n\n"); + + printf("=>\t"); scanf("%d", &arr_ch); + + while (1) { + + if (arr_ch == 1) { + + printf("\n\nPlease Enter The Number Of Elements You Wish To Add To The Array:\n\n"); + + int n, i, j; + + printf("=>\tn\t:\t"); scanf("%d", &n); + + int num_arr[n]; + + printf("\nPlease Enter Elements:\n\n"); + + for (i = 0; i < n; i++) { printf("=>\tELEMENT-%d\t:\t", i + 1); scanf("%d", &num_arr[i]); } + + // sorting + for (i = 0; i < n; i++) { + + for (j = i + 1; j < n; ++j) { + + if (num_arr[i] > num_arr[j]) { + + num_arr[i] ^= num_arr[j]; + num_arr[j] = num_arr[i] ^ num_arr[j]; + num_arr[i] ^= num_arr[j]; + + } + + } + + } + + printf("\nSorted Array:\n\n{ %d", num_arr[0]); + + for (i = 1; i < n; i++) { printf(", %d", num_arr[i]); } + + printf(" }\n\n"); + + t_index = binsrch(n, num_arr); + + break; + + } + else if (arr_ch == 2) { + + int n = 100, num_arr[100] = { + + 1, 2, 4, 5, 6, 7, 10, 11, 14, 16, + 19, 20, 21, 24, 25, 26, 29, 31, 32, 33, + 34, 35, 37, 43, 45, 46, 47, 51, 52, 53, + 56, 58, 59, 62, 63, 66, 67, 71, 72, 74, + 76, 77, 79, 83, 84, 86, 88, 89, 91, 93, + 95, 96, 97, 101, 123, 143, 150, 158, 172, 184, + 221, 224, 232, 235, 245, 279, 299, 304, 306, 315, + 318, 330, 363, 366, 402, 408, 516, 535, 551, 553, + 558, 562, 567, 583, 586, 627, 640, 675, 693, 719, + 728, 756, 769, 784, 820, 838, 855, 867, 871, 897 + + }; + + printf("\n\nHere Is An Array Of 100 Elements (Read Left-to-Right, Top-to-Bottom, Sequentially.):\n\n"); + + int i, j; + + printf("{"); + + for (j = 0; j < n / 10; j++) { + + printf("\t%d", num_arr[j]); + + for (i = j + (n / 10); i < n; i += n / 10) { printf(",\t%d", num_arr[i]); } + + if (j == (n / 10) - 1) { printf("\t}\n"); continue; } + + printf("\n"); + + } + + t_index = binsrch(n, num_arr); + + break; + + } + else { t_index = -2; break; } + + } + + if (t_index >= 0) { printf("\n\nThe element is present at the index %d.\n\n\n", t_index); } + else if (t_index == -1) { printf("\n\nThe element was not found in the array.\n\n\n"); } + else { printf("\n\nInvalid Argument For Choice, Exiting...\n\n\n"); } + +} diff --git a/Data Structure Algorithms/2/ACM_DSA_02.c b/Data Structure Algorithms/2/ACM_DSA_02.c new file mode 100644 index 0000000..11c2660 --- /dev/null +++ b/Data Structure Algorithms/2/ACM_DSA_02.c @@ -0,0 +1,132 @@ +#include + +/* Implement the bubble sort algorithm to sort an array of integers. */ + +void switch_vars(int* a, int* b) { *a ^= *b; *b = *a ^ *b; *a ^= *b; } + +void bubble_sort(int length_arr, int num_arr[]) { + + int i = 0, j, k; + + while (i < length_arr) { + + for (j = 0; j < length_arr - (i + 1); j++) { + + if (num_arr[j] > num_arr[j + 1]) { switch_vars(&num_arr[j], &num_arr[j + 1]); } + + } + + i++; + + } + + if (length_arr != 100) { + + printf("\nSorted Array:\n\n{ %d", num_arr[0]); + + for (i = 1; i < length_arr; i++) { printf(", %d", num_arr[i]); } + + printf(" }\n\n"); + + } + else { + + printf("\nSorted Array:\n\n"); + + printf("{"); + + for (j = 0; j < length_arr / 10; j++) { + + printf("\t%d", num_arr[j]); + + for (i = j + (length_arr / 10); i < length_arr; i += length_arr / 10) { printf(",\t%d", num_arr[i]); } + + if (j == (length_arr / 10) - 1) { printf("\t}\n"); continue; } + + printf("\n"); + + } + + } +} + +void main() { + + int arr_choice; + + printf("\nHello!\n\nPlease Select An Option:\n\n\t1. Enter Elements To Populate Custom Array, Then Use Bubble Sort.\n\t2. Test Bubble Sort Using Pre-Defined Unsorted Array.\n\n"); + + printf("=>\t"); scanf("%d", &arr_choice); + + switch (arr_choice) { + + case 1: { + + printf("\n\nPlease Enter The Number Of Elements You Wish To Add To The Array:\n\n"); + + int n, i, j; + + printf("=>\tn\t:\t"); scanf("%d", &n); + + int num_arr[n]; + + printf("\nPlease Enter Elements:\n\n"); + + for (i = 0; i < n; i++) { printf("=>\tELEMENT-%d\t:\t", i + 1); scanf("%d", &num_arr[i]); } + + printf("\nUnsorted Array:\n\n{ %d", num_arr[0]); + + for (i = 1; i < n; i++) { printf(", %d", num_arr[i]); } + + printf(" }\n\n"); + + bubble_sort(n, num_arr); + + break; + + } + + case 2: { + + int n = 100, num_arr[100] = { + + 0, 260, 267, 268, 13, 14, 16, 277, 278, 24, + 26, 27, 282, 29, 284, 31, 34, 291, 36, 294, + 39, 298, 44, 45, 46, 306, 51, 310, 55, 56, + 57, 59, 60, 318, 321, 324, 69, 71, 77, 337, + 338, 86, 87, 342, 89, 90, 346, 348, 98, 355, + 100, 356, 102, 357, 359, 105, 361, 363, 109, 365, + 366, 112, 368, 370, 371, 372, 117, 118, 120, 122, + 124, 130, 133, 137, 138, 141, 149, 153, 154, 157, + 159, 160, 168, 171, 178, 181, 183, 184, 194, 197, + 202, 205, 213, 214, 223, 224, 225, 231, 232, 236 + + }; + + printf("\n\nHere Is An Array Of 100 Elements (Read Left-to-Right, Top-to-Bottom, Sequentially):\n\n"); + + int i, j; + + printf("{"); + + for (j = 0; j < n / 10; j++) { + + printf("\t%d", num_arr[j]); + + for (i = j + (n / 10); i < n; i += n / 10) { printf(",\t%d", num_arr[i]); } + + if ( j == (n / 10) - 1) { printf("\t}\n"); continue; } + + printf("\n"); + + } + + bubble_sort(n, num_arr); + + break; + + } + + } + +} \ No newline at end of file diff --git a/Data Structure Algorithms/3/ACM_DSA_03.c b/Data Structure Algorithms/3/ACM_DSA_03.c new file mode 100644 index 0000000..ae56117 --- /dev/null +++ b/Data Structure Algorithms/3/ACM_DSA_03.c @@ -0,0 +1,105 @@ +#include + +/* Implement a linear search algorithm to find the index of a given element in an array. */ + +int linsrch(int arr_len, int arr[]) { + + int target, i; + + printf("\nPlease Enter Value To Be Searched For Using The Linear Search Algorithm:\n\n=>\tTARGET\t:\t"); + scanf("%d", &target); + + for (i = 0; i < arr_len; i++) { + + if (target == arr[i]) { return i; } + + } + + return -1; + +} + +void main() { + + int arr_ch, t_index; + + printf("\nHello!\n\nPlease Select An Option:\n\n\t1. Enter Elements To Populate Custom Array, Then Use Linear Search.\n\t2. Test Linear Search Using Pre-Defined Array.\n\n"); + + printf("=>\t"); scanf("%d", &arr_ch); + + while (1) { + + if (arr_ch == 1) { + + printf("\n\nPlease Enter The Number Of Elements You Wish To Add To The Array:\n\n"); + + int n, i, j; + + printf("=>\tn\t:\t"); scanf("%d", &n); + + int num_arr[n]; + + printf("\nPlease Enter Elements:\n\n"); + + for (i = 0; i < n; i++) { printf("=>\tELEMENT-%d\t:\t", i + 1); scanf("%d", &num_arr[i]); } + + printf("\nArray:\n\n{ %d", num_arr[0]); + + for (i = 1; i < n; i++) { printf(", %d", num_arr[i]); } + + printf(" }\n\n"); + + t_index = linsrch(n, num_arr); + + break; + + } + else if (arr_ch == 2) { + + int n = 100, num_arr[100] = { + + 0, 260, 267, 268, 13, 14, 16, 277, 278, 24, + 26, 27, 282, 29, 284, 31, 34, 291, 36, 294, + 39, 298, 44, 45, 46, 306, 51, 310, 55, 56, + 57, 59, 60, 318, 321, 324, 69, 71, 77, 337, + 338, 86, 87, 342, 89, 90, 346, 348, 98, 355, + 100, 356, 102, 357, 359, 105, 361, 363, 109, 365, + 366, 112, 368, 370, 371, 372, 117, 118, 120, 122, + 124, 130, 133, 137, 138, 141, 149, 153, 154, 157, + 159, 160, 168, 171, 178, 181, 183, 184, 194, 197, + 202, 205, 213, 214, 223, 224, 225, 231, 232, 236 + + }; + + printf("\n\nHere Is An Array Of 100 Elements (Read Left-to-Right, Top-to-Bottom, Sequentially.):\n\n"); + + int i, j; + + printf("{"); + + for (j = 0; j < n / 10; j++) { + + printf("\t%d", num_arr[j]); + + for (i = j + (n / 10); i < n; i += n / 10) { printf(",\t%d", num_arr[i]); } + + if (j == (n / 10) - 1) { printf("\t}\n"); continue; } + + printf("\n"); + + } + + t_index = linsrch(n, num_arr); + + break; + + } + else { t_index = -2; break; } + + } + + if (t_index >= 0) { printf("\n\nThe element is present at the index %d.\n\n\n", t_index); } + else if (t_index == -1) { printf("\n\nThe element was not found in the array.\n\n\n"); } + else { printf("\n\nInvalid Argument For Choice, Exiting...\n\n\n"); } + +} \ No newline at end of file diff --git a/Data Structure Algorithms/4/ACM_DSA_04.c b/Data Structure Algorithms/4/ACM_DSA_04.c new file mode 100644 index 0000000..017b9a9 --- /dev/null +++ b/Data Structure Algorithms/4/ACM_DSA_04.c @@ -0,0 +1,133 @@ +#include + +/* Implement the selection sort algorithm to sort an array of integers. */ + +void switch_vars(int* a, int* b) { *a ^= *b; *b = *a ^ *b; *a ^= *b; } + +void selection_sort(int length_arr, int num_arr[]) { + + int i = 0, j, k; + + while (i < length_arr - 1){ + + int min_index = i; + + for (j = i; j < length_arr ; j++) { if (num_arr[j] < num_arr[min_index]) { min_index = j; } } + + switch_vars(&num_arr[i], &num_arr[min_index]); + + i++; + + } + + if (length_arr != 100) { + + printf("\nSorted Array:\n\n{ %d", num_arr[0]); + + for (i = 1; i < length_arr; i++) { printf(", %d", num_arr[i]); } + + printf(" }\n\n"); + + } + else { + + printf("\nSorted Array:\n\n"); + + printf("{"); + + for (j = 0; j < length_arr / 10; j++) { + + printf("\t%d", num_arr[j]); + + for (i = j + (length_arr / 10); i < length_arr; i += length_arr / 10) { printf(",\t%d", num_arr[i]); } + + if (j == (length_arr / 10) - 1) { printf("\t}\n"); continue; } + + printf("\n"); + + } + + } + +} + +void main() { + + int arr_choice; + + printf("\nHello!\n\nPlease Select An Option:\n\n\t1. Enter Elements To Populate Custom Array, Then Use Selection Sort.\n\t2. Test Selection Sort Using Pre-Defined Unsorted Array.\n\n"); + + printf("=>\t"); scanf("%d", &arr_choice); + + switch (arr_choice) { + + case 1: { + + printf("\n\nPlease Enter The Number Of Elements You Wish To Add To The Array:\n\n"); + + int n, i, j; + + printf("=>\tn\t:\t"); scanf("%d", &n); + + int num_arr[n]; + + printf("\nPlease Enter Elements:\n\n"); + + for (i = 0; i < n; i++) { printf("=>\tELEMENT-%d\t:\t", i + 1); scanf("%d", &num_arr[i]); } + + printf("\nUnsorted Array:\n\n{ %d", num_arr[0]); + + for (i = 1; i < n; i++) { printf(", %d", num_arr[i]); } + + printf(" }\n\n"); + + selection_sort(n, num_arr); + + break; + + } + + case 2: { + + int n = 100, num_arr[100] = { + + 0, 260, 267, 268, 13, 14, 16, 277, 278, 24, + 26, 27, 282, 29, 284, 31, 34, 291, 36, 294, + 39, 298, 44, 45, 46, 306, 51, 310, 55, 56, + 57, 59, 60, 318, 321, 324, 69, 71, 77, 337, + 338, 86, 87, 342, 89, 90, 346, 348, 98, 355, + 100, 356, 102, 357, 359, 105, 361, 363, 109, 365, + 366, 112, 368, 370, 371, 372, 117, 118, 120, 122, + 124, 130, 133, 137, 138, 141, 149, 153, 154, 157, + 159, 160, 168, 171, 178, 181, 183, 184, 194, 197, + 202, 205, 213, 214, 223, 224, 225, 231, 232, 236 + + }; + + printf("\n\nHere Is An Array Of 100 Elements (Read Left-to-Right, Top-to-Bottom, Sequentially):\n\n"); + + int i, j; + + printf("{"); + + for (j = 0; j < n / 10; j++) { + + printf("\t%d", num_arr[j]); + + for (i = j + (n / 10); i < n; i += n / 10) { printf(",\t%d", num_arr[i]); } + + if (j == (n / 10) - 1) { printf("\t}\n"); continue; } + + printf("\n"); + + } + + selection_sort(n, num_arr); + + break; + + } + + } + +} \ No newline at end of file From 0dab49411ceb4132d7a22894a31422559fbb3a38 Mon Sep 17 00:00:00 2001 From: RoyalTaterYeeter <86218183+RoyalTaterYeeter@users.noreply.github.com> Date: Fri, 29 Sep 2023 22:18:20 +0530 Subject: [PATCH 04/12] Delete 3 directory --- 3/ACM_DSA_03.c | 105 ------------------------------------------------- 1 file changed, 105 deletions(-) delete mode 100644 3/ACM_DSA_03.c diff --git a/3/ACM_DSA_03.c b/3/ACM_DSA_03.c deleted file mode 100644 index ae56117..0000000 --- a/3/ACM_DSA_03.c +++ /dev/null @@ -1,105 +0,0 @@ -#include - -/* Implement a linear search algorithm to find the index of a given element in an array. */ - -int linsrch(int arr_len, int arr[]) { - - int target, i; - - printf("\nPlease Enter Value To Be Searched For Using The Linear Search Algorithm:\n\n=>\tTARGET\t:\t"); - scanf("%d", &target); - - for (i = 0; i < arr_len; i++) { - - if (target == arr[i]) { return i; } - - } - - return -1; - -} - -void main() { - - int arr_ch, t_index; - - printf("\nHello!\n\nPlease Select An Option:\n\n\t1. Enter Elements To Populate Custom Array, Then Use Linear Search.\n\t2. Test Linear Search Using Pre-Defined Array.\n\n"); - - printf("=>\t"); scanf("%d", &arr_ch); - - while (1) { - - if (arr_ch == 1) { - - printf("\n\nPlease Enter The Number Of Elements You Wish To Add To The Array:\n\n"); - - int n, i, j; - - printf("=>\tn\t:\t"); scanf("%d", &n); - - int num_arr[n]; - - printf("\nPlease Enter Elements:\n\n"); - - for (i = 0; i < n; i++) { printf("=>\tELEMENT-%d\t:\t", i + 1); scanf("%d", &num_arr[i]); } - - printf("\nArray:\n\n{ %d", num_arr[0]); - - for (i = 1; i < n; i++) { printf(", %d", num_arr[i]); } - - printf(" }\n\n"); - - t_index = linsrch(n, num_arr); - - break; - - } - else if (arr_ch == 2) { - - int n = 100, num_arr[100] = { - - 0, 260, 267, 268, 13, 14, 16, 277, 278, 24, - 26, 27, 282, 29, 284, 31, 34, 291, 36, 294, - 39, 298, 44, 45, 46, 306, 51, 310, 55, 56, - 57, 59, 60, 318, 321, 324, 69, 71, 77, 337, - 338, 86, 87, 342, 89, 90, 346, 348, 98, 355, - 100, 356, 102, 357, 359, 105, 361, 363, 109, 365, - 366, 112, 368, 370, 371, 372, 117, 118, 120, 122, - 124, 130, 133, 137, 138, 141, 149, 153, 154, 157, - 159, 160, 168, 171, 178, 181, 183, 184, 194, 197, - 202, 205, 213, 214, 223, 224, 225, 231, 232, 236 - - }; - - printf("\n\nHere Is An Array Of 100 Elements (Read Left-to-Right, Top-to-Bottom, Sequentially.):\n\n"); - - int i, j; - - printf("{"); - - for (j = 0; j < n / 10; j++) { - - printf("\t%d", num_arr[j]); - - for (i = j + (n / 10); i < n; i += n / 10) { printf(",\t%d", num_arr[i]); } - - if (j == (n / 10) - 1) { printf("\t}\n"); continue; } - - printf("\n"); - - } - - t_index = linsrch(n, num_arr); - - break; - - } - else { t_index = -2; break; } - - } - - if (t_index >= 0) { printf("\n\nThe element is present at the index %d.\n\n\n", t_index); } - else if (t_index == -1) { printf("\n\nThe element was not found in the array.\n\n\n"); } - else { printf("\n\nInvalid Argument For Choice, Exiting...\n\n\n"); } - -} \ No newline at end of file From c2648f2ced558065621f2e6777aac8271c88ef47 Mon Sep 17 00:00:00 2001 From: RoyalTaterYeeter <86218183+RoyalTaterYeeter@users.noreply.github.com> Date: Fri, 29 Sep 2023 22:18:30 +0530 Subject: [PATCH 05/12] Delete 2 directory --- 2/ACM_DSA_02.c | 132 ------------------------------------------------- 1 file changed, 132 deletions(-) delete mode 100644 2/ACM_DSA_02.c diff --git a/2/ACM_DSA_02.c b/2/ACM_DSA_02.c deleted file mode 100644 index 11c2660..0000000 --- a/2/ACM_DSA_02.c +++ /dev/null @@ -1,132 +0,0 @@ -#include - -/* Implement the bubble sort algorithm to sort an array of integers. */ - -void switch_vars(int* a, int* b) { *a ^= *b; *b = *a ^ *b; *a ^= *b; } - -void bubble_sort(int length_arr, int num_arr[]) { - - int i = 0, j, k; - - while (i < length_arr) { - - for (j = 0; j < length_arr - (i + 1); j++) { - - if (num_arr[j] > num_arr[j + 1]) { switch_vars(&num_arr[j], &num_arr[j + 1]); } - - } - - i++; - - } - - if (length_arr != 100) { - - printf("\nSorted Array:\n\n{ %d", num_arr[0]); - - for (i = 1; i < length_arr; i++) { printf(", %d", num_arr[i]); } - - printf(" }\n\n"); - - } - else { - - printf("\nSorted Array:\n\n"); - - printf("{"); - - for (j = 0; j < length_arr / 10; j++) { - - printf("\t%d", num_arr[j]); - - for (i = j + (length_arr / 10); i < length_arr; i += length_arr / 10) { printf(",\t%d", num_arr[i]); } - - if (j == (length_arr / 10) - 1) { printf("\t}\n"); continue; } - - printf("\n"); - - } - - } -} - -void main() { - - int arr_choice; - - printf("\nHello!\n\nPlease Select An Option:\n\n\t1. Enter Elements To Populate Custom Array, Then Use Bubble Sort.\n\t2. Test Bubble Sort Using Pre-Defined Unsorted Array.\n\n"); - - printf("=>\t"); scanf("%d", &arr_choice); - - switch (arr_choice) { - - case 1: { - - printf("\n\nPlease Enter The Number Of Elements You Wish To Add To The Array:\n\n"); - - int n, i, j; - - printf("=>\tn\t:\t"); scanf("%d", &n); - - int num_arr[n]; - - printf("\nPlease Enter Elements:\n\n"); - - for (i = 0; i < n; i++) { printf("=>\tELEMENT-%d\t:\t", i + 1); scanf("%d", &num_arr[i]); } - - printf("\nUnsorted Array:\n\n{ %d", num_arr[0]); - - for (i = 1; i < n; i++) { printf(", %d", num_arr[i]); } - - printf(" }\n\n"); - - bubble_sort(n, num_arr); - - break; - - } - - case 2: { - - int n = 100, num_arr[100] = { - - 0, 260, 267, 268, 13, 14, 16, 277, 278, 24, - 26, 27, 282, 29, 284, 31, 34, 291, 36, 294, - 39, 298, 44, 45, 46, 306, 51, 310, 55, 56, - 57, 59, 60, 318, 321, 324, 69, 71, 77, 337, - 338, 86, 87, 342, 89, 90, 346, 348, 98, 355, - 100, 356, 102, 357, 359, 105, 361, 363, 109, 365, - 366, 112, 368, 370, 371, 372, 117, 118, 120, 122, - 124, 130, 133, 137, 138, 141, 149, 153, 154, 157, - 159, 160, 168, 171, 178, 181, 183, 184, 194, 197, - 202, 205, 213, 214, 223, 224, 225, 231, 232, 236 - - }; - - printf("\n\nHere Is An Array Of 100 Elements (Read Left-to-Right, Top-to-Bottom, Sequentially):\n\n"); - - int i, j; - - printf("{"); - - for (j = 0; j < n / 10; j++) { - - printf("\t%d", num_arr[j]); - - for (i = j + (n / 10); i < n; i += n / 10) { printf(",\t%d", num_arr[i]); } - - if ( j == (n / 10) - 1) { printf("\t}\n"); continue; } - - printf("\n"); - - } - - bubble_sort(n, num_arr); - - break; - - } - - } - -} \ No newline at end of file From 709e1109e8e408e0fa5fd0d807f5e14d32fbc66d Mon Sep 17 00:00:00 2001 From: RoyalTaterYeeter <86218183+RoyalTaterYeeter@users.noreply.github.com> Date: Fri, 29 Sep 2023 22:18:38 +0530 Subject: [PATCH 06/12] Delete 1 directory --- 1/ACM_DSA_01.c | 127 ------------------------------------------------- 1 file changed, 127 deletions(-) delete mode 100644 1/ACM_DSA_01.c diff --git a/1/ACM_DSA_01.c b/1/ACM_DSA_01.c deleted file mode 100644 index 8f83a80..0000000 --- a/1/ACM_DSA_01.c +++ /dev/null @@ -1,127 +0,0 @@ -#include - -/* Implement a binary search algorithm to find the index of a given element in a sorted array. */ - -int binsrch(int arr_len, int arr[]) { - - int l_index = 0, r_index = arr_len - 1, t, m_index; - - printf("\nPlease Enter Value To Be Searched For Using The Binary Search Algorithm:\n\n=>\tTARGET\t:\t"); - scanf("%d", &t); - - while (l_index <= r_index) { - - m_index = (l_index + r_index)/2; - - if (arr[m_index] == t) { return m_index; } - - if (arr[m_index] < t) { l_index = m_index + 1; continue; } - else if (arr[m_index] > t) { r_index = m_index - 1; continue; } - - } - - return -1; - -} - -void main() { - - int arr_ch, t_index; - - printf("\nHello!\n\nPlease Select An Option:\n\n\t1. Enter Elements To Populate Custom Array, Then Use Binary Search.\n\t2. Test Binary Search Using Pre-Defined Array.\n\n"); - - printf("=>\t"); scanf("%d", &arr_ch); - - while (1) { - - if (arr_ch == 1) { - - printf("\n\nPlease Enter The Number Of Elements You Wish To Add To The Array:\n\n"); - - int n, i, j; - - printf("=>\tn\t:\t"); scanf("%d", &n); - - int num_arr[n]; - - printf("\nPlease Enter Elements:\n\n"); - - for (i = 0; i < n; i++) { printf("=>\tELEMENT-%d\t:\t", i + 1); scanf("%d", &num_arr[i]); } - - // sorting - for (i = 0; i < n; i++) { - - for (j = i + 1; j < n; ++j) { - - if (num_arr[i] > num_arr[j]) { - - num_arr[i] ^= num_arr[j]; - num_arr[j] = num_arr[i] ^ num_arr[j]; - num_arr[i] ^= num_arr[j]; - - } - - } - - } - - printf("\nSorted Array:\n\n{ %d", num_arr[0]); - - for (i = 1; i < n; i++) { printf(", %d", num_arr[i]); } - - printf(" }\n\n"); - - t_index = binsrch(n, num_arr); - - break; - - } - else if (arr_ch == 2) { - - int n = 100, num_arr[100] = { - - 1, 2, 4, 5, 6, 7, 10, 11, 14, 16, - 19, 20, 21, 24, 25, 26, 29, 31, 32, 33, - 34, 35, 37, 43, 45, 46, 47, 51, 52, 53, - 56, 58, 59, 62, 63, 66, 67, 71, 72, 74, - 76, 77, 79, 83, 84, 86, 88, 89, 91, 93, - 95, 96, 97, 101, 123, 143, 150, 158, 172, 184, - 221, 224, 232, 235, 245, 279, 299, 304, 306, 315, - 318, 330, 363, 366, 402, 408, 516, 535, 551, 553, - 558, 562, 567, 583, 586, 627, 640, 675, 693, 719, - 728, 756, 769, 784, 820, 838, 855, 867, 871, 897 - - }; - - printf("\n\nHere Is An Array Of 100 Elements (Read Left-to-Right, Top-to-Bottom, Sequentially.):\n\n"); - - int i, j; - - printf("{"); - - for (j = 0; j < n / 10; j++) { - - printf("\t%d", num_arr[j]); - - for (i = j + (n / 10); i < n; i += n / 10) { printf(",\t%d", num_arr[i]); } - - if (j == (n / 10) - 1) { printf("\t}\n"); continue; } - - printf("\n"); - - } - - t_index = binsrch(n, num_arr); - - break; - - } - else { t_index = -2; break; } - - } - - if (t_index >= 0) { printf("\n\nThe element is present at the index %d.\n\n\n", t_index); } - else if (t_index == -1) { printf("\n\nThe element was not found in the array.\n\n\n"); } - else { printf("\n\nInvalid Argument For Choice, Exiting...\n\n\n"); } - -} From 9e75f4d246ec85d638f1b1d96d4852412767f023 Mon Sep 17 00:00:00 2001 From: RoyalTaterYeeter <86218183+RoyalTaterYeeter@users.noreply.github.com> Date: Fri, 29 Sep 2023 22:18:53 +0530 Subject: [PATCH 07/12] Delete 4 directory --- 4/ACM_DSA_04.c | 133 ------------------------------------------------- 1 file changed, 133 deletions(-) delete mode 100644 4/ACM_DSA_04.c diff --git a/4/ACM_DSA_04.c b/4/ACM_DSA_04.c deleted file mode 100644 index 017b9a9..0000000 --- a/4/ACM_DSA_04.c +++ /dev/null @@ -1,133 +0,0 @@ -#include - -/* Implement the selection sort algorithm to sort an array of integers. */ - -void switch_vars(int* a, int* b) { *a ^= *b; *b = *a ^ *b; *a ^= *b; } - -void selection_sort(int length_arr, int num_arr[]) { - - int i = 0, j, k; - - while (i < length_arr - 1){ - - int min_index = i; - - for (j = i; j < length_arr ; j++) { if (num_arr[j] < num_arr[min_index]) { min_index = j; } } - - switch_vars(&num_arr[i], &num_arr[min_index]); - - i++; - - } - - if (length_arr != 100) { - - printf("\nSorted Array:\n\n{ %d", num_arr[0]); - - for (i = 1; i < length_arr; i++) { printf(", %d", num_arr[i]); } - - printf(" }\n\n"); - - } - else { - - printf("\nSorted Array:\n\n"); - - printf("{"); - - for (j = 0; j < length_arr / 10; j++) { - - printf("\t%d", num_arr[j]); - - for (i = j + (length_arr / 10); i < length_arr; i += length_arr / 10) { printf(",\t%d", num_arr[i]); } - - if (j == (length_arr / 10) - 1) { printf("\t}\n"); continue; } - - printf("\n"); - - } - - } - -} - -void main() { - - int arr_choice; - - printf("\nHello!\n\nPlease Select An Option:\n\n\t1. Enter Elements To Populate Custom Array, Then Use Selection Sort.\n\t2. Test Selection Sort Using Pre-Defined Unsorted Array.\n\n"); - - printf("=>\t"); scanf("%d", &arr_choice); - - switch (arr_choice) { - - case 1: { - - printf("\n\nPlease Enter The Number Of Elements You Wish To Add To The Array:\n\n"); - - int n, i, j; - - printf("=>\tn\t:\t"); scanf("%d", &n); - - int num_arr[n]; - - printf("\nPlease Enter Elements:\n\n"); - - for (i = 0; i < n; i++) { printf("=>\tELEMENT-%d\t:\t", i + 1); scanf("%d", &num_arr[i]); } - - printf("\nUnsorted Array:\n\n{ %d", num_arr[0]); - - for (i = 1; i < n; i++) { printf(", %d", num_arr[i]); } - - printf(" }\n\n"); - - selection_sort(n, num_arr); - - break; - - } - - case 2: { - - int n = 100, num_arr[100] = { - - 0, 260, 267, 268, 13, 14, 16, 277, 278, 24, - 26, 27, 282, 29, 284, 31, 34, 291, 36, 294, - 39, 298, 44, 45, 46, 306, 51, 310, 55, 56, - 57, 59, 60, 318, 321, 324, 69, 71, 77, 337, - 338, 86, 87, 342, 89, 90, 346, 348, 98, 355, - 100, 356, 102, 357, 359, 105, 361, 363, 109, 365, - 366, 112, 368, 370, 371, 372, 117, 118, 120, 122, - 124, 130, 133, 137, 138, 141, 149, 153, 154, 157, - 159, 160, 168, 171, 178, 181, 183, 184, 194, 197, - 202, 205, 213, 214, 223, 224, 225, 231, 232, 236 - - }; - - printf("\n\nHere Is An Array Of 100 Elements (Read Left-to-Right, Top-to-Bottom, Sequentially):\n\n"); - - int i, j; - - printf("{"); - - for (j = 0; j < n / 10; j++) { - - printf("\t%d", num_arr[j]); - - for (i = j + (n / 10); i < n; i += n / 10) { printf(",\t%d", num_arr[i]); } - - if (j == (n / 10) - 1) { printf("\t}\n"); continue; } - - printf("\n"); - - } - - selection_sort(n, num_arr); - - break; - - } - - } - -} \ No newline at end of file From 45bac60c2fefc96197d9775f8b24fa12ad6d6750 Mon Sep 17 00:00:00 2001 From: RoyalTaterYeeter <86218183+RoyalTaterYeeter@users.noreply.github.com> Date: Fri, 29 Sep 2023 22:19:13 +0530 Subject: [PATCH 08/12] Delete Data Structure Algorithms/1 directory --- Data Structure Algorithms/1/ACM_DSA_01.c | 127 ----------------------- 1 file changed, 127 deletions(-) delete mode 100644 Data Structure Algorithms/1/ACM_DSA_01.c diff --git a/Data Structure Algorithms/1/ACM_DSA_01.c b/Data Structure Algorithms/1/ACM_DSA_01.c deleted file mode 100644 index 8f83a80..0000000 --- a/Data Structure Algorithms/1/ACM_DSA_01.c +++ /dev/null @@ -1,127 +0,0 @@ -#include - -/* Implement a binary search algorithm to find the index of a given element in a sorted array. */ - -int binsrch(int arr_len, int arr[]) { - - int l_index = 0, r_index = arr_len - 1, t, m_index; - - printf("\nPlease Enter Value To Be Searched For Using The Binary Search Algorithm:\n\n=>\tTARGET\t:\t"); - scanf("%d", &t); - - while (l_index <= r_index) { - - m_index = (l_index + r_index)/2; - - if (arr[m_index] == t) { return m_index; } - - if (arr[m_index] < t) { l_index = m_index + 1; continue; } - else if (arr[m_index] > t) { r_index = m_index - 1; continue; } - - } - - return -1; - -} - -void main() { - - int arr_ch, t_index; - - printf("\nHello!\n\nPlease Select An Option:\n\n\t1. Enter Elements To Populate Custom Array, Then Use Binary Search.\n\t2. Test Binary Search Using Pre-Defined Array.\n\n"); - - printf("=>\t"); scanf("%d", &arr_ch); - - while (1) { - - if (arr_ch == 1) { - - printf("\n\nPlease Enter The Number Of Elements You Wish To Add To The Array:\n\n"); - - int n, i, j; - - printf("=>\tn\t:\t"); scanf("%d", &n); - - int num_arr[n]; - - printf("\nPlease Enter Elements:\n\n"); - - for (i = 0; i < n; i++) { printf("=>\tELEMENT-%d\t:\t", i + 1); scanf("%d", &num_arr[i]); } - - // sorting - for (i = 0; i < n; i++) { - - for (j = i + 1; j < n; ++j) { - - if (num_arr[i] > num_arr[j]) { - - num_arr[i] ^= num_arr[j]; - num_arr[j] = num_arr[i] ^ num_arr[j]; - num_arr[i] ^= num_arr[j]; - - } - - } - - } - - printf("\nSorted Array:\n\n{ %d", num_arr[0]); - - for (i = 1; i < n; i++) { printf(", %d", num_arr[i]); } - - printf(" }\n\n"); - - t_index = binsrch(n, num_arr); - - break; - - } - else if (arr_ch == 2) { - - int n = 100, num_arr[100] = { - - 1, 2, 4, 5, 6, 7, 10, 11, 14, 16, - 19, 20, 21, 24, 25, 26, 29, 31, 32, 33, - 34, 35, 37, 43, 45, 46, 47, 51, 52, 53, - 56, 58, 59, 62, 63, 66, 67, 71, 72, 74, - 76, 77, 79, 83, 84, 86, 88, 89, 91, 93, - 95, 96, 97, 101, 123, 143, 150, 158, 172, 184, - 221, 224, 232, 235, 245, 279, 299, 304, 306, 315, - 318, 330, 363, 366, 402, 408, 516, 535, 551, 553, - 558, 562, 567, 583, 586, 627, 640, 675, 693, 719, - 728, 756, 769, 784, 820, 838, 855, 867, 871, 897 - - }; - - printf("\n\nHere Is An Array Of 100 Elements (Read Left-to-Right, Top-to-Bottom, Sequentially.):\n\n"); - - int i, j; - - printf("{"); - - for (j = 0; j < n / 10; j++) { - - printf("\t%d", num_arr[j]); - - for (i = j + (n / 10); i < n; i += n / 10) { printf(",\t%d", num_arr[i]); } - - if (j == (n / 10) - 1) { printf("\t}\n"); continue; } - - printf("\n"); - - } - - t_index = binsrch(n, num_arr); - - break; - - } - else { t_index = -2; break; } - - } - - if (t_index >= 0) { printf("\n\nThe element is present at the index %d.\n\n\n", t_index); } - else if (t_index == -1) { printf("\n\nThe element was not found in the array.\n\n\n"); } - else { printf("\n\nInvalid Argument For Choice, Exiting...\n\n\n"); } - -} From 2f38317be1ecc926948b56787b49b89466734969 Mon Sep 17 00:00:00 2001 From: RoyalTaterYeeter <86218183+RoyalTaterYeeter@users.noreply.github.com> Date: Fri, 29 Sep 2023 22:20:15 +0530 Subject: [PATCH 09/12] Delete Data Structure Algorithms directory --- Data Structure Algorithms/2/ACM_DSA_02.c | 132 ---------------------- Data Structure Algorithms/3/ACM_DSA_03.c | 105 ------------------ Data Structure Algorithms/4/ACM_DSA_04.c | 133 ----------------------- 3 files changed, 370 deletions(-) delete mode 100644 Data Structure Algorithms/2/ACM_DSA_02.c delete mode 100644 Data Structure Algorithms/3/ACM_DSA_03.c delete mode 100644 Data Structure Algorithms/4/ACM_DSA_04.c diff --git a/Data Structure Algorithms/2/ACM_DSA_02.c b/Data Structure Algorithms/2/ACM_DSA_02.c deleted file mode 100644 index 11c2660..0000000 --- a/Data Structure Algorithms/2/ACM_DSA_02.c +++ /dev/null @@ -1,132 +0,0 @@ -#include - -/* Implement the bubble sort algorithm to sort an array of integers. */ - -void switch_vars(int* a, int* b) { *a ^= *b; *b = *a ^ *b; *a ^= *b; } - -void bubble_sort(int length_arr, int num_arr[]) { - - int i = 0, j, k; - - while (i < length_arr) { - - for (j = 0; j < length_arr - (i + 1); j++) { - - if (num_arr[j] > num_arr[j + 1]) { switch_vars(&num_arr[j], &num_arr[j + 1]); } - - } - - i++; - - } - - if (length_arr != 100) { - - printf("\nSorted Array:\n\n{ %d", num_arr[0]); - - for (i = 1; i < length_arr; i++) { printf(", %d", num_arr[i]); } - - printf(" }\n\n"); - - } - else { - - printf("\nSorted Array:\n\n"); - - printf("{"); - - for (j = 0; j < length_arr / 10; j++) { - - printf("\t%d", num_arr[j]); - - for (i = j + (length_arr / 10); i < length_arr; i += length_arr / 10) { printf(",\t%d", num_arr[i]); } - - if (j == (length_arr / 10) - 1) { printf("\t}\n"); continue; } - - printf("\n"); - - } - - } -} - -void main() { - - int arr_choice; - - printf("\nHello!\n\nPlease Select An Option:\n\n\t1. Enter Elements To Populate Custom Array, Then Use Bubble Sort.\n\t2. Test Bubble Sort Using Pre-Defined Unsorted Array.\n\n"); - - printf("=>\t"); scanf("%d", &arr_choice); - - switch (arr_choice) { - - case 1: { - - printf("\n\nPlease Enter The Number Of Elements You Wish To Add To The Array:\n\n"); - - int n, i, j; - - printf("=>\tn\t:\t"); scanf("%d", &n); - - int num_arr[n]; - - printf("\nPlease Enter Elements:\n\n"); - - for (i = 0; i < n; i++) { printf("=>\tELEMENT-%d\t:\t", i + 1); scanf("%d", &num_arr[i]); } - - printf("\nUnsorted Array:\n\n{ %d", num_arr[0]); - - for (i = 1; i < n; i++) { printf(", %d", num_arr[i]); } - - printf(" }\n\n"); - - bubble_sort(n, num_arr); - - break; - - } - - case 2: { - - int n = 100, num_arr[100] = { - - 0, 260, 267, 268, 13, 14, 16, 277, 278, 24, - 26, 27, 282, 29, 284, 31, 34, 291, 36, 294, - 39, 298, 44, 45, 46, 306, 51, 310, 55, 56, - 57, 59, 60, 318, 321, 324, 69, 71, 77, 337, - 338, 86, 87, 342, 89, 90, 346, 348, 98, 355, - 100, 356, 102, 357, 359, 105, 361, 363, 109, 365, - 366, 112, 368, 370, 371, 372, 117, 118, 120, 122, - 124, 130, 133, 137, 138, 141, 149, 153, 154, 157, - 159, 160, 168, 171, 178, 181, 183, 184, 194, 197, - 202, 205, 213, 214, 223, 224, 225, 231, 232, 236 - - }; - - printf("\n\nHere Is An Array Of 100 Elements (Read Left-to-Right, Top-to-Bottom, Sequentially):\n\n"); - - int i, j; - - printf("{"); - - for (j = 0; j < n / 10; j++) { - - printf("\t%d", num_arr[j]); - - for (i = j + (n / 10); i < n; i += n / 10) { printf(",\t%d", num_arr[i]); } - - if ( j == (n / 10) - 1) { printf("\t}\n"); continue; } - - printf("\n"); - - } - - bubble_sort(n, num_arr); - - break; - - } - - } - -} \ No newline at end of file diff --git a/Data Structure Algorithms/3/ACM_DSA_03.c b/Data Structure Algorithms/3/ACM_DSA_03.c deleted file mode 100644 index ae56117..0000000 --- a/Data Structure Algorithms/3/ACM_DSA_03.c +++ /dev/null @@ -1,105 +0,0 @@ -#include - -/* Implement a linear search algorithm to find the index of a given element in an array. */ - -int linsrch(int arr_len, int arr[]) { - - int target, i; - - printf("\nPlease Enter Value To Be Searched For Using The Linear Search Algorithm:\n\n=>\tTARGET\t:\t"); - scanf("%d", &target); - - for (i = 0; i < arr_len; i++) { - - if (target == arr[i]) { return i; } - - } - - return -1; - -} - -void main() { - - int arr_ch, t_index; - - printf("\nHello!\n\nPlease Select An Option:\n\n\t1. Enter Elements To Populate Custom Array, Then Use Linear Search.\n\t2. Test Linear Search Using Pre-Defined Array.\n\n"); - - printf("=>\t"); scanf("%d", &arr_ch); - - while (1) { - - if (arr_ch == 1) { - - printf("\n\nPlease Enter The Number Of Elements You Wish To Add To The Array:\n\n"); - - int n, i, j; - - printf("=>\tn\t:\t"); scanf("%d", &n); - - int num_arr[n]; - - printf("\nPlease Enter Elements:\n\n"); - - for (i = 0; i < n; i++) { printf("=>\tELEMENT-%d\t:\t", i + 1); scanf("%d", &num_arr[i]); } - - printf("\nArray:\n\n{ %d", num_arr[0]); - - for (i = 1; i < n; i++) { printf(", %d", num_arr[i]); } - - printf(" }\n\n"); - - t_index = linsrch(n, num_arr); - - break; - - } - else if (arr_ch == 2) { - - int n = 100, num_arr[100] = { - - 0, 260, 267, 268, 13, 14, 16, 277, 278, 24, - 26, 27, 282, 29, 284, 31, 34, 291, 36, 294, - 39, 298, 44, 45, 46, 306, 51, 310, 55, 56, - 57, 59, 60, 318, 321, 324, 69, 71, 77, 337, - 338, 86, 87, 342, 89, 90, 346, 348, 98, 355, - 100, 356, 102, 357, 359, 105, 361, 363, 109, 365, - 366, 112, 368, 370, 371, 372, 117, 118, 120, 122, - 124, 130, 133, 137, 138, 141, 149, 153, 154, 157, - 159, 160, 168, 171, 178, 181, 183, 184, 194, 197, - 202, 205, 213, 214, 223, 224, 225, 231, 232, 236 - - }; - - printf("\n\nHere Is An Array Of 100 Elements (Read Left-to-Right, Top-to-Bottom, Sequentially.):\n\n"); - - int i, j; - - printf("{"); - - for (j = 0; j < n / 10; j++) { - - printf("\t%d", num_arr[j]); - - for (i = j + (n / 10); i < n; i += n / 10) { printf(",\t%d", num_arr[i]); } - - if (j == (n / 10) - 1) { printf("\t}\n"); continue; } - - printf("\n"); - - } - - t_index = linsrch(n, num_arr); - - break; - - } - else { t_index = -2; break; } - - } - - if (t_index >= 0) { printf("\n\nThe element is present at the index %d.\n\n\n", t_index); } - else if (t_index == -1) { printf("\n\nThe element was not found in the array.\n\n\n"); } - else { printf("\n\nInvalid Argument For Choice, Exiting...\n\n\n"); } - -} \ No newline at end of file diff --git a/Data Structure Algorithms/4/ACM_DSA_04.c b/Data Structure Algorithms/4/ACM_DSA_04.c deleted file mode 100644 index 017b9a9..0000000 --- a/Data Structure Algorithms/4/ACM_DSA_04.c +++ /dev/null @@ -1,133 +0,0 @@ -#include - -/* Implement the selection sort algorithm to sort an array of integers. */ - -void switch_vars(int* a, int* b) { *a ^= *b; *b = *a ^ *b; *a ^= *b; } - -void selection_sort(int length_arr, int num_arr[]) { - - int i = 0, j, k; - - while (i < length_arr - 1){ - - int min_index = i; - - for (j = i; j < length_arr ; j++) { if (num_arr[j] < num_arr[min_index]) { min_index = j; } } - - switch_vars(&num_arr[i], &num_arr[min_index]); - - i++; - - } - - if (length_arr != 100) { - - printf("\nSorted Array:\n\n{ %d", num_arr[0]); - - for (i = 1; i < length_arr; i++) { printf(", %d", num_arr[i]); } - - printf(" }\n\n"); - - } - else { - - printf("\nSorted Array:\n\n"); - - printf("{"); - - for (j = 0; j < length_arr / 10; j++) { - - printf("\t%d", num_arr[j]); - - for (i = j + (length_arr / 10); i < length_arr; i += length_arr / 10) { printf(",\t%d", num_arr[i]); } - - if (j == (length_arr / 10) - 1) { printf("\t}\n"); continue; } - - printf("\n"); - - } - - } - -} - -void main() { - - int arr_choice; - - printf("\nHello!\n\nPlease Select An Option:\n\n\t1. Enter Elements To Populate Custom Array, Then Use Selection Sort.\n\t2. Test Selection Sort Using Pre-Defined Unsorted Array.\n\n"); - - printf("=>\t"); scanf("%d", &arr_choice); - - switch (arr_choice) { - - case 1: { - - printf("\n\nPlease Enter The Number Of Elements You Wish To Add To The Array:\n\n"); - - int n, i, j; - - printf("=>\tn\t:\t"); scanf("%d", &n); - - int num_arr[n]; - - printf("\nPlease Enter Elements:\n\n"); - - for (i = 0; i < n; i++) { printf("=>\tELEMENT-%d\t:\t", i + 1); scanf("%d", &num_arr[i]); } - - printf("\nUnsorted Array:\n\n{ %d", num_arr[0]); - - for (i = 1; i < n; i++) { printf(", %d", num_arr[i]); } - - printf(" }\n\n"); - - selection_sort(n, num_arr); - - break; - - } - - case 2: { - - int n = 100, num_arr[100] = { - - 0, 260, 267, 268, 13, 14, 16, 277, 278, 24, - 26, 27, 282, 29, 284, 31, 34, 291, 36, 294, - 39, 298, 44, 45, 46, 306, 51, 310, 55, 56, - 57, 59, 60, 318, 321, 324, 69, 71, 77, 337, - 338, 86, 87, 342, 89, 90, 346, 348, 98, 355, - 100, 356, 102, 357, 359, 105, 361, 363, 109, 365, - 366, 112, 368, 370, 371, 372, 117, 118, 120, 122, - 124, 130, 133, 137, 138, 141, 149, 153, 154, 157, - 159, 160, 168, 171, 178, 181, 183, 184, 194, 197, - 202, 205, 213, 214, 223, 224, 225, 231, 232, 236 - - }; - - printf("\n\nHere Is An Array Of 100 Elements (Read Left-to-Right, Top-to-Bottom, Sequentially):\n\n"); - - int i, j; - - printf("{"); - - for (j = 0; j < n / 10; j++) { - - printf("\t%d", num_arr[j]); - - for (i = j + (n / 10); i < n; i += n / 10) { printf(",\t%d", num_arr[i]); } - - if (j == (n / 10) - 1) { printf("\t}\n"); continue; } - - printf("\n"); - - } - - selection_sort(n, num_arr); - - break; - - } - - } - -} \ No newline at end of file From 05fa615e82e369298d226dffdcf51e63f44b5b4a Mon Sep 17 00:00:00 2001 From: Agamvir Singh Gill <86218183+RoyalTaterYeeter@users.noreply.github.com> Date: Fri, 29 Sep 2023 22:20:59 +0530 Subject: [PATCH 10/12] Delete DSA_QUESTIONS.txt --- DSA_QUESTIONS.txt | 21 --------------------- 1 file changed, 21 deletions(-) delete mode 100644 DSA_QUESTIONS.txt diff --git a/DSA_QUESTIONS.txt b/DSA_QUESTIONS.txt deleted file mode 100644 index 5eb36f2..0000000 --- a/DSA_QUESTIONS.txt +++ /dev/null @@ -1,21 +0,0 @@ - -DATA STRUCTURE ALGORITHMS - ACM TECHNICAL MENTORSHIP - -Questions: - -1. Implement a binary search algorithm to find the index of a given element in a sorted array. - -2. Implement the bubble sort algorithm to sort an array of integers. - -3. Implement a linear search algorithm to find the index of a given element in an array. - -4. Implement the selection sort algorithm to sort an array of integers. - -5. Write a recursive function to generate series of Fibonacci numbers up to some value n. - -6. Implement a function to determine whether a given string is a palindrome. - -7. Write a recursive function to calculate the result of raising a number to a positive integer exponent. - -8. Write a program in C to count the number of vowels and consonants in a string. - From 54986bbef8985b6215001230c1f29e7356032059 Mon Sep 17 00:00:00 2001 From: Agamvir Singh Gill <86218183+RoyalTaterYeeter@users.noreply.github.com> Date: Fri, 29 Sep 2023 22:22:07 +0530 Subject: [PATCH 11/12] Properly uploaded experiments 1 to 4 --- Data Structure Algorithms/1/ACM_DSA_01.c | 127 +++++++++++++++++++ Data Structure Algorithms/2/ACM_DSA_02.c | 132 +++++++++++++++++++ Data Structure Algorithms/3/ACM_DSA_03.c | 105 ++++++++++++++++ Data Structure Algorithms/4/ACM_DSA_04.c | 133 ++++++++++++++++++++ Data Structure Algorithms/DSA_QUESTIONS.txt | 21 ++++ 5 files changed, 518 insertions(+) create mode 100644 Data Structure Algorithms/1/ACM_DSA_01.c create mode 100644 Data Structure Algorithms/2/ACM_DSA_02.c create mode 100644 Data Structure Algorithms/3/ACM_DSA_03.c create mode 100644 Data Structure Algorithms/4/ACM_DSA_04.c create mode 100644 Data Structure Algorithms/DSA_QUESTIONS.txt diff --git a/Data Structure Algorithms/1/ACM_DSA_01.c b/Data Structure Algorithms/1/ACM_DSA_01.c new file mode 100644 index 0000000..8f83a80 --- /dev/null +++ b/Data Structure Algorithms/1/ACM_DSA_01.c @@ -0,0 +1,127 @@ +#include + +/* Implement a binary search algorithm to find the index of a given element in a sorted array. */ + +int binsrch(int arr_len, int arr[]) { + + int l_index = 0, r_index = arr_len - 1, t, m_index; + + printf("\nPlease Enter Value To Be Searched For Using The Binary Search Algorithm:\n\n=>\tTARGET\t:\t"); + scanf("%d", &t); + + while (l_index <= r_index) { + + m_index = (l_index + r_index)/2; + + if (arr[m_index] == t) { return m_index; } + + if (arr[m_index] < t) { l_index = m_index + 1; continue; } + else if (arr[m_index] > t) { r_index = m_index - 1; continue; } + + } + + return -1; + +} + +void main() { + + int arr_ch, t_index; + + printf("\nHello!\n\nPlease Select An Option:\n\n\t1. Enter Elements To Populate Custom Array, Then Use Binary Search.\n\t2. Test Binary Search Using Pre-Defined Array.\n\n"); + + printf("=>\t"); scanf("%d", &arr_ch); + + while (1) { + + if (arr_ch == 1) { + + printf("\n\nPlease Enter The Number Of Elements You Wish To Add To The Array:\n\n"); + + int n, i, j; + + printf("=>\tn\t:\t"); scanf("%d", &n); + + int num_arr[n]; + + printf("\nPlease Enter Elements:\n\n"); + + for (i = 0; i < n; i++) { printf("=>\tELEMENT-%d\t:\t", i + 1); scanf("%d", &num_arr[i]); } + + // sorting + for (i = 0; i < n; i++) { + + for (j = i + 1; j < n; ++j) { + + if (num_arr[i] > num_arr[j]) { + + num_arr[i] ^= num_arr[j]; + num_arr[j] = num_arr[i] ^ num_arr[j]; + num_arr[i] ^= num_arr[j]; + + } + + } + + } + + printf("\nSorted Array:\n\n{ %d", num_arr[0]); + + for (i = 1; i < n; i++) { printf(", %d", num_arr[i]); } + + printf(" }\n\n"); + + t_index = binsrch(n, num_arr); + + break; + + } + else if (arr_ch == 2) { + + int n = 100, num_arr[100] = { + + 1, 2, 4, 5, 6, 7, 10, 11, 14, 16, + 19, 20, 21, 24, 25, 26, 29, 31, 32, 33, + 34, 35, 37, 43, 45, 46, 47, 51, 52, 53, + 56, 58, 59, 62, 63, 66, 67, 71, 72, 74, + 76, 77, 79, 83, 84, 86, 88, 89, 91, 93, + 95, 96, 97, 101, 123, 143, 150, 158, 172, 184, + 221, 224, 232, 235, 245, 279, 299, 304, 306, 315, + 318, 330, 363, 366, 402, 408, 516, 535, 551, 553, + 558, 562, 567, 583, 586, 627, 640, 675, 693, 719, + 728, 756, 769, 784, 820, 838, 855, 867, 871, 897 + + }; + + printf("\n\nHere Is An Array Of 100 Elements (Read Left-to-Right, Top-to-Bottom, Sequentially.):\n\n"); + + int i, j; + + printf("{"); + + for (j = 0; j < n / 10; j++) { + + printf("\t%d", num_arr[j]); + + for (i = j + (n / 10); i < n; i += n / 10) { printf(",\t%d", num_arr[i]); } + + if (j == (n / 10) - 1) { printf("\t}\n"); continue; } + + printf("\n"); + + } + + t_index = binsrch(n, num_arr); + + break; + + } + else { t_index = -2; break; } + + } + + if (t_index >= 0) { printf("\n\nThe element is present at the index %d.\n\n\n", t_index); } + else if (t_index == -1) { printf("\n\nThe element was not found in the array.\n\n\n"); } + else { printf("\n\nInvalid Argument For Choice, Exiting...\n\n\n"); } + +} diff --git a/Data Structure Algorithms/2/ACM_DSA_02.c b/Data Structure Algorithms/2/ACM_DSA_02.c new file mode 100644 index 0000000..11c2660 --- /dev/null +++ b/Data Structure Algorithms/2/ACM_DSA_02.c @@ -0,0 +1,132 @@ +#include + +/* Implement the bubble sort algorithm to sort an array of integers. */ + +void switch_vars(int* a, int* b) { *a ^= *b; *b = *a ^ *b; *a ^= *b; } + +void bubble_sort(int length_arr, int num_arr[]) { + + int i = 0, j, k; + + while (i < length_arr) { + + for (j = 0; j < length_arr - (i + 1); j++) { + + if (num_arr[j] > num_arr[j + 1]) { switch_vars(&num_arr[j], &num_arr[j + 1]); } + + } + + i++; + + } + + if (length_arr != 100) { + + printf("\nSorted Array:\n\n{ %d", num_arr[0]); + + for (i = 1; i < length_arr; i++) { printf(", %d", num_arr[i]); } + + printf(" }\n\n"); + + } + else { + + printf("\nSorted Array:\n\n"); + + printf("{"); + + for (j = 0; j < length_arr / 10; j++) { + + printf("\t%d", num_arr[j]); + + for (i = j + (length_arr / 10); i < length_arr; i += length_arr / 10) { printf(",\t%d", num_arr[i]); } + + if (j == (length_arr / 10) - 1) { printf("\t}\n"); continue; } + + printf("\n"); + + } + + } +} + +void main() { + + int arr_choice; + + printf("\nHello!\n\nPlease Select An Option:\n\n\t1. Enter Elements To Populate Custom Array, Then Use Bubble Sort.\n\t2. Test Bubble Sort Using Pre-Defined Unsorted Array.\n\n"); + + printf("=>\t"); scanf("%d", &arr_choice); + + switch (arr_choice) { + + case 1: { + + printf("\n\nPlease Enter The Number Of Elements You Wish To Add To The Array:\n\n"); + + int n, i, j; + + printf("=>\tn\t:\t"); scanf("%d", &n); + + int num_arr[n]; + + printf("\nPlease Enter Elements:\n\n"); + + for (i = 0; i < n; i++) { printf("=>\tELEMENT-%d\t:\t", i + 1); scanf("%d", &num_arr[i]); } + + printf("\nUnsorted Array:\n\n{ %d", num_arr[0]); + + for (i = 1; i < n; i++) { printf(", %d", num_arr[i]); } + + printf(" }\n\n"); + + bubble_sort(n, num_arr); + + break; + + } + + case 2: { + + int n = 100, num_arr[100] = { + + 0, 260, 267, 268, 13, 14, 16, 277, 278, 24, + 26, 27, 282, 29, 284, 31, 34, 291, 36, 294, + 39, 298, 44, 45, 46, 306, 51, 310, 55, 56, + 57, 59, 60, 318, 321, 324, 69, 71, 77, 337, + 338, 86, 87, 342, 89, 90, 346, 348, 98, 355, + 100, 356, 102, 357, 359, 105, 361, 363, 109, 365, + 366, 112, 368, 370, 371, 372, 117, 118, 120, 122, + 124, 130, 133, 137, 138, 141, 149, 153, 154, 157, + 159, 160, 168, 171, 178, 181, 183, 184, 194, 197, + 202, 205, 213, 214, 223, 224, 225, 231, 232, 236 + + }; + + printf("\n\nHere Is An Array Of 100 Elements (Read Left-to-Right, Top-to-Bottom, Sequentially):\n\n"); + + int i, j; + + printf("{"); + + for (j = 0; j < n / 10; j++) { + + printf("\t%d", num_arr[j]); + + for (i = j + (n / 10); i < n; i += n / 10) { printf(",\t%d", num_arr[i]); } + + if ( j == (n / 10) - 1) { printf("\t}\n"); continue; } + + printf("\n"); + + } + + bubble_sort(n, num_arr); + + break; + + } + + } + +} \ No newline at end of file diff --git a/Data Structure Algorithms/3/ACM_DSA_03.c b/Data Structure Algorithms/3/ACM_DSA_03.c new file mode 100644 index 0000000..ae56117 --- /dev/null +++ b/Data Structure Algorithms/3/ACM_DSA_03.c @@ -0,0 +1,105 @@ +#include + +/* Implement a linear search algorithm to find the index of a given element in an array. */ + +int linsrch(int arr_len, int arr[]) { + + int target, i; + + printf("\nPlease Enter Value To Be Searched For Using The Linear Search Algorithm:\n\n=>\tTARGET\t:\t"); + scanf("%d", &target); + + for (i = 0; i < arr_len; i++) { + + if (target == arr[i]) { return i; } + + } + + return -1; + +} + +void main() { + + int arr_ch, t_index; + + printf("\nHello!\n\nPlease Select An Option:\n\n\t1. Enter Elements To Populate Custom Array, Then Use Linear Search.\n\t2. Test Linear Search Using Pre-Defined Array.\n\n"); + + printf("=>\t"); scanf("%d", &arr_ch); + + while (1) { + + if (arr_ch == 1) { + + printf("\n\nPlease Enter The Number Of Elements You Wish To Add To The Array:\n\n"); + + int n, i, j; + + printf("=>\tn\t:\t"); scanf("%d", &n); + + int num_arr[n]; + + printf("\nPlease Enter Elements:\n\n"); + + for (i = 0; i < n; i++) { printf("=>\tELEMENT-%d\t:\t", i + 1); scanf("%d", &num_arr[i]); } + + printf("\nArray:\n\n{ %d", num_arr[0]); + + for (i = 1; i < n; i++) { printf(", %d", num_arr[i]); } + + printf(" }\n\n"); + + t_index = linsrch(n, num_arr); + + break; + + } + else if (arr_ch == 2) { + + int n = 100, num_arr[100] = { + + 0, 260, 267, 268, 13, 14, 16, 277, 278, 24, + 26, 27, 282, 29, 284, 31, 34, 291, 36, 294, + 39, 298, 44, 45, 46, 306, 51, 310, 55, 56, + 57, 59, 60, 318, 321, 324, 69, 71, 77, 337, + 338, 86, 87, 342, 89, 90, 346, 348, 98, 355, + 100, 356, 102, 357, 359, 105, 361, 363, 109, 365, + 366, 112, 368, 370, 371, 372, 117, 118, 120, 122, + 124, 130, 133, 137, 138, 141, 149, 153, 154, 157, + 159, 160, 168, 171, 178, 181, 183, 184, 194, 197, + 202, 205, 213, 214, 223, 224, 225, 231, 232, 236 + + }; + + printf("\n\nHere Is An Array Of 100 Elements (Read Left-to-Right, Top-to-Bottom, Sequentially.):\n\n"); + + int i, j; + + printf("{"); + + for (j = 0; j < n / 10; j++) { + + printf("\t%d", num_arr[j]); + + for (i = j + (n / 10); i < n; i += n / 10) { printf(",\t%d", num_arr[i]); } + + if (j == (n / 10) - 1) { printf("\t}\n"); continue; } + + printf("\n"); + + } + + t_index = linsrch(n, num_arr); + + break; + + } + else { t_index = -2; break; } + + } + + if (t_index >= 0) { printf("\n\nThe element is present at the index %d.\n\n\n", t_index); } + else if (t_index == -1) { printf("\n\nThe element was not found in the array.\n\n\n"); } + else { printf("\n\nInvalid Argument For Choice, Exiting...\n\n\n"); } + +} \ No newline at end of file diff --git a/Data Structure Algorithms/4/ACM_DSA_04.c b/Data Structure Algorithms/4/ACM_DSA_04.c new file mode 100644 index 0000000..017b9a9 --- /dev/null +++ b/Data Structure Algorithms/4/ACM_DSA_04.c @@ -0,0 +1,133 @@ +#include + +/* Implement the selection sort algorithm to sort an array of integers. */ + +void switch_vars(int* a, int* b) { *a ^= *b; *b = *a ^ *b; *a ^= *b; } + +void selection_sort(int length_arr, int num_arr[]) { + + int i = 0, j, k; + + while (i < length_arr - 1){ + + int min_index = i; + + for (j = i; j < length_arr ; j++) { if (num_arr[j] < num_arr[min_index]) { min_index = j; } } + + switch_vars(&num_arr[i], &num_arr[min_index]); + + i++; + + } + + if (length_arr != 100) { + + printf("\nSorted Array:\n\n{ %d", num_arr[0]); + + for (i = 1; i < length_arr; i++) { printf(", %d", num_arr[i]); } + + printf(" }\n\n"); + + } + else { + + printf("\nSorted Array:\n\n"); + + printf("{"); + + for (j = 0; j < length_arr / 10; j++) { + + printf("\t%d", num_arr[j]); + + for (i = j + (length_arr / 10); i < length_arr; i += length_arr / 10) { printf(",\t%d", num_arr[i]); } + + if (j == (length_arr / 10) - 1) { printf("\t}\n"); continue; } + + printf("\n"); + + } + + } + +} + +void main() { + + int arr_choice; + + printf("\nHello!\n\nPlease Select An Option:\n\n\t1. Enter Elements To Populate Custom Array, Then Use Selection Sort.\n\t2. Test Selection Sort Using Pre-Defined Unsorted Array.\n\n"); + + printf("=>\t"); scanf("%d", &arr_choice); + + switch (arr_choice) { + + case 1: { + + printf("\n\nPlease Enter The Number Of Elements You Wish To Add To The Array:\n\n"); + + int n, i, j; + + printf("=>\tn\t:\t"); scanf("%d", &n); + + int num_arr[n]; + + printf("\nPlease Enter Elements:\n\n"); + + for (i = 0; i < n; i++) { printf("=>\tELEMENT-%d\t:\t", i + 1); scanf("%d", &num_arr[i]); } + + printf("\nUnsorted Array:\n\n{ %d", num_arr[0]); + + for (i = 1; i < n; i++) { printf(", %d", num_arr[i]); } + + printf(" }\n\n"); + + selection_sort(n, num_arr); + + break; + + } + + case 2: { + + int n = 100, num_arr[100] = { + + 0, 260, 267, 268, 13, 14, 16, 277, 278, 24, + 26, 27, 282, 29, 284, 31, 34, 291, 36, 294, + 39, 298, 44, 45, 46, 306, 51, 310, 55, 56, + 57, 59, 60, 318, 321, 324, 69, 71, 77, 337, + 338, 86, 87, 342, 89, 90, 346, 348, 98, 355, + 100, 356, 102, 357, 359, 105, 361, 363, 109, 365, + 366, 112, 368, 370, 371, 372, 117, 118, 120, 122, + 124, 130, 133, 137, 138, 141, 149, 153, 154, 157, + 159, 160, 168, 171, 178, 181, 183, 184, 194, 197, + 202, 205, 213, 214, 223, 224, 225, 231, 232, 236 + + }; + + printf("\n\nHere Is An Array Of 100 Elements (Read Left-to-Right, Top-to-Bottom, Sequentially):\n\n"); + + int i, j; + + printf("{"); + + for (j = 0; j < n / 10; j++) { + + printf("\t%d", num_arr[j]); + + for (i = j + (n / 10); i < n; i += n / 10) { printf(",\t%d", num_arr[i]); } + + if (j == (n / 10) - 1) { printf("\t}\n"); continue; } + + printf("\n"); + + } + + selection_sort(n, num_arr); + + break; + + } + + } + +} \ No newline at end of file diff --git a/Data Structure Algorithms/DSA_QUESTIONS.txt b/Data Structure Algorithms/DSA_QUESTIONS.txt new file mode 100644 index 0000000..5eb36f2 --- /dev/null +++ b/Data Structure Algorithms/DSA_QUESTIONS.txt @@ -0,0 +1,21 @@ + +DATA STRUCTURE ALGORITHMS - ACM TECHNICAL MENTORSHIP + +Questions: + +1. Implement a binary search algorithm to find the index of a given element in a sorted array. + +2. Implement the bubble sort algorithm to sort an array of integers. + +3. Implement a linear search algorithm to find the index of a given element in an array. + +4. Implement the selection sort algorithm to sort an array of integers. + +5. Write a recursive function to generate series of Fibonacci numbers up to some value n. + +6. Implement a function to determine whether a given string is a palindrome. + +7. Write a recursive function to calculate the result of raising a number to a positive integer exponent. + +8. Write a program in C to count the number of vowels and consonants in a string. + From 3529652cd42308d5467edb65ff19da3d36df38ed Mon Sep 17 00:00:00 2001 From: Agamvir Singh Gill <86218183+RoyalTaterYeeter@users.noreply.github.com> Date: Fri, 29 Sep 2023 22:22:46 +0530 Subject: [PATCH 12/12] Create README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..ea1962a --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# Technical-Mentorship-2023 + +Only questions up to question 4 have been uploaded.