DSA_Simulation_Questions
DSA_Simulation_Questions
Code:
#include <stdio.h>
int i, j, temp;
temp = arr[j];
arr[j + 1] = temp;
printf("\n");
int main() {
return 0;
Simulation:
Consider the array arr[] = {64, 34, 25, 12, 22, 11, 90}.
Pass 1:
- Compare 64 and 34. Since 64 > 34, swap them. New array: {34, 64, 25, 12, 22, 11, 90}
- Compare 64 and 25. Since 64 > 25, swap them. New array: {34, 25, 64, 12, 22, 11, 90}
...
Code:
#include <stdio.h>
arr[position] = element;
(*n)++;
int main() {
return 0;
Simulation:
Consider the array arr[] = {1, 2, 3, 4, 5}, with element = 10, position = 2 (0-indexed).
...
Code:
#include <stdio.h>
(*n)--;
int main() {
return 0;
Simulation:
Consider the array arr[] = {1, 2, 3, 4, 5}, and we want to delete the element at position = 2
(0-indexed).
...
Code:
#include <stdio.h>
if (arr[i] == target) {
return;
}
printf("Element not found\n");
int main() {
linearSearch(arr, n, target);
return 0;
Simulation:
Consider the array arr[] = {2, 3, 4, 10, 40}, and we want to search for the target = 10.
...
Code:
#include <stdio.h>
if (arr[mid] == target)
return mid;
else
high = mid - 1;
return -1;
int main() {
if (result != -1)
else
return 0;
Simulation:
Consider the array arr[] = {2, 3, 4, 10, 40}, and we want to search for the target = 10. The array is
...
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int temp;
temp = arr[j];
arr[j + 1] = temp;
int main() {
int arr[size];
}
clock_t start = clock();
bubbleSort(arr, size);
return 0;
Simulation:
This program measures the time taken to sort arrays of sizes 10, 100, and 1000 using bubble sort.