KLE Tech | Computer Science | Solved Model Question Papers

School of Computer Science and Engineering

MODEL QUESTION PAPER With Solutions

Course: Problem Solving With DataStructures
Course Code: 18ECSP102 

Semester: II
Date of Exam: Duration: 75 mins

 

1a) Explain File operations: fopen, fclose , fscanf, fprintf

Sol] Please refer – File Handling in C programming | Operations in Files


1b) What is static memory allocation and dynamic memory allocation?

Difference between malloc and calloc functions

Malloc()Calloc()
1.ptr = (cast_type *) malloc(byte_size);

 

ptr = (cast_type *) calloc (n, size);
2.Malloc() function will create a single block of memory of size specified by the user.Calloc() function can assign multiple blocks of memory for a variable.
3.Malloc function contains garbage value.The memory block allocated by a calloc function is always initialized to zero.
4Number of argument is 1.Number of arguments are 2.
5Malloc is faster than calloc.Calloc is slower than malloc.
6It is not secure as compare to calloc.It is secure to use compared to malloc.
7Time efficiency is higher than calloc().Time efficiency is lower than malloc().
8Malloc() function returns only starting address and does not make it zero.Before allocating the address, Calloc() function returns the starting address and make it zero.
9It does not perform initialization of memory.It performs memory initialization.

 

Difference between Static and dynamic memory allocation

StaticDynamic
1.In the static memory allocation, variables get allocated permanently, till the program executes or function call finishes.In the Dynamic memory allocation, variables get allocated only if your program unit gets active.
2.Static Memory Allocation is done before program execution.Dynamic Memory Allocation is done during program execution.
3.It uses stack for managing the static allocation of memoryIt uses heap for managing the dynamic allocation of memory
4It is less efficientIt is more efficient
5In Static Memory Allocation, there is no memory re-usabilityIn Dynamic Memory Allocation, there is memory re-usability and memory can be freed when not required
6In this memory allocation scheme, execution is faster than dynamic memory allocation.In this memory allocation scheme, execution is slower than static memory allocation.
5Example: This static memory allocation is generally used for array.Example: This dynamic memory allocation is generally used for linked list.

 


1c) Blockchain is the new technology in computer science, where it is used to store the
‘n’ transaction details of users. Shivam is very much interested in implementing
blockchain kind of technology using C programming. Transaction details contain:
Transaction_ID, sender name, receiver name, amount, time. Please help Shivam to
implement the above problem and perform the below operations.

i) Display the transaction details of the particular Transaction_ID.
ii) Display the transaction details of the particular user

Soln] Please Refer – C Programming Data Structure | Block-chain compare, search, string


2a)  Create a structure for storing movie information with a minimum of 6 fields and
show the memory allocation.

struct movie
{
char name[30];
char director[30];
int budget;
int release_date;
float box_office_collection;
char hero_name[30];
}m;
2022 06 10 16 09 08 Presentation1.pptx PowerPoint Product Activation Failed

2b) Vishal owns a cyber café, where he has ‘N’ number of computers stored in a file.
Since Vishal is lazy to write the details of ‘N’ computers on paper, he stores the
details of computers in a file. Please help Vishal to store the details of the computers
and perform the below operations.
Display the details of all computers.

Refer – C Programming File Handling | Storing Data into the File overwrite


2c) KLETU started admission for 2022 under the graduate program. The candidates
are selected based on the rank obtained in CET. During the second round of
counseling few candidates withdraw and new candidates get added based on their
rank. Display the final list of candidates that took admitted to KLETU.

ReferAll operations on Student linked lists (Insert, delete, display) (Multiple data)

Add this chunk of code to it:

node delete_pos(node head,int pos)
{
node cur,prev;
int count;
if(head==NULL)
{
printf("List is empty\n");
return NULL;
}
if(pos==1)
{
cur=head;
head=head->next;
printf("Deleted data:%d\n",cur->data);
free(cur);
return head;
}
prev=NULL;cur=head;
count=1;
while(cur!=NULL&&count!=pos)
{
prev=cur;
cur=cur->next;
count++;
}
if(cur==NULL)
{
printf("Invalid position specified\n");
}
prev->next=cur->next;
printf("Deleted:%d\n",cur->data);
free(cur);
return head;
}

3a) Write a modular C program to compare the contents of two files.

Refer – File Handling | Comparing two files in *files


3b) A list of persons information is stored in a list in random order according to their
age. The police men came and reversed the positions of all people from start till the
last person. Ajay is a kid standing there and wants to know what will be the new
list persons.

// Iterative C program to reverse a linked list
#include <stdio.h>
#include <stdlib.h>

/* Link list node */
struct Node {
int data;
struct Node* next;
};

/* Function to reverse the linked list */
static void reverse(struct Node** head_ref)
{
struct Node* prev = NULL;
struct Node* current = *head_ref;
struct Node* next = NULL;
while (current != NULL) {
// Store next
next = current->next;

// Reverse current node's pointer
current->next = prev;

// Move pointers one position ahead.
prev = current;
current = next;
}
*head_ref = prev;
}

/* Function to push a node */
void push(struct Node** head_ref, int new_data)
{
struct Node* new_node
= (struct Node*)malloc(sizeof(struct Node));
new_node->data = new_data;
new_node->next = (*head_ref);
(*head_ref) = new_node;
}

/* Function to print linked list */
void printList(struct Node* head)
{
struct Node* temp = head;
while (temp != NULL) {
printf("%d ", temp->data);
temp = temp->next;
}
}

/* Driver code*/
int main()
{
/* Start with the empty list */
struct Node* head = NULL;

push(&head, 20);
push(&head, 4);
push(&head, 15);
push(&head, 85);

printf("Given linked list\n");
printList(head);
reverse(&head);
printf("\nReversed Linked list \n");
printList(head);
getchar();
}

© Credits

Tejas N (1)
'H' div
Department of Computer Science

Anurag S (1)
'O' div
Department of Electrical & Electronics

Basavaraj Kalburgi (1)
'O' div
Department of Computer Science

Anushika Kotari(2)
'H' div
Department of Computer Science

 


(  ) — Number of Contributions!

Refer : C Programming HackerRank all solutions for Loops | Arrays | strings

Please find some more codes of Loops, Condition Statements, 1D Arrays, 2D Arrays, Strings, Pointers, Data Structures, Files, Linked lists, MISC, Solved model question papers & Hacker Rank all solutions on the below page:

Top 100+ C Programming codes – KLE Technological University







Leave a Comment

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

Welcome to FactsPrime

Sorry, We have detected that you have activated Ad-Blocker. Please Consider supporting us by disabling your Ad Blocker, It helps us in maintaining this website. To View the content, Please disable adblocker and refresh the page.

Thank You !!!