Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

ID: 211-15-3986

Daffodil International University Teacher’s Initial

Fall 2021 MRH


Department of Computer Science and Engineering
Midterm Open Book Examination Answer Script
Full Marks: 25 Allowed Time: 4hrs (from: 9:00am to: 11:30am)
Date: Sunday, 13 November, 2021

Submission Date: Sunday, 13 November, 2021

General Information (must be filled by the student)


COURSE CODE: CSE134 SECTION: PC - A PROGRAM: DAY / EVEN

STUDENT ID: 211-15-3986 TIME STARTED: 09:00am TIME ENDED: 11:30am

[Student must either TYPE or HAND WRITE the answers in this template; In case needed just
write your detail on the paper using hand]

** Plagiarism will be checked while you submit your response. You are advised to be honest during
the open book exam.
ID: 211-15-3986

Part-A

a)

knees

head

e m t n e m t n

22 41.0 ‘K’ toes 41 7.5 ‘T’ NULL

Knees Toes

b)
STACK: (empty)

Queue: (empty)

Push (5) STACK : 5

Push (6) STACK : 5,6

Push (7) STACK : 5,6,7

Push (18) STACK : 5,6,7,18

Pop (18) STACK : 5,6,7

Enqueue (18) Queue : 18

Push (55) STACK : 5,6,7,55

Push (45) STACK : 5,6,7,55,45

Pop (45) STACK : 5,6,7,55

Enqueue (45) Queue : 18,45

Pop (55) STACK : 5,6,7


** Plagiarism will be checked while you submit your response. You are advised to be honest during
the open book exam.
ID: 211-15-3986

Enqueue (55) Queue : 18,45,55

Pop (7) STACK : 5,6

Enqueue (7) Queue : 18,45,55,7

Pop (6) STACK : 5

Enqueue (6) Queue : 18,45,55,7,6

Pop (5) STACK : (empty)

Enqueue (5) Queue : 18,45,55,7,6,5

Push (2) STACK : 2

Dequeue (8) Queue : dequeue (8) not possible because Queue 8 not present

Part-B
a)
#include<stdio.h>
#include<stdlib.h>

struct node{
int al;
** Plagiarism will be checked while you submit your response. You are advised to be honest during
the open book exam.
ID: 211-15-3986

struct node *imran;


};

void linkListSearch(struct node *p){


int n, found=0;

struct node *q = p->imran;

printf("Enter search value: ");


scanf("%d", &n);

while (p!=NULL)
{
if (p->al==n)
{
found=1;
break;
}
p = p->imran;

if (found==1)
{
p->imran = q->imran;
free(q);
printf("Next item delete sucess\n");
}else
{
printf("Value Not Founded");
}

int main(){

struct node *head;

struct node *a = NULL;


struct node *b = NULL;
struct node *c = NULL;
struct node *d = NULL;

a = malloc(sizeof(struct node));
b = malloc(sizeof(struct node));
c = malloc(sizeof(struct node));
d = malloc(sizeof(struct node));

** Plagiarism will be checked while you submit your response. You are advised to be honest during
the open book exam.
ID: 211-15-3986

a->al = 8;
b->al = 3;
c->al = 6;
d->al = 9;

a->imran = b;
b->imran = c;
c->imran = d;
d->imran = NULL;

head = a;

linkListSearch(head);

return 0;
}

b)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct node {
char d;
char e;
struct node *f;
}*head;

void createList(char d,char e);


void lastInsert(char d,char e);
void displayList();
int countNodes();

int main()
{

int n, data, position;

createList('D','k');
createList('J','K');
//NODE NODE IN qUESTION 2B
printf("\nData in the list \n");
displayList();
//insert last
** Plagiarism will be checked while you submit your response. You are advised to be honest during
the open book exam.
ID: 211-15-3986

lastInsert('M','S');
printf("\nData in the list \n");
displayList();

printf("Total Nodes : %d",countNodes());

return 0;
}

void createList(char d,char e)


{
struct node *temp;
temp = (struct node *)malloc(sizeof(struct node));
temp->d = d;
temp->e = e;
temp->f = NULL;

if(head == NULL)
{
head = temp;
}
else
{
temp->f = head;
head = temp;
}
}

//create a function for last insert


void lastInsert(char d,char e)
{
struct node *temp;
temp = (struct node *)malloc(sizeof(struct node));
temp->d = d;
temp->e = e;
temp->f = NULL;

if(head == NULL)
{
head = temp;
}
else
{
struct node *p;
p = head;
while(p->f != NULL)
{
** Plagiarism will be checked while you submit your response. You are advised to be honest during
the open book exam.
ID: 211-15-3986

p = p->f;
}
p->f = temp;
}
}

//display the list


void displayList()
{
struct node *p;
p = head;
while(p != NULL)
{
printf("\n%c %c\n",p->d,p->e);
p = p->f;
}
}

//count the number of nodes in the list


int countNodes()
{
struct node *p;
p = head;
int count = 0;
while(p != NULL)
{
count++;
p = p->f;
}
return count;
}

c)
#include<stdio.h>//id=211-15-3986
int main()
{
int std_id[10]={2,1,1,1,5,3,9,8,6,0};
int i,n;
printf("Search 5 in array.\n");
for(i=0; i<n; i++)
{
if(std_id[i]==5)
{
printf("5 found at position %d\n", i+1);
** Plagiarism will be checked while you submit your response. You are advised to be honest during
the open book exam.
ID: 211-15-3986

return 0;
}
}

printf("element not found.\n");


return 0;
}

i)
the array that I created if I want to search an element from it, I will use the method
liner search. As my array is one-dimensional, the linear search can be easily executed.

Linear search is an algorithm for finding a target value within a list. It sequentially
checks each element of the list for the target value until a match is found or until all
the elements have been searched. This is one of the most basic search algorithms and
is directly, inspired by real-life events.

Algorithm

Steps involved in this algorithm are:

Step 1: Select the first element as the current element. // A[0]

Step 2: Compare the current element with the target element.// A[i]=5

If matches, then go to step 5.

Step 3: If there is a next element, then set current element to next element and go to
Step 2.

Step 4: Target element not found. Go to Step 6. //A[i]!=5

Step 5: Target element found and return location.

Step 6: Exit process.

** Plagiarism will be checked while you submit your response. You are advised to be honest during
the open book exam.
ID: 211-15-3986

Part-C
a) Postfix

Given expression: V/ (N*Z- (Q+R^S)/T)*M+K*P

Using my student ID: 2/(1*1-(1+5^3)/9)*8+6*0 [For last digit using 0 instead of P]

Input Output Stack


2/ (1*1- (1+5^3)/9)*8+6*0 2
2/ (1*1- (1+5^3)/9)*8+6*0 2 /
2/ (1*1- (1+5^3)/9)*8+6*0 2 /
2/ (1*1- (1+5^3)/9)*8+6*0 2 /(
2/ (1*1- (1+5^3)/9)*8+6*0 21 /(
2/ (1*1- (1+5^3)/9)*8+6*0 21 /(*
2/ (1*1- (1+5^3)/9)*8+6*0 2 11 /(*
2/ (1*1- (1+5^3)/9)*8+6*0 2 11* /(-
2/ (1*1- (1+5^3)/9)*8+6*0 2 11* /(-
2/ (1*1- (1+5^3)/9)*8+6*0 2 11* /(-(
2/ (1*1- (1+5^3)/9)*8+6*0 2 11* 1 /(-(
2/ (1*1- (1+5^3)/9)*8+6*0 2 11* 1 /(-(+
2/ (1*1- (1+5^3)/9)*8+6*0 2 11* 15 /(-(+
2/ (1*1- (1+5^3)/9)*8+6*0 2 11* 15 /(-(+^
2/ (1*1- (1+5^3)/9)*8+6*0 2 11* 153 /(-(+^
2/ (1*1- (1+5^3)/9)*8+6*0 2 11* 153^+ /(-
2/ (1*1- (1+5^3)/9)*8+6*0 2 11* 153^+ /(-/
2/ (1*1- (1+5^3)/9)*8+6*0 2 11* 153^+9 /(-/
2/ (1*1- (1+5^3)/9)*8+6*0 2 11* 153^+9/- /
2/ (1*1- (1+5^3)/9)*8+6*0 2 11* 153^+9/-/ *
2/ (1*1- (1+5^3)/9)*8+6*0 2 11* 153^+9/-/8 *
2/ (1*1- (1+5^3)/9)*8+6*0 2 11* 153^+9/-/8* +
2/ (1*1- (1+5^3)/9)*8+6*0 2 11* 153^+9/-/8*6 +
2/ (1*1- (1+5^3)/9)*8+6*0 2 11* 153^+9/-/8*6 +*
2/ (1*1- (1+5^3)/9)*8+6*0 2 11* 153^+9/-/8*60 +*
2/ (1*1- (1+5^3)/9)*8+6*0 2 11* 153^+9/-/8*60*+
** Plagiarism will be checked while you submit your response. You are advised to be honest during
the open book exam.
ID: 211-15-3986

Output of Postfix: 2 11* 153^+9/-/8*60*+

Prefix

1. Reverse the expression 2/(1*1-(1+5^3)/9)*8+6*0 to 0*6+8*(9/(3^5+1)-1*1)/2

2. Postfix of 0*6+8*(9/(3^5+1)-1*1)/2

Input Output Stack


0*6+8*(9/(3^5+1)-1*1)/2
0*6+8*(9/(3^5+1)-1*1)/2
0*6+8*(9/(3^5+1)-1*1)/2 0
0*6+8*(9/(3^5+1)-1*1)/2 0 *
0*6+8*(9/(3^5+1)-1*1)/2 06 *
0*6+8*(9/(3^5+1)-1*1)/2 06* +
0*6+8*(9/(3^5+1)-1*1)/2 06*8 +
0*6+8*(9/(3^5+1)-1*1)/2 06*8 +*
0*6+8*(9/(3^5+1)-1*1)/2 06*8 +*(
0*6+8*(9/(3^5+1)-1*1)/2 06*89 +*(
0*6+8*(9/(3^5+1)-1*1)/2 06*89 +*(/
0*6+8*(9/(3^5+1)-1*1)/2 06*89 +*(/(
0*6+8*(9/(3^5+1)-1*1)/2 06*893 +*(/(
0*6+8*(9/(3^5+1)-1*1)/2 06*893 +*(/(^
0*6+8*(9/(3^5+1)-1*1)/2 06*8935 +*(/(^
0*6+8*(9/(3^5+1)-1*1)/2 06*8935^ +*(/(+
0*6+8*(9/(3^5+1)-1*1)/2 06*8935^1 +*(/(+
0*6+8*(9/(3^5+1)-1*1)/2 06*8935^1+ +*(/
0*6+8*(9/(3^5+1)-1*1)/2 06*8935^1+/ +*(-
0*6+8*(9/(3^5+1)-1*1)/2 06*8935^1+/1 +*(-
0*6+8*(9/(3^5+1)-1*1)/2 06*8935^1+/1 +*(-*
0*6+8*(9/(3^5+1)-1*1)/2 06*8935^1+/11 +*(-*
0*6+8*(9/(3^5+1)-1*1)/2 06*8935^1+/11*- +*
0*6+8*(9/(3^5+1)-1*1)/2 06*8935^1+/11*-* +/
0*6+8*(9/(3^5+1)-1*1)/2 06*8935^1+/11*-*2 +/
0*6+8*(9/(3^5+1)-1*1)/2 06*8935^1+/11*-*2/+

3. Reversed string of 06*8935^1+/11*-*2/+: +/2*-*11/+1^5398*60

Answer is +/2*-*11/+1^5398*60

** Plagiarism will be checked while you submit your response. You are advised to be honest during
the open book exam.
ID: 211-15-3986

b)
The evaluation value of avobe postfix is 211*153^+9/-/8*60*+ = 16

** Plagiarism will be checked while you submit your response. You are advised to be honest during
the open book exam.

You might also like