Docsity

Advanced Programming Final Exam, Exams of Programming Languages

Toggle sidebar
bg1
Applied Programming
Final, Fall 2014
Date: Jan 13, 2015 Marks: 100 Time: 3 hours
Roll Number: _______________ Section: ____________
Department of Computer Science
National University of Computer & Emerging Sciences, Lahore Page 1 of 15
Q1 [10] Programming Basics
What is the value of variables x, y Just before the return statement of function main? Also what
will be stored in arr3 before the end of main function?
#include <iostream>
using name space std;
void MysteryFunction(int arr1[],int arr2[],int arr3[],int size);
void ProcessCode(int Code1, int & Code2);
const int SIZE=5;
int main()
{ int x = 1,y=5;
int arr1[SIZE]={1,3,7,9,23}; int arr2[SIZE]={2,8,10,12,24}; int arr3[SIZE*2]={0};
ProcessCode(x,y);
switch(x+y)
{
case 1:
case 2: MysteryFunction(arr1,arr2,arr3,SIZE-1); break;
case 3: MysteryFunction(arr1,arr2,arr3,SIZE); break;
case 4: MysteryFunction(arr1,arr2,arr3,SIZE-2); break;
}
//what is the final value of the variables?
return 0;
}
void MysteryFunction(int arr1[],int arr2[], int arr3[],int size)
{
int i=0,k=0,j=0;
while (i<size || j< size)
{
if ((i < size) && (arr1[i] < arr2[j]))
{ arr3[k] = arr1[i];
i++;
}
else
{
arr3[k] = arr2[j];
j++;
}
k++;
}
}
void ProcessCode(int Code1,int
&Code2)
{
Code1 = Code1+1;
Code2 = Code2-4;
}
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Advanced Programming Final Exam and more Exams Programming Languages in PDF only on Docsity!

Applied Programming

Final, Fall 2014

Date: Jan 13, 2015 Marks: 100 Time: 3 hours

Roll Number: _______________ Section: ____________

Department of Computer Science

Q1 [10] Programming Basics

What is the value of variables x , y Just before the return statement of function main? Also what will be stored in arr3 before the end of main function?

#include using name space std; void MysteryFunction(int arr1[],int arr2[],int arr3[],int size); void ProcessCode(int Code1, int & Code2); const int SIZE=5;

int main() { int x = 1,y=5; int arr1[SIZE]={1,3,7,9,23}; int arr2[SIZE]={2,8,10,12,24}; int arr3[SIZE*2]={0}; ProcessCode(x,y); switch(x+y) { case 1: case 2: MysteryFunction(arr1,arr2,arr3,SIZE-1); break; case 3: MysteryFunction(arr1,arr2,arr3,SIZE); break; case 4: MysteryFunction(arr1,arr2,arr3,SIZE-2); break; } //what is the final value of the variables? return 0; }

void MysteryFunction(int arr1[],int arr2[], int arr3[],int size) { int i=0,k=0,j=0; while (i<size || j< size) { if ((i < size) && (arr1[i] < arr2[j])) { arr3[k] = arr1[i]; i++; } else { arr3[k] = arr2[j]; j++; } k++; } }

void ProcessCode(int Code1,int &Code2) { Code1 = Code1+1; Code2 = Code2-4; }

Department of Computer Science

x = _____________ y = _____________ arr3[] = ___________________________________________________________________________

Q2 [25] LinkedList

(a) Swap two adjacent pair elements by adjusting data along whole linked list Singly linked list. Write a recursive function for it.

Original List

Resultant List

Department of Computer Science

Department of Computer Science

Q3 [15] Priority Queue

A priority queue can be expressed in the form of heap tree. Priority will be used as heap criteria. Assuming priority queue is built to handle processes in operating system and a list of processes is maintained in a priority queue. Processes are attached with attributes priority and arrival time. Write a procedure HEAP_PRIORITY_QUEUE to service the processes as FIFO order only.

Department of Computer Science

Q4 [30] Tree Representations and Algorithms

(a) Define a template based Node of B Tree.

(b) Perform the following operations on the 4-way B-Tree (2-3-4 tree) given below.

Starting from the initial tree, insert: 66, 54, 88, and 39 Starting from the initial tree, delete: 16, 25, 53 and 27

Department of Computer Science

Department of Computer Science

Department of Computer Science

Q5 [20] Graph Representations and Algorithms

(a) Given an undirected weighted graph G = (V, E), design an algorithm to find a minimum weight cycle in G. Note that the weight of cycle is simply the sum of the weights of all its edges. There could be more than one minimum weight cycles in G, and you might report any one of them, along with the weight itself. You must:

 Describe your algorithm in English.  Give a clean and precise pseudo code.  Analyze your algorithm and state its running time as a function of |V| and |E|.

Note: You should not re-write any algorithm covered in class, but can use it as a function call.

Department of Computer Science

Department of Computer Science