< Ace Coding /> πŸš€
337 subscribers
54 photos
2 videos
95 files
66 links
Welcome to Ace Coding! Join us for tips, tutorials, and insights on coding and software engineering. Stay updated with the latest content and elevate your programming skills!Let's learn and grow together in the world of software engineering!
Download Telegram
What’s wrong with the above snippet of code?
Anonymous Quiz
40%
a. Perfectly fine
14%
b. Sum is not printed
21%
c. Runtime error
24%
d. Compilation error
πŸ”₯4
Predict the output:

    int i = 0;
while (++i < 5);
cout << "i: " << i << endl;
Predict the output:

    int x = 5;
int y = 10;
(x > y ? x : y) = 50;
cout << "x: " << x << ", y: " << y << endl;
Predict the output:

    int a = (3, 4, 1, 2); 
cout << a ;
πŸ“ Types of Errors in a Program: πŸ’₯βš‘οΈπŸ”

πŸ’₯ Compilation Error: (Cannot compile, cannot run)
Occurs when the code has syntax issues, preventing it from being compiled. Common examples include missing semicolons, mismatched parentheses, or undeclared variables.
Example: int x = ;


⚑️ Runtime Error: (Compiles but cannot run, compilation comes before code execution or running)
Happens while the program is running. It usually occurs due to illegal operations like division by zero, accessing invalid memory, or infinite loops.
Example: int x = 5 / 0;


πŸ” Logical Error: (Code compiles and runs but won't result a correct output)
Occurs when the code runs without crashing, but it produces incorrect results due to flawed logic or assumptions. It can be tricky to spot as the program compiles and runs fine.
Example: int a = 5; int b = 2; cout << a - b; (Expecting multiplication but using subtraction)


πŸŒŸπŸš€ @AceCoding Presents! πŸš€πŸŒŸ
πŸ“š Simple Sorting Algorithms implementation in in C++

1. Insertion Sort
void insertion_sort(int arr[], int size) {
int temp, i, j;
for (i = 0; i < size; i++) {
temp = arr[i];
j = i;
while (j > 0 && arr[j-1] > temp) {
arr[j] = arr[j - 1];
j--;
}
arr[j] = temp;
}
}


2. Bubble Sort

void bubble_sort(int arr[], int size) {
for (int i = 0; i < size; i++) {
for (int j = i + 1; j < size; j++) {
if (arr[i] > arr[j]) {
swap(arr[i], arr[j]);
}
}
}
return;
}


βœ… Optimized version of bubble sort, which will give a TC of O(n) best case (array is already sorted)
void bubbleSortOptimized(int arr[], int size) {
for (int i = 0; i < size - 1; i++) {
bool swapped = false;
for (int j = 0; j < size - 1 - i; j++) {
if (arr[j] > arr[j + 1]) {
swap(arr[j], arr[j + 1]);
swapped = true;
}
}
if (!swapped) break;
}
}


3. Selection Sort

void selection_sort(int arr[], int size) {
int min_index;
for (int i = 0; i < size; i++) {
min_index = i;
for (int j = i + 1; j < size; j++) {
if (arr[j] < arr[min_index]) {
min_index = j;
}
}
swap(arr[i], arr[min_index;
}
}


βš™οΈ Which Sorting Algorithm is Best?

- Insertion Sort is efficient for small or nearly sorted datasets.
- Bubble Sort is simple but slow for large datasets (O(nΒ²) time complexity).
- Selection Sort is also O(nΒ²) but has a fixed number of swaps.

πŸŒŸπŸš€ @AceCoding Presents! πŸš€πŸŒŸ
Here you can see the trade-offs of different sorting algorithms πŸ“Š

πŸŒŸπŸš€ @AceCoding Presents! πŸš€πŸŒŸ
Forwarded from AASTU Software Engineering (John Robi)
DSA Exams.rar
24.8 MB
Previous DSA exams
πŸ“Š Big O (worst case) Visualization.

πŸŒŸπŸš€ @AceCoding Presents! πŸš€πŸŒŸ
βœ… Optimized version of bubble sort, which will give a TC of O(n) best case (array is already sorted)
void bubbleSortOptimized(int arr[], int n) {
for (int i = 0; i < n - 1; i++) {
bool swapped = false;
for (int j = 0; j < n - 1 - i; j++) {
if (arr[j] > arr[j + 1]) {
swap(arr[j], arr[j + 1]);
swapped = true;
}
}
if (!swapped) break;
}
}
πŸŒŸπŸš€ @AceCoding Presents! πŸš€πŸŒŸ
πŸŒŸπŸš€ @AceCoding Presents! πŸš€πŸŒŸ
βœ… When do we encounter a Time Complexity of O(n * log n)? To be more explicit O(n * log2 n) the base is 2 not 10.


Whenever we repeatedly divide the problem by 2 or multiply the input by 2 (as seen in algorithms like merge sort or heap sort), we often deal with quasi-linear time complexity, which is O(n * log n). This pattern is common in efficient sorting and searching algorithms, so keep it in mind when breaking down problems!

#DSA #TimeComplexity #CodingTips

@AceCoding
πŸ”₯2
DSA MID TEST 2023-ANSWERSHEET.pdf
700.7 KB
πŸ“šπŸš€ DSA AASTU 2023 Mid Exam

With Solution Answers πŸ“πŸ’‘

#AASTU #DSA #DSAmidexam #softwaremidexam

πŸŒŸπŸš€ @AceCoding Presents! πŸš€πŸŒŸ
Basic_data_structures_and_time_and_space_complexity.pdf
3.9 MB
From a2sv
πŸŒŸπŸš€ @AceCoding Presents! πŸš€πŸŒŸ
⚑1πŸ™1