0% found this document useful (0 votes)
11 views4 pages

Assignments

The document discusses several data structures and algorithms topics: 1. Creating an abstract data type for complex numbers. 2. Functions to find the smallest odd number and remove all odd numbers from a linked list. 3. Sorting algorithms by Big O notation. 4. Writing pseudocode and analyzing complexity to calculate 2^n. 5. Proposing a hash function and drawing hash tables using different collision handling methods.

Uploaded by

ca.petropavlosk
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views4 pages

Assignments

The document discusses several data structures and algorithms topics: 1. Creating an abstract data type for complex numbers. 2. Functions to find the smallest odd number and remove all odd numbers from a linked list. 3. Sorting algorithms by Big O notation. 4. Writing pseudocode and analyzing complexity to calculate 2^n. 5. Proposing a hash function and drawing hash tables using different collision handling methods.

Uploaded by

ca.petropavlosk
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Mini review 1

1. Create an abstract of Complex number data type.


2. Given a singly linked list Head containing n integer numbers, write two
functions to do the following tasks:
● Find the smallest odd number of Head

● Remove all odd numbers of Head

3. Sort the following functions in the increasing order of Big O notations:


4nlogn + 2n 210 2logn
3n+100logn 4n 2n
2 3
n + 10n n nlogn

210
3n+100logn
4n
2logn
nlogn
4nlogn+2n
n2+10n
2n
n3
4. Given an integer number n, your task is to write two different algorithms in
pseudo-codes to calculate 2n, and evaluate the complexity of the algorithms.
5. #include<bits/stdc++.h>
6. using namespace std;
7.
8. int power_of_two(int n) {
9. return 1 << n;
10. }
11.
12. int main() {
13. int n = 5;
14. cout << "2^n = " << power_of_two(n) <<
endl;
15. return 0;
16. }
17.

#include<bits/stdc++.h>
using namespace std;
int power_of_two(int n) {
int result = 1;
for (int i = 0; i < n; i++) {
result *= 2;
}
return result;
}

int main() {
int n = 5;
cout << "2^n = " << power_of_two(n) << endl;
return 0;
}

18. Calculate the complexity of the following functions:


Function sum:
sum = 0;
for ( i = 0; i < n; i + +)
for ( j = i + 1; j < = n; j + +)
for ( k = 1; k < 10; k + +)
sum = sum + i * j * k ;

O(n^2)

Function Matrix:
for (i = 0 ; i < n ; i++)
for (j = 0 ; j < n ; j++)
if (i == j)
A[i][j] = 1;
else
A[i][j] = 0;
O(n^2)

19. Given a list of students (id, name):


(7,An), (3,Be), (11, Cu), (4, Da) , (8, Gi), (16, En), (21, Ba), (5, Go)
Your task is to propose a hash function, and draw the hash table with the
proposed hash function using both collision handling methods

20. Do following tasks with the heap tree:


● Construct a max heap tree including: 2, 19, 38, 29, 66, 64, 72, 3, 16, 89,
15, 37, 20, 28, 73, 5.
● Insert the following numbers into the above max heap tree: 5, 13, 9, 7, 24,
4, 6

21. Do the following tasks with binary search tree:


● Create a binary search tree from following numbers: 14, 15, 35, 62, 29, 42,
40, 80, 59, 23, 46, 57, 3, 19
● Draw BSTs after deleting keys 12, 42 and 13 from the above tree.

22. write TreeSearch(k, T) function to check if k is in the binary tree search T.

23. Find the order of nodes in preorder, postorder, and inorder traversals

39

70 83

53 61 72 16

24 48
cd
a b

You might also like