Data Structures and Algorithms - Competitive Practice Sheet (Code with Harry) PDF
Document Details
Uploaded by Deleted User
Tags
Summary
This document contains practice questions and problems related to data structures and algorithms, focusing on calculating time complexity. It includes code examples in C and tasks involving recursive algorithms, balanced binary search trees and finding prime numbers.
Full Transcript
F 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 v...
F 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 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); } } } 3. Consider the recursive algorithm above, where the random(int n) spends one unit of time to return a random integer which is evenly distributed within the range [0,n][0,n]. If the average processing time is T(n), what is the value of T(6)? int function(int n) { int i; if (n