/CS-F211

Repo containing problems and solutions of labsheets used for Data Structures and Algorithms course

Primary LanguageC

CS-F211

2-2, DSA course at BITS Pilani, Hyderabad Campus

Topics Covered

  • Time and Space Complexity
  • Searching and Sorting Algorithms
  • Stacks and Queues
  • Linked Lists
  • Priority Queues and Heaps
  • Hash Tables
  • BST, Balanced BST, Red Black Trees
  • Skip List
  • Divide and Conquer
  • Greedy Algorithm
  • Dynamic Programming
  • Graph Algorithms

Important Notes

Initializing Array Using Malloc

int** array;
// allocating memory for n pointers of size int*
array = (int**)malloc(n*sizeof(int*));
// allocating memory for n int values to each pointer
for(int i=0;i<n;i++){
  int* temp = (int*)malloc(n*sizeof(int));
  array[i] = temp;
}

Passing 2D-Array declared using DMA to function

int function(int** arr){
  // can access arr[i][j]
}

Finding length of Array in C

int arr[100];
int size = (&arr)[1]-arr;
// size = 100
// (&arr)[1] points to memory location just after the last element of array and arr points to base index of array
// similarly for character arrays

Finding length of 2D-Array in C

int arr[5][3];
int size = (&arr)[1]-arr;
// size = 5
// (&arr)[1] points to memory location just after the last row of array and arr points to base index of array

Lab Summary

Lab Topic Lab Sheet Date
1 Implementing Basic Algorithms like Two pointer, Sliding window, Quick sort etc. Lab 1 31 Jan 2023
2 Implementing basic operations on Singly linked list and Structures Lab 2 07 Feb 2023
3 Doubly Linked Lists and Binary Search Lab 3 14 Feb 2023
4 Sorting and Math Lab 4 21 Feb 2023
5 Recursion, Prefix Sum, Sliding Window, Bitmasking Lab 5 28 Feb 2023
6 Stacks and Queues Lab 6 07 Mar 2023
7 Heaps, Binary Trees and Binary Search Trees Lab 7 28 Mar 2023
8 Maps, Sets and Strings Lab 8 11 Apr 2023
9 Maps, Sets, Strings and Stacks Lab 9 18 Apr 2023
10 Divide and Conquer, Recap Lab 10 25 Apr 2023