Professional Documents
Culture Documents
FINAL EXAMINATION
(Answer Sheet)
Name Ahmed Samyan Nayyef
ID No. A11900712
Write your full name and student ID No.
Candidate must answer ALL questions
Answer:
Q1/A-
1- False. An array can only store a grouping of data of the same type such as fixed-point variables,
floating-point variables and pointers etc.
2- False. The remaining elements will NOT be initialized to the last value in the initializer list, they
will be initialized with O’s.
B-
Output is:
1
4
9
16
25
Total is 55.
C-(i)
int main()
{
int r[10]={};
for (int index = 0; index< 6; index++)
printf("%d\n",r[index]);
return 0;
}
(ii)-
1
ETE308 Higher Data Structure & Algorithms Spring 2020
int main()
{
D-
1- #define N 3
2- char product[20];
3- for(k=0;k<N;k++)
4- sum +=cost[k];
5- average= sum/N;
printf("Average: %5.1f\n",average);
Q2/A-
1- head=(struct node *)malloc(sizeof(struct node));
2- head->value=1;
3- temp=(struct node *)malloc(sizeof(struct node));
4- head->next->value=10;
5- struct node *newnod;
newnod=(struct node *)malloc(sizeof(struct node));
temp = &newnod;
6- head->next->next->value=100;
7- head->next->next->next=NULL;
8- temp=&head;
B-
(i)-
2
ETE308 Higher Data Structure & Algorithms Spring 2020
(ii)-
C-
(i)-
3
ETE308 Higher Data Structure & Algorithms Spring 2020
(ii)-
1- struct BinTreeNode {
char data;
struct BinTreeNode *left;
struct BinTreeNode *right;
};
2- setTree();
3- printf("\nInorder traversal: ");
inorder(root);
printf("\nPostorder traversal: ");
postorder(root);
printf("\nPreorder traversal: ");
preorder(root);
4- temp = (struct BinTreeNode *)malloc(sizeof(struct BinTreeNode));
5- temp->data = data;
6- return(temp);
7- root->right->right = initBinTreeNode('e');
root->right->left = initBinTreeNode('c');
8- parent1 = root->right->right;
parent1->right =initBinTreeNode('g');
9- inorder(node->left);
printf("%c",node->data);
inorder(node->right);
4
ETE308 Higher Data Structure & Algorithms Spring 2020
Q3/A-
Recursion Iteration
The statement in a body of a function calls Allows the set of instructions to be
the function itself. repeatedly executed.
It is always applied to functions. It is applied to iteration statements or
“loops”.
Slow in execution Fast in execution
It Reduces the size of the code It makes the code longer
B-
(i)-
F(3)= 5*5^2*5^1 =625
(ii)-
int power(int n)
{
if (n==0)
return 1;
else
return 5 * power(n-1);
}
5
ETE308 Higher Data Structure & Algorithms Spring 2020
(iii)-
#include <stdio.h>
#include <stdlib.h>
(iv)-
int power(int n)
{
int product=1;
for(int i=1;i<=n;i++)
product *=5;
return product;
}
Q4\A-
(i)-
T(n) = W(n) = A(n)
= 1 + 4n^2+ 6n + 2
= 4n^2+ 6n + 3
(ii)-
T(n)=3+T(n-1)
=3+{3+T(n-2)}=3(2)+T(n-2)
=3(2)+{3+T(n-3)}=3(3)+T(n-3)
=…
=3(n)+T(n-n)=3(n)+T(0)
=3n+1
6
ETE308 Higher Data Structure & Algorithms Spring 2020
(iii)-
B-
(i)-
int NumberEven(int a[], int n){ //none
int j, Number=0, n; //1
W(n)=1 + 2n + 2 + 2n + n = 5n + 3
A(n)=1 + 2n/2 + 2 + 2n/2 + n/2 = 2.5n+3
Big-O(f(n)) = n times if n is any positive integer