Professional Documents
Culture Documents
SPRING 2020
(1 Hour)
Name
ID
INSTRUCTIONS TO STUDENT
1. This Question paper consists of 5 pages including cover page with 2 Questions only.
2. Answer ALL questions. The distribution of the marks for each question is given.
3. Please write all your answers in the answer sheet provided.
ETE308 – Higher Data Structure and Algorithms
{
if(num%2==0)
---------(6)-------------//Increment count by 1
}
return 0;
}
[6 Marks]
(c) Consider the following incomplete C program consisting with arrays and nested loops.
Based on the comments provided, write the correct alternative to replace the blank line
and provide the expected output of the program
#include <stdio.h>
#include <stdlib.h>
__________(1)___________________ //Add the constant macro to define array bound of N
__________(2)_________________ //Add the constant macro to define array bound of M
int main(void) {
int i, j;
int c[N][M] = {
{1, 2},
{3, 4},
{5, 6}
};
2
ETE308 – Higher Data Structure and Algorithms
Figure 2(a)
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct node{
char name[20];
int age;
struct node *next;
};
int main(){
struct node *head;
struct node *temp;
3
ETE308 – Higher Data Structure and Algorithms
_________(1)________________________
//Create a head node and assign the allocated memory to head
strcpy(head->name, "ang");
________(2)_______________ //Place 20 into the age member of the head node
_________(3)______________________
//Create a new node and assign the allocated memory to head->nx
temp = head->next;
strcpy(temp->name, "khairul");
__________(5)__________________________
//Create a new node and assign the allocated memory to temp->next
temp = temp->next;
strcpy(temp->name, "lui");
______(6)__________ //Place 19 into the age member of the new node
_______(7)______________________________
//Create a new node and assign the allocated memory to temp->next
temp = temp->next;
strcpy(temp->name, "wafa");
_______(8)________________ //Place 20 into the age member of the new node
while(temp){
printf("%s\t%d\n", temp->name, temp->age);
temp = temp->next;
}
return 0;
}
[10 marks]
4
ETE308 – Higher Data Structure and Algorithms
(c) Consider a binary tree shown in Figure Q2(c), give the sequence of the visited nodes in
preorder, postorder and inorder traversals.
Figure Q2(c)
[6 Marks]
End of Paper