Data structure and algorithm, Schemes and Mind Maps of Data Structures and Algorithms

These notes contains comprehensive notes on Data Structures and Algorithms (DSA), emphasizing time complexity analysis with C programming examples. It includes single and nested loop examples, recursive function analysis, and Big-O complexity comparisons. Topics like tree traversal (O(n) complexity) and prime number checks (O(√n) complexity) are also covered. The file provides practical problem-solving scenarios for competitive programming. Overall, it’s a focused resource for understanding algorithmic efficiency.

Typology: Schemes and Mind Maps

2024/2025

Available from 12/27/2024

hamza-anjum
hamza-anjum 🇵🇰

8 documents

1 / 30

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e

Partial preview of the text

Download Data structure and algorithm and more Schemes and Mind Maps Data Structures and Algorithms in PDF only on Docsity!

Source: https://stackoverflow.com/questions/3255/big-o-how-do-you-calculate-approximate-it

URBAN

Time Complexity – Competitive Practice Sheet

  1. Fine the time complexity of the func1 function in the program show in program1.c as follows: #include <stdio.h> void func1 (int array[], int length) { int sum = 0 ; int product = 1 ; for (int i = 0 ; i < length; i++) { sum += array[i]; } for (int i = 0 ; i < length; i++) { product *= array[i]; } } int main () { int arr[] = { 3 , 5 , 66 }; func1 (arr, 3 ); return 0 ; }
  2. Fine the time complexity of the func function in the program from program2.c as follows: void func (int n) { int sum = 0 ; int product = 1 ; for (int i = 0 ; i < n; i++) { for (int j = 0 ; j < n; j++) { printf ("%d , %d\n", i, j); } } }

return 1 ;

  1. What is the time complexity of the following snippet of code?

int isPrime (int n){

for (int i = 2 ; i * i < 10000 ; i++) {

if (n % i == 0 )

return 0 ;

return 1 ;

isPrime();