0% found this document useful (0 votes)
37 views10 pages

DS

Math discret

Uploaded by

alainfabo21
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
37 views10 pages

DS

Math discret

Uploaded by

alainfabo21
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 10
Roll No. Pandit Deendayal Energy University Mid Semester Examination: September 2023 B. Tech. (Computer Science and Engineering) ‘Semester - Date: 12/09/2023 Course Name: Data Structures Time: 2 hours Course Code: 20CP201T. Max. Marks: 50 Instructions: 1. Do not write anything other than your roll number on question paper. 2. Read question paper properly and assume suitable data wherever essential by mentioning it clearly. 3. Write appropriate units, nomenclature, and draw neat diagrams wherever required. Que. Description co No. Marks | Mapping (Ql | Select the correct option (I Marks) and give proper justification (2 Marks) for each of the following Multiple-Choice Questions. QUAY | Analgorithm A reads 500 integers. These integers ae values in the range [0, 100] that represent the scores of 500 students. It then prints the frequency of each score above 50, What would be the best way for A to store the frequencies? i. Amay of 50 numbers ii, Array of 100 numbers iii, Array of 500 numbers iv. Dynamically allocated array of 550 numbers DUG [A queue is implemented wsing a cireular Tinka list, that i, the Tok part of rear node contains the address of front node of the lst. There is a restretion that we can only use one pointer to access the elements ofthe queve. Let this pointer be ‘per’ To which node “ptr” shold point such that both enQueneQ) and deQueuie() are performed in constant time? i. Front Node ji, Rear Node Node next to Front iv.__Not Possible with single pointer GH] [A aueue is implemented using a non-ciroular singly linked list I has a head pointer pointing tothe first node ofthe list and a tail pointer pointing tothe last node of thelist. Let 'n’ denotes the number of nodes in the queue. Let enquewe() be implemented by inserting a new node at the head, and dequeweQ be implemented by deletion of a node from the tail. Which one of the following is} 3 | CO-3 the time compiexties of the time-efficient implementation of enquewe() and | dequewe() respectively, for this data structure? 0,001) i, 00,0) O(n), 001) iv. __0(m),0(n) Qi (D) | Assume that the § elements (1,2,4,5,9) are pushed and popped using some possible combinations of 5 rusi() and 5 popO operations. The elements should be compulsorily pushed inthe sequence 2, 5, 1,9, 4. However, they ean be popped con 3 co2 any time in between, Which of the following output permutation can’tbe obtained | 3 cos in the same order as below? i 1,5,9,2,4 i Bee 51 94 ii, __2,9,1,4,5 iv. 5.1,4,2,9 Page 1 of 2 @ Fill in the blanks with correct answers (I Marks) and give proper reason to your answer (2 Marks) for each of the following. QA) ‘One aspect of linear data structures that makes it different from the non Tinear data structures is cO-1 ee ‘Consider the two stacks 5; and 5;, Various operations are performed on these stacks in the following given order: push(S,.54), push(S,,52), push(S;.22), Push(Se,55), push(S;,52), q = pop(S,). push(S,,35), p= pop(S,), Push(Sy,10), push(Sa,15), pusk(Sy.20), q = poplSi) p= portSi). push(Sy,20). q = pop(Sa). Here, push(S, a) insert the element a into stack S ‘whereas pop(S) returns the deleted clement from stack S. After all these operations, the value of p + g is —--- co2 QO Postfix equivalent of the infix expression 3 = log(x + 1) — log (@/2) is ——- Cd eo The following postfix expression with single digit operands is evaluated using stack: 823/23 « +51 + —. After the first « (multiplication) is evaluated, the top two elements of the stack are ~~-e-(top) and w-----~---(next 10 top). co-4 QA) Write any 5 differences between linear and non-linear data structures, COT Q3(B) What is the output of the following function, where “start” points to the first node of the linked ist 1+ 2 3+ 4+ 5+ 6? void fun(struct node » start) if(start return; printf((%d", start — data); NULL) if(start + next # NULL) fun(start + next > next); printf((%d", start + data); 3 ‘Also, explain in detail how your output is obtained, coz @ Write algorithms to implement following operations of the circular queue using an array: 1. enQueue(): to insert an element in the circular queue. 2._deQueue(); to delete an element from the circular queue, ‘OR ‘Write algorithms to implement following operations of the stack using an array: 1. push():10 insert an element in the stack. 2._pop():to delete an element from the stack. cos A) ‘Apply infix to postiix algorithm that uses stack to convert the following infix expression into its corresponding postfix notation. A+ (B+C=D'G)—H) co-4 eB) ‘Write pseudocode to evaluate the postfix expression using suitable data structures. co-4 ———— == End of the Question Paper Page 2 of 2 Powered by AI Copilot Sure, here are the solutions to the questions in your mid-semester exam paper: Qu. (A) Best way to store frequenci + ii, Array of 100 numbers + Justification: Since the scores range from 0 to 100, an array of 100 elements is su frequency of each score. QI. (B) Pointer for constant time enQueue() and deQueue(): + ii, Rear Node + Justification: Pointing to the rear node allows both enQueue() and deQueue() operations to be performed in constant time. Qo Time complexities of enqueue() and dequeue(): * if. (OC), (OM) «Justification: Inserting at the head is (O(1)), but deleting from the tail requires traversing the list, making it (O(n)), Ql. (D) Output permutation that can’t be obtained: * iv.5,1,4,2,9 tification: This sequence violates th Q2. (A) Value of p+ q: tack’s LIFO (Last In, Fi + Answer: 67 + Justification: After performing the given operations, p = 55 and q = 12, so p+ q= 67. Q2. (B) Aspect of linear data structures: + Answer: Elements are arranged sequentially. + Justification: Linear data structures have elements in a sequence, unlike non-linear s ructures. Q2.0 Postfix equivalent of the infix expression: + Answer: (3 \log(x + 1) - og(a/2)) + Justification: Convert the infix expression to postfix notation. Q2. (D) Top two elements of the stack after first multiplication: + Answer: 8 and 2 + Justification: Evaluate the postfix expression step by step. Q3. (A) Differences between linear and non- jinear data structures: 1, Arrangement: Linear structures are sequential; non-linear are hierarchical. 2. Traversal: Linear structures are traversed linearly; non-linear require specific traversal methods. 3, Examples: Arrays and linked lists are linear; trees and graphs are non-linear. 4. Memory Utilization: Linear structures use contiguous memory; non-linear may use non-contiguous memory. 5. Complexity: Operations in linear structures are generally simpler than in non-linear structures. Q3.(B) Output of the function: + Answer: 135531 + Justification: The function prints nodes in a specific order based on the given conditions. Q4 Algorithms for circular queue operations: 1, enQueueQ): void enQueue(int value) { if ((rear + 1) % SIZE == front) { 7/ Queue is full y else { rear = (rear + 1) % SIZE; queue[rear] = value; } 2. deQueue(): int dequeue() { if (Front == rear) { 17 Queue is enpty return 13 } else { front = (front + 1) % SIZE; return queue[front]5 } Q5. (A) Pseudocode to evaluate postfix expression: 1. Initialize an empty stack. 2. For each token in the postfix expression: © If the token is an operand, push it onto the stack. © Ifthe token is an operator, pop the required number of operands from the stack, perform the ‘operation, and push the result back onto the stack. 3. The result will be the only element left in the stack. Q5. (B) Infix to postfix conver: * Given infix expression: (A + (B * C - D“G)- H) + Postfix expression: (ABC*DG”-H-) Feel free to ask if you need further clarification on any of these solutions! Roll No. Deendayal Energy University Mid Semester Examination - September 2022 B.Tech. (Computer Science and Engineering) Date: 23/09/2022 Course Name: Data Structure ime: 2 hours Course Code: 20CP201T Instructions: 1. Do not write anything o :0u roll number on question paper 2. Assume suitable data whe: and mention it clearly, 3._ Write appropriate units, 1: , and draw neat diagrams wherever require. uestion | Description ; 5 le No. : Marks, Q1-(A)_ Which one ofthe following isthe dlsadvantage oF arays? —— {- Data structure like queue or stack eannot be implemented {i There are chances of wastage of memory space if elements inserted in an array are lesser than the allocated size, | ii, Easier to store elements of same datatype. | iv. _Elements are sequentially accessed. QI-(B) | What does “stack underflow” refers to? i, Accessing item from an undefined stack, Adding items to a stack that is already full, ii. Removing items from an empty stack. iv.__Index out of bounds exception. ‘What the time complexity of pop) operation when the stack is implemented using an array? & 0a) i. om O(ogn) iv. O(log) ‘What is the need for a circular queue? cffective usage of memory ji, easier computations to delete elements based on priority iv. _ implement FIFO principle in queues jh. circular queue; how do you inerement the rear end of the queue? Here, REAR points to the last element of circular queue and CAPACITY is the size of the queue, i, REAR=REAR +1 REAR = (REAR + 1) % CAPACITY REAR (REAR % CAPACITY) + | REAR= REAR - 1 Q2.(A) ferentiate between the linear and non-linear data structures, Q2.(B) | Write an algorithm or pseudocode to evaluate the postfix expression using *_| suitable data structure, ENS} how Priority Queue can be applied, with an appropriate example. fix to postfix algorithm that uses stack to convert the following infix expression into its corresponding postfix notation. A+B+(C~D)/E+F~G, Q3.(B) Powered by AT Copilot Sure, I can help with that! Here are the solutions to the questions in your mid-semester exam paper: Qu.(A) Disadvantage of array: ‘+ iii, There are chances of wastage of memory space if elements inserted in an array are lesser than the allocated size. Qi. B) Stack underflow refers te + iii, Removing items from an empty stack, Qo Time complexity of pop() operation in an array-implemented stack: * i.(O(1)) Ql.) Need for a circular queue: + i, Effective usage of memory QI. (E) Incrementing the rear end of a circular queue: * ii, (Wext{REAR} = (\text{REAR} + 1) % \text{CAPACITY} ) Q2. (A) Difference between linear and non-linear data structures: + Linear Data Struetures: Elements are arranged sequentially (e.g., arrays, linked lists). + Non-linear Data Structures: Elements are arranged hierarchically (c.g., trees, graphs). Q2. (B) Algorithm to evaluate postfix expression: I. Initialize an empty stack. 2. For each token in the postfix expression: © If the token is an operand, push it onto the stack: © Ifthe token is an operator, pop the required number of operands from the stack, perform the operation, and push the result back onto the stack. 3. The result will be the only element left in the stack. Q3.(A) Priority Queue Application Example: + Example: Task scheduling in operating systems where tasks with higher priority are processed first. Q3. (B) Infix to postfix conversion: + Given infix expression: (A+B +(C -D)/E+F-G) + Postfix expression: ( AB+CD-E/+F+G- ) Q4 Operations on stack ‘S’ and queue ‘Q push(A) -> S: [A], Q:[] push(B) > S:[A, B], Q: [] pop() > S: [A], Q: [C}, Output: B enqueue(D) > 8: [A], Q: [C, D] is : dequeue() > S: (A, EJ. Q: [D], Output: C push(F) > S: (A, B, F],Q: [D] enqueue(G) -> 10, dequeued) . F], Q: [G], Output: D 11, push(H) -> S: [A, E, FH], Q: [G] 12, dequeue() > S: [A, E, F, H}, Q: [], Output: G 13. push(I) -> S: [ 14, dequeue() > S: 15, dequeue() > S: 16, push(J) > S: 17. pop() > S: [A, 18, enqueue(K) > S: 19, push(L) -> S: [A. 20. pop() > 8: [A, 21. dequeue() > S. 22, enqueue(M) 23. enqueue(N) -> 24, enqueue(O) 25. pop() > S: [A, 26, dequeue) > S Q5. (A) Operation performed by function(Q): SRA aVaYNe 1.0 f : [K], Output: L Qf], Output: K ', H, 1], Q: [M] Ere + The function reverses the elements of the queue. Q5. (B) Time complexity of the given program: + The time complexity is (O(n2)). Q5.0 Time complexity of the given program: ‘+ The time complexity is (O(log \log n)). Feel free to ask if you need further clarification on any of these solutions!

You might also like