Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
28 views
36 pages
Akash 3rd Sem Data Structure
Uploaded by
2215148
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
Download
Save
Save Akash 3rd Sem Data Structure For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
0 ratings
0% found this document useful (0 votes)
28 views
36 pages
Akash 3rd Sem Data Structure
Uploaded by
2215148
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
Carousel Previous
Carousel Next
Download
Save
Save Akash 3rd Sem Data Structure For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
Download
Save Akash 3rd Sem Data Structure For Later
You are on page 1
/ 36
Search
Fullscreen
FIRST TERM EXAMINATION THIRD SEMESTER (B.TECH) [ETCS-209] DATA STRUCTURES—SEPT, 2014 Time: 1.30 hrs. MM. :30 Note: Attempt any three questions in total including Question No. 1 which is compulsory. Q.1.(a) Define a Double ended queue? What are its type? Ans. Adeque isa list in wi hich the element can be inserted or deleted at either end. It is also known as a head-tail linked list, because elements can be added to or removed from either the front (head) or back (tail) ena Consider the deque shown in fig. [ 29 [37 [ 4554] 63 J O12 Less 4 5 6 Righte? 8 9 42 [56] | LJ 63 [27 [18] Right=0 1 2 Left=3 4 5 6 LeR-7? 8 9 Double-ended queues there are two variants of double-ended queue. (2) Input Restricted deque: In this dequeue, insertions can be done at one of the dequeue, while deletion can be done from both ends (2) Output Restricted deque: In this dequeue, deletions can be done only at one of the dequeue, while insertion can be done on both ends, Q.1.(6) What are linear list? What are it types? An. A linear list is a non-sequential collection of data items called nodes. These nodes in principle are structures containing fields, each node in a linked list has basically two field (1) Data field (2) Link field. The data field contains an actual value to be stored and processed, And the link field contain the address of the next data item in the linked list. Basically, START) INFO] wwFo] x Single linked list START Me a NEXT [2 Prev [into [next Jef Prev | into | next Nodes L = = . Doubly linked liste-eulse ‘third Semester, Data Structures ‘Types of linked list: (1) Singly linked list (2) Doubly linked list (3) Circular linked list (4) Circular doubly linked list Q.1.(c) Reverse a linked list without using the pointer? Ans. To reverse a linear linked list, three pointer fields are used. These are t cpt which hold the address of the previous node, current node and next node. yy, With the address of the first node, which is held in pointer variable FIRST, is agg” to PTR and typt is assigned value NULL. y Algorithm Step 1 PTR = FIRST Step 2 ‘TPT = NULL Step 3 Repeat step 4 while PTR! = NULL Step 4 (a) CPT = LINK (PTR) (b) LINK (PTR) = TPT (©) TPT = PTR (d) PTR = CPT Step 5 STOP. Q.1.(d)(é) Convert the following in fix expression into a postfix using a stack la + (b-c))* ((d-e)/(5+g-h) Ans. Symbol Scanned Stack Express (Post fix) 1, { ( a 2; a ( a 3. + (+ a 4. ( (+4 ab 5. b (+ ab | 6. - tH abe | %. ( I+(- abe — { 8. ) (+ abe — | 9. ) abe - + | 10. = = abe - + | 1. { { abe-+ | 12, ( *(( abe - + 13. a + abe-+d | 14. us a(- abe—+d | 15. e a abe - + de | 16. ) * abe - + de- | 11: i v abe ~ + de - | 18. ( “Ul abe ~ + de — | 19 3 “u abe-+de-f 20 + ‘Ue shen Wnt =f ait * “Wa abe +de—fe |LP. University-{B.Tech)-Akash Books 2014-3 es a Ae abe— +de-5g ae B He abe — + de —fgh = : vw” abe = + de - fgh-+ = ! = abe - + de - fgh-+/* Q.1.(d)(Gi) If you are using C language to implement the heterogenous linked list, what pointer type will yuc “1se? Ans. We use the void pointer to implement the heterogeneous linked list. The heterogenous linked list contain different data types in its nodes and we need a link, Pointer, to connect them. Since we can't use ordinary pointer for this, we use the void Pointer. Void pointer is a generic pointer type, and capable of storing pointer to any type. Q.1.(e) What are threaded binary Trees? How are threads different from pointers? And how we can determine the next node to which a thread points? Ans. In a linked representation of any binary tree, half of the entries in the pointer field LEFT and RIGHT will contain null entries. This space may be more efficiently used by replacing the null entrics by special pointers called threads. Which points to the nodes higher in the trees. Such trees are called Threaded Tree. __ Difference between threads and pointer: Threads in a binary tree must be distinguished from normal pointer. In a graphical representation of a threaded binary tree, threads are shown by dotted lines. In a computer memory, an extra field called tag or flag is used to distinguish a thread from a normal pointer. ‘Tree can be threaded using one way threading or two way threading. In a one way threading, a thread will appear in the right field of the node and will point to the successor node in the in order traversal of tree; and in two way threading of tree a thread will also appear in the left field of a node and will point to the preceding node in the in order traversal of tree. Q.2.(a) Write an algorithm or pseudo code to extract characters from a given string from a given position for n characters and store it another string which is initialized at run time. Ans. # include
# define SIZE 100 void print_str (char S (1); void read_str (char S{)); main () { char str (SIZE); dof read_str (Str); print_str (Str); } while (Str (0); ) void read_str (char * S) (0; (c= get char())!="\n';i ++) Slil=c S{i] = NULL;| am 4-2014 ‘Third Semester, Data Structures 1 Void print_str (char*S) for (i =0; 8 [isi+4) putchar (Si); putchar (‘\n'); ) Q.2.(b) What is Abstract Data t} id its impl tation t aon stract Data type anid its implementation through ag, Ans. Abstract Data Type: Abstract data type is the specifications of the data which specifies the logical and mathematical model of the delta type. ‘om To implement a fraction data type: ‘Type day strict { int numerator, denomination; fraction; } main () ( fraction f; £. numerator = 1; £, denomination = 2; Application | «—use the ADT t |Spectication] «—define the ADT Implementation — Implement ADT When we use abstract data type, our program divide into two: ‘The Application: The part that use Abstract data type. The Implementation: The part that implement the Abstract data type. Q.2.(c) How will you check the validity of an expression containing nested parenthesis? ‘Ans. To check the validity of an expression containing nested parenthesis we use the stack. Stack works fine for this. The steps are: (1) Maintain a stack of characters. (2) Whenever you find opening braces ‘(,‘’, or {’ push it on the stack. (3) Whenever you find closing traces), ‘?, 'Y check if top of stack is corresponding opening bracket, if yes then pop the stack, else break the loop and return false. (4) Repeat step 2-3 until end of the string. Q.3.(a) Write a pseudo code/algorithm for (i) insertion at the end of a circular linked list. (éi) Deletion of a node with a given data in a doubly linked list. Ans, FIRST [te we] bls blo] | 5 PTR cpr'pe ved ase ng LP. University-(B.Tech)-Akash Books Repeat CPT = Link (CPT) till link (CPT) ¢ FIRST ie, LINK (CPT) = PTR ut Atthe 1 2. eraae a) It eae eee INK (PTR) = FIRST. FiRsT cer pre 10 18 al jot pfs end If Avail = NULL then linked list is overflow and STOP. PTR « AVAIL, AVAIL « LINK (AVAIL) Read INFO (PTR) CPT « FIRST Repeat step 5 while LINK (CPT)! = FIRST CPT < LINK (CPT) LINK (CPT) © PTR LINK (PTR) « FIRST STOP. specific node is given. if FIRST = NULL then write UNDERFLOW and STOP Read DATA as information of node to be deleted. PTR « FIRST Repeat step (5) while INFO (PTR) = DATA PTR + RPT (PTR) CPT « LPT (PTR) TPT < RPT (PTR) RPT (CPT) <— TPT LPT (TPT) < CPT RPT (PTR) « AVAIL, AVAIL < PTR STOP. Q.8.(6) How can we use linked list to store a sparse matrix? Ans. The most advantage of linked list is manageability of memo important. Torepresent a sparse matrix we use a linked list for each row and cach column. So for large programs which are used to process a lot of data its needs two pointers : Next in this row and next in this column, Struct node { node * next (01; node * next row; int row; int col; in h Clas ( t value; matrix ry and it is very6-2014 ‘Third Semester, Data Structures node **colhead; // Head element of columns node ** rowhead; // the head element of rows int rows cols; // number of rows & columns of matrix; operations of the clat ) str Write a pseudo code/algorithm to remove duplicate element from, ist? Ans. Transverse the list from the head (or start) node. While Traversing, compar, each node with its next node. If data of next node is same as current node then delete th, next node. Before we delete a node, we need to store next pointer of the node. Program: # include
# include < stdlib.h> Struct node (int data; struct node * next; hb Void remove Duplicates (Struct node * head) ( Struct node * current = head; Struct node.* next ~ next; if (Current == NULL) return; While (Current > next! = NULL) ( if (Curmet — 7 data = = current - > next — > data) ( next — next = current — > next — > next; free (current _ next); ) else { current = current —> next; ) } } void Push (Struct node ** head — ref, int new-data) { Struct node * new_node = (Struct node*) malloc (size of (Struct node); new_node—> next = (*head-ref); (*head-ref) = new-node; ) Void printlist (Struct node * node) , ( While (node! = NULL) bai printf ("/d", node - > data); node = node — > next;LP. University-(B.Tech)-Akash Books au ’ int main () t ‘ struct node * head = NULL; element from a Push (& head, 20); Push (& head, 13); wersing, com, Push (& head, 13); de then delete ine Push (& head, 11); be node. Push (& head, 11); Push (& head, 11); Print f(“n linked list before duplicate removal Print List (head); remove Duplicates (head); Printf ("In linked list after duplicate Removal Printlist (head); getchar (); ) Q-4(@) Consider a float array APR (2:8, -4: 1), 6: 10) whose base address is 200, Find the address of APR (5, - 1, 8] Ans. APR (2: 8,— 4:1), 6:10) length of three dimensional of APR are 4-8-2127 Ly=1--4)41=6 L,=10-641=5 Accordingly APR contains L, : Ly : Ly =7 x 6x 5 = 210 elements. ‘Suppose the programming language store APR in memory in row major order, and Base (APR) = 200 w = 4 words per memory cell. ‘The effective indices of the subscripts are: E,=5-2=3 E,=-1-(4)=3 E,=8-6=2. For row major order, we have: E\ly = 3x6=18 B\L,+E, = 1843-21 EL, +B)L, = 21% 5 = 105 (B,L,+E,)L,+E, = 105 +2= 107 Add (APR [5,~ 1, 8) = 200 +4 (107) = 200 + 428 = 628. Q.4.(b) Consider a circular queue with fixed 5 position, Find the value of Front & REAR when following operations are performed @ A,B,C, inserted. (ii) Ais deleted. (ii) D&E are inserted. (iv) B& C deleted. (0) F inserted. (vi) D deleted. t node)); (vii) G & H inserted. Ans. (i) A,B, C, inserted. FRONT REAR8-2014 Third Semester, Data Structures (Wi) Ais doloted Bic FRONT REAR (ii) D & Faro inserted. Bi/c]oO/;E rons near (iv) B& C deleted. o;e FRONT REAR | (v) F inserted F ole t + EAR Front (vi) Dis deleted. F E fen FRONT (vii) G & H inserted. FIiG|# E REAR FRONTFIRST TERM EXAMINATION [SEPT.-2015] THIRD SEMESTER [B. TECH] DATA STRUCTURE [ETCS-209] : 1% Hrs. MM: 30 : Attempt Q.No.1 which is compulsory any two more questions Q.1. (a) How the resulting BST will look if the input is already sorted in non- decreasing order. a) Ans. Ifall nodes are already sorted in non decreasing order then all nodes are inserted into the right side of a binary search tree, for example > nodes are 1, 2,3,4,5 the BST will look like + Q.1. (6) Construct Binary tree T from following sequence. (2) PREORDER: AB DG CEHIF INORDER: DGBAHEICF Ans. PREORDER:ABDGCEHIF INORDER:DGBAHEICF Q.1. (c) Number of nodes in complete tree is 1000000. Find its depth. (1) ‘Ans. The depth of complete binary tree is !og(n) where no. of nodes is n. So the depth of complete binary tree which has the 1000000 nodes is. log (1000000) = 6 Q.1. (d) Write algorithm/program to perform POP operation on stack using singly linked list. (2)2-2015 ‘Third Semester, Data Structure Ans. Void pop (c) { Struct node * ptr; If(top = = NULL) {printf ("Underflow") return; ) ptr = top; top = ptr -» link; free (ptr); ) Q.1. (e) What is the difference between ground header linked list and circular header linked list? a) Ans. A grounded header list is a header list where the last node contains the null pointer, Acircular header list is a header list where the last node points back to the header node. Q.1, (f What is the condition that a circular queue is full if the queue is implemented using arrays? a Ans. If ((front = = 0) && (rear == Max - 1)|| (front == rear + 1)) that means queue is overflow or full Q.1. @ Binary tree with N nodes has exactly sus Null branches a Ans. Binary tree with N nodes has exactly n + 1 null branches. QL. (h) What is Time Space Trade off? Ans. Time-Space tradeoff: Is a way of solving a problem calculation in less time by using more space (or memory), or by solving a problem in very litle space by spending along time. Most computers have a large amount of space, but not infinite space. Alo, ‘most people are willing to wait a little while for a big calculation, but not forever. So if your problem is taking a long time but not much memory, a space-time tradeoff would let you use more memory and solve the problem more quickly or it could be solved very quickly but requires more memory than you have, you can try to spend more time solving the problem in the limited memory, Q.2. (a) Why height balancing tree is required? Create AVL tree of following, 4G, 2, b, 9, ¢, x, d, We, v, f. (8) Ans. The first balanced binary search tree or height balancing tree was the AVL tree with has an additional balancing condition. The simplest idea is to require that the loft and right subtrees have the same height, so height balancing tree is required. AVL tree of nodes~a, z, 6, ¥, ¢, x, d, w, ¢ Uf. ‘ Creation of AVL Tree Nodes:a, z, 9,02, 0,0, uftand circular @M \tains the null ‘to the header the queue is a) in less time >y spending space. Also, ever. So if leoff would jolved very me solving following. (8) s the AVL e that the tired. LP. University-{B.Tech.}-Akash Books Insert a @ 1 Insert z 0 @? Insert z ke? co ‘There is Balance factor of a is -2 80 after R-L. rotation the tree is. ws vane SY oF Insert ¢ 2015-3TP Unioornity-(R Tech }-Akash Books 2018-5 A eieeaae 1 ™ the Balance factor is unbalanced so after applying the IR 4 eS « Nps °© wD Insert « he tree in—LP. University-{B,Tech,HAkash Books 2015-7 (6) LINK (PTR) = Tpp () TPT = PTR (d) PTR = CPT Step 5 Stop. Q.3. (a) Consider the toll ih teweced polish notation using stack, lowing in fix expression and convert into re’ (6) Ans. (A + (B*C-(D/EAF)*Gye}1) Character Stack Reverse polish Notatic Scanned Postfix Notation ( ( A ( A ¥ o A ( (+ A B (4 AB s Gt AB ‘ Ge Anc - (+(- ABC* ( (+(-( ABC* D oven ABC* D / (=U ABC * D E (4-0 ABC * DE “ (HU ABC * DE F (eC ABC * DEF ) exes ABC * DEF 4 . Gc ABC * DEF */ G (HC-* ABC * DEF 4/G ) (+ ABC * DEF 4/G*_ . Ge ABC* DEF */G* — H Ge ABC * DEF 4/G* — ) = ABC* DEF */G*_H* 4 Reverse polish notation at Q-3. (b) What is an algorithm/program for inserting and deleting a node ata given location in circular linked list. 6) Ans. Inserting a node at given location. Step 1. If AVAIL = NULL then write overflow and stop Step 2. Read DATAas information of node after which insertion will be made. Step 3. PTR = AVAIL AVAIL = LINK (AVAIL) Read Info (PTR) Step 4. CPT = FIRST Step 5. Repeat Step 6 while Info (CPT) ! = DATAae eS te Sate ia er 42015 ‘Third Semester, Data Structure Insert « Inseyt d Insert w86-2015, ‘Third Semester, Data Structure After Insert the node v the tree is unbalanced so after apply the R.R rotation ty, tree is— Insert f ‘After Insert the node / the tree is unbalanced so after apply the R-L rotation final tree is— @.2. 6) Write a procedure/program to reverse a singly linked without any more memory? Ans. Reverse a singly linked list. Step 1 PTR = FIRST Step 2 TPT = NULL Step 3 Repeat step 4 while PTR! = NULL Step 4 (a) CPT = LINk (PTR)| | 8-2015 ‘Third Semester, Data Structure Step 6. CPT = LINK (CPT) Step 7. LINK(PTR) = LINK (CPT) LINK (CPT) = PTR Step 8 Stop. Deletion of node at given Location. ‘Step 1. If FIRST = NULL then write underflow and stop. ‘Step 2. Read DATA as information of nede to be deleted Step3. PTR = FIRST ‘Step 4. Repeat step 5 while info (PTR) « DATA Step 5. CPT =PTR PTR = LINK (PTR) ‘Step 6. LINK (CPT) = LINK (PTR) Step 7. LINK (PTR) = AVAIL AVAIL = PTR Step 8. Stop. QA (a) Suppose multidimensional arrays A and B are declared as A(-2* 2p and B (1:4, 5:5, -10:5) stored in column major order. (é) Find the length of each dimensions of Aand B. as (di) The number of elements in A and BR. CT (ili) Consider the elements 12, 3, 2) in B. Find the effective indices El, F), E3, and the address of the clement assuming Rase(h) « 400 and there are wei ‘words per memory location. as ‘Ana. (1) The length of 2 <> som te obta! od by Length « upper bound = Lower bound © 1 Hence the length Li of the dimensions of A are L192 =(-2) 61 -Band! 2072-7 6te2t Lo B~16 1 B12 5 5-6-8) 0 bo 1 LIS 1-10) 0 12 16 (ii) Accordingly A has 5°21 = 108 elements and has 8*11°16 = L408 be >-" GAD) The effective ir ‘ox Bi ts obta ved from Bi = ki-LA, where ki is the given inde and LB is the lower bound. Hence El = 3-1 = 2, £2 © 3-(-5) © £3 =3~(-10)-13 Considering B is stored in column-majr- order, the address of B (2,3,3) ¥" calculated as. ESL2 = 13°11 » 143, E212 + F2 = 143 +8 = 151 (ESL2 + E2) Li = 151°S = 1208, (E3L2 + E2) L1 + El = 1208 +2 = 1210 ‘Therfore address of B [33,3] = 400 + 4(1 QA (b) What is Garbage Collections? “) = 400 + 4840 = 5240.LP University-(B.Tech.}-Akaah Books nee QA. (e) Weite algorithmprogram for insertion operation on queue wving singty linked list, _ void insert () ' stroct node * ptr; tx = (atroct node *) malloc (sizeof (struct node) int item; prinf "Input the element for Inserting”): scant (/d", and item); ptr > info = item; ptr Link = NULL; If (front = = NULL) front = Ptr, ese rear — link = ptr; rear = ptr, ’ee EE FIRST TERM EXAMINATION [SEPT. 2016] THIRD SEMESTER [B.TECH] DATA STRUCTURE [ETCS-209] ‘Timo: 1.80 hrs, M.M. :30 Note: Attempt any three questions including Q.no. L which is compulsory. QL. (a) What are two main factors for measuring the performance of algorithm? Explain in brief, (2) Ans, Space and Time complexities are the parameters by which we ean analyze the performance of a program or algorithm Space Complexity: It is the amount of memory it needed to run to completion. It has a fixed pact that includes space for the cock, space for simple variable and fixed size component variables, constants ete. and a v iable part that includes the space needed by component variable whose size is dependent on the particular problem instance being solved and the stack space Time Complexity: It is the amount of computer time needs to run to completion. tis the sum of the compile time & the run time. The compile time does not depend on the instance characteristics major concern is th n time of a program. Q.1. (b) What do you mean by garbage collection? (2) age collect n (GC) is a dynamic approach to ement and heap allocation that processes and identifies dead memory block and reallocates storage for collection is to reduy automatic memory mai ‘use. The primary purpose of garbage ory leaks. Qu. (©) Define time-space trade off? @ 4 problem calculation in less time ace (or memory), orby solving a problem in very little space by spending «long time. Most computers ha ke amount of space, but not infinite space. Also, most people are willing to wait a little while for « big calculation, but not forever Sere Yur problem is taking @ long time but not much memory, a space-time tradeot would ‘et you use more memory and solve the problem more quickly or it could be Quickly but re Solving the probl Ans. Til by using more pace tradeoff: Ly a way of solviny solved very nory than you have, you e ited memory ‘an try to spend more time min the ti 1. @) How the resulting binary search tree will look like “iready sorted in non-decroasing order, Ans, if the input is @ Fall nodes are already sorted in non decreasing order then all nodes are “merted into the right side of a binary search tree, for example —» hodes are 12,9, 4,5 ‘he BST Will look like > Ts ye is Sen eeCOP Ek RT oe ae 2-2016 ‘Third Semester, Data Structure Q.1. (e) Number of nodes in a complete tree is 1000000. Find its depthy & Ans. The depth of complete binary tree is log(n) where no, of nodes isn, So the dey of complete binary tree which has the 1000000 nodes is. log (1000000) = 6 Q2. (a) Write a programv/algorithm to evaluate a postfix expression usiy stack? Consider the following infix expression and convert into posify expression using stack. (A + (B*C - (D\E “ F)*G)*H) on, Ans. Algorithm for Evaluation of Postfix Expression Create an empty stack and start scanning the postfix expression from left to rig, * Ifthe element is an operand, push it into the stack. + Ifthe element is an operator O, pop twice and get A and B respectively. Caleulat BOA and push it back to the stack * When the expression is ended, the value in the stack is the final answer. Character Stack Reverse polish Notatic Scanned Postfix Notation ( ( A ( + G A ( (+( A B (+0 AB * (+(* AB +H ABC (4(- ABC* CH(-( ABC* (4(~( ABC* D (4-0 ABC * D GU ABC * DEwo LP. University{B.TechAkash Books 2016-3 ABC * DE ABC * DEF ABC * DEF * ABC * DEF */ ABC * DEF */G ABC * DEF */G*— ABC* DEF */G* - ABC “DEF */G* - | ABC" DEF */G*-H*+ | Reverse polish notation 1 | Q2.(b) Write a procedure/program to reverse a singly linked list without sing any more memory? (3) Ans. Refer Q.2. (a) End Term Examination 2016 Q3. (a) Suppose multidimensional arrays A and B are declared as A (-2.2, 222) and B(1 : 8, -5 : 5, -10: 5) stored in column major order. (24243) (@ Find the length of each dimensional of Aand B (i) The number of elements in A and B. (iii) Consider the elements B(3, 3, 3} itr B. Find the effective indices E1, E2, Band the address of the element assuming Base (b) =400 and there are w=4 words per memory location. Ans. (i) The length of a dimension is obtained by Length = upper bound ~ Lower bound + 1 Hence the length Li of the dimensions of A are: 1=2-(-2)41=5andL2=22-241221 814128, 12 =5—(5) 41411, L33—(-10)+1=16 \®) Accordingly A has 5*21 = 105 elements and B has 8*11°16 = 1408 elements, (i) The effective i i ined from ng index Eiis obtained Bisthe lower bound Hence Bt = 3_ “LB, where ki is the given index "3 = 2, E2 =3 ~(-5)= E3=3-(-10) = 13 kotsted TH B is stored in column-major order, the address of B [3,3,3) will be 8 12 = 1g. a 13°11 = 143, EaL2 + B2 = 143 +8 = 151 1. 1 P2) Li = 15198 = 1208, (ESL? + F2) L1 + 1 = 1208 +2 = 1210 fo "© Address of B[3, 3, 9] = 400 + 4(1210) = 400 + 4840 = 5240. ie rt ate ttt ts |third ‘Semester, Data Structure smiprogram for deleting anode at, nalgorith ms given Location. pst = NULL then write underflow and stop. 1RST = sep {node to be deleted. tion of no a 4 DATA as informal step 2. Rea = FIRST step 3. PIR ; 4. Repeat step 5 while info (PTR) 4 DATA step step 5. CPT=PIR PTR = LINK (PTR) Step 6. LINK (CPT) = LINK (PTR) Step 7. LINK (PTR) = AVAIL AVAIL = PTR Step 8. Stop. QA. (a) Why height balancing of tree is required? Create AVL treeaf ix a, 2b, Ys 65% d, W, VE ‘Ans. The first balanced binary search tree or height balancing tree was te tree with has an additional balancing condition. The simplest idea is to require left and right subtrees have the same height, so height balancing trees requ AVL tree of nodes- a, z, b, y, ¢, x, d, w, e, 0, f. Creation of AVL Tree Nodes: a, 2, , 9, ¢, x, d, w, e, v, f Insert a @ Insert 2 Insert 2LP. University-(B.Tech)-Akash Books neo factor of a i8 -2 90 after R-L rotation the tree is rare i# pala’ ou insert? WY ’ 2016-56-2016 ‘Third Semester, Data Structure There is the Balance factor of bis ~ 2 So after LR rotation the tree ig insert Insert d After Insertior the tree is— Insert w Insert y After Insertion of w rotation the tree is— A tree S Insert ¢]LP. University(B.Tech)-Akash Books 2016-7 ter insertion of node ¢ the tree is unbalanced so after applying the L-L rotation tren i= ¥ ay In MT the node v the tree is unbalanced so after apply the R.R rot :tion the Be ol %s-2016 ‘Third Semester, Data Structure Insert f of ne jer: Following sequence gives the preorder and inord: Tree T. PREORDER : ABDGCEHIF INORDER : DGBAHEICE ‘anwtruets binary tree for the shove sequence. Ans. PREORDER:ABDGCENIPLP University-(B.Tech)-Akash Books 2016-9 ono BF poBAHEICEFIRST TERM EXAMINATION [SEPT. 2021/1 THIRD SEMESTER [B.TECH] DATA STRUCTURES [ETCS-209] pare ‘Time :1% hrs. pir Note: Q.1 is compulsory. Attmept any two questions from the remaining: | QA.Attempt all parts: trate the Q.1. (a) Convert the given infix into post-fix expression. Demons | steps of conversion, (2) | web en aon - Infix into Postfix expression of a + (b* c - (d/e*f)*g)*h: aractor Scanned Stack Postfix Notation | a a | + + a | ( + a b + ab . +c ab c “ abe - ae abe* | ¢ +H abc* | a Ht abetd | 1 Ho abe*d | e + abc*de a HUN abe*de ft Hn abc*def ) ra abe*def*y = + abe*defay g + abe*deP/g ) + abe*defr/ge. . +” abe*def*/g*_ h + abetdefrge-h ) O for ati (2) | Ans. Tis casistsaima hotght of any AVL-tree with 7 nodes is 3, AVL trees are binary trees with the following restrictions. pie height difference of the children is at most 1. ‘oth children are AVL trees2-2017 Q.1. (c) What is a doubly linked list? ‘Ans. Doubly Linked List : % Doubly Linked List is a variation of Linked list in whi featalis both ways, either forward and backward easily as een Mosinee Leable ig Following are the important terms to understand the concept of, doubly linked Lin * Link - Each link of a linked list can store a data called anelement, * Next - Each link of a linked list contains a link to the next link called Next, | * Prey - Each link of a linked list contains a link to the previous link called Pre + LinkedList - A Linked List contains the connection link to the first link cata First and to the last link called Last. aa Doubly Linked List Representation NULL Gece Bere Q.1. (d) What pointer type is used to implement a heterogneous list in Explain in brief? a ‘Ans. The heterogeneous linked list contains different data types in its nodes a» we need a link, pointer to connect them. It is not possible to use ordinary pointers ft this. So we go for void pointer. Void pointer is capable of storing pointer to any typ: it is a generic pointer type. Q.1. (e) Explain the following terms used in tree: is () Terminal Node _(ii) Siblings i) Degree of Node (iv) Height of tree a ‘Ans, (i) Terminal Node : Ina tree data structure, the node which owe a child is called as LEAF Node. In simple words, a leaf is anode with noc" tg (ii) Siblings : Ina tree data structure, nodes which belong to same Pane as SIBLINGS. In simple words, the nodes with same parent are eel (iii) Degree of Node : Ina tree data structure, the total number of i it the Degree of 20% node is called as DEGREE of that Node. In simple words, number of children it has. ‘ regdes (iv) Height of tree :In a tree data structure; the total number © 1 Node node to a particular node in the longest path is called a5 HEIGHT o (a alee a is atc eg here tines LP. University-{B.Tech.]-Akash Books aes ight of | tree, height of the root node is said to be height of the tree. Ina tree, height | nodes is ‘0’ | Q.2. Attempt all parts: 2017-3 i 1.5]{1.4] . (a) Calculate the address of element at X[4, 3] ina a array pear ee a row major order, Assume the base address to 7 | element requires 4 words of storage. | Ans. Row Major Order i” | Loctatiy vate ee (A) + win (i —Lower bound for row index) + j— lower bound for | column index)] Base (X) = 1000, w=4,n=4 So the address of X [4.3] = 1000 +4 [4 (4-1) + (3— DI = 1000 + 4[4 x 3 +2) = 1000 44x 14 = 1056 Q2. 6) Write an algorithm to delete the last node of the linked list. (5) Ans. Step 1: If linked list is empty (START == NULL) Write “Sorry Buddy there is no node Step 2: If linked list have only one node (START -> NEXT== NULL) free(START) START = NULL Step 3: Ifthe list have more than one node | PTR=START while(PTR -> NEXT != NULL) i PREPTR = PTR PIR = PTR-> NEXT | PREPTR -> NEXT = NULL free( PTR ) Step 4: EXIT 3. Attempt alll parts: FRONT = 2, REAR = 4, QUEUE: _,L,M,N_,_ Describe the queue as following operations takes place: LAddO 2. ada P 3, Delete two elements 4. Add QRS 5. Delete one. Ans, Initially (3) 1 2 3 4 5 6 '4-2017 (i) Add 0 | (ii) Add P I 1 Front Rear (iii) Delete two elements | a cw [Se 1 } Front Lal (iv) Add Q, R, S 1 2 3 4 5 6 Q R s N ° | Pp Rear Front (v) Delete one letter 1 2 3 4 Q R s I I Rear Front Q.3. (b) Insert the following elements in alphabetical order int binary search tree: J, R, D, G, T, E,M; H, P,A, F, @ sat of? 1. Find the final tree T 2. Find the post-order trave’ a 0 an en6-2017 Insert H Insert P Insert A Insert F Insert ¢ This is Gi) Pos Q4.at Q4.(a of Tyield INoRI PREO Ans. I PREO! This is17-7 LP. University-{B. Tech.}~Akash Books 20 Insert Q This is final tree T, Gi) Post order traversal of tree T is [AFEHGDQPMTRJ| Q.-4. Attempt all parts: Q-4. (a) A binary tree has 9 nodes. The inorder and preorder traversals are of yield the following sequences of nodes 6) INORDER: EAC KFHDBG PREORDER: FAEK C DHGB. Draw the tree T. Ans. INORDER: EAC KF HDBG PREORDER: FAEKCDHGB 0 EACK HDBG “citerf ge s-2017 ‘Third Semester, Data Structures me . +. 60 Constrnet ten ATL tase 2 following elements are j, i | BZIASAIGISI6 Ams. KL tree A 321A5£161514 Insert 3 .|-9 LP. University-{B.Tech.]-Akash Books 2017 Insert 6 | After Rebalancing Insert 16 Insert 1510-2017 Insert 14
You might also like
313301DSU Model Answer Winter-2024
PDF
No ratings yet
313301DSU Model Answer Winter-2024
24 pages
Data Structures Unit - I Notes
PDF
No ratings yet
Data Structures Unit - I Notes
86 pages
Module 2
PDF
No ratings yet
Module 2
111 pages
Final DS Mod3
PDF
No ratings yet
Final DS Mod3
92 pages
Linked List
PDF
No ratings yet
Linked List
104 pages
Week 9
PDF
No ratings yet
Week 9
44 pages
DS Unit 3
PDF
No ratings yet
DS Unit 3
70 pages
Module-2 DS 2024
PDF
No ratings yet
Module-2 DS 2024
52 pages
Unit IV - Linked List - 2 Sep
PDF
No ratings yet
Unit IV - Linked List - 2 Sep
83 pages
Unit IV - Linked List
PDF
No ratings yet
Unit IV - Linked List
81 pages
Unit IV - Linked FULL
PDF
No ratings yet
Unit IV - Linked FULL
81 pages
Lec 4
PDF
No ratings yet
Lec 4
30 pages
Circular Linked List Data Structure
PDF
No ratings yet
Circular Linked List Data Structure
47 pages
Lecture 5 DS
PDF
No ratings yet
Lecture 5 DS
42 pages
DS Module 3
PDF
No ratings yet
DS Module 3
29 pages
Chapter - 4 Stack & Queue
PDF
No ratings yet
Chapter - 4 Stack & Queue
25 pages
Dsa - Unit III
PDF
No ratings yet
Dsa - Unit III
28 pages
Ds 2
PDF
No ratings yet
Ds 2
22 pages
Data Structures With C
PDF
No ratings yet
Data Structures With C
12 pages
All Document Reader 1734249888366
PDF
No ratings yet
All Document Reader 1734249888366
27 pages
Illustrate A C Function To Add Two Polynomials. Show The Linked List Representation of Two Polynomials and Its Addition
PDF
No ratings yet
Illustrate A C Function To Add Two Polynomials. Show The Linked List Representation of Two Polynomials and Its Addition
12 pages
Linked List
PDF
No ratings yet
Linked List
19 pages
Linked List - For - Student
PDF
No ratings yet
Linked List - For - Student
47 pages
15IT305 Data Structures and Algorithms
PDF
No ratings yet
15IT305 Data Structures and Algorithms
128 pages
UNIT-IV Linked List
PDF
No ratings yet
UNIT-IV Linked List
14 pages
Data Structures
PDF
No ratings yet
Data Structures
14 pages
Data Structure فيرست+سكند2019+فاينل2019+2020
PDF
No ratings yet
Data Structure فيرست+سكند2019+فاينل2019+2020
22 pages
Linear Double Linked Lists
PDF
No ratings yet
Linear Double Linked Lists
7 pages
10 - 19ucses301 - A - 5 - 22unit Iii App
PDF
No ratings yet
10 - 19ucses301 - A - 5 - 22unit Iii App
10 pages
ICT Cp&Ds Anskey
PDF
No ratings yet
ICT Cp&Ds Anskey
9 pages
DEC 2022 Data Structure Solution
PDF
No ratings yet
DEC 2022 Data Structure Solution
18 pages
10 Done
PDF
No ratings yet
10 Done
13 pages
Module 3 Part 1
PDF
No ratings yet
Module 3 Part 1
23 pages
1071
PDF
No ratings yet
1071
123 pages
Datastructures Lab
PDF
No ratings yet
Datastructures Lab
18 pages
Ee2204 Data Structures and Algorithm (Common To EEE, EIE & ICE)
PDF
No ratings yet
Ee2204 Data Structures and Algorithm (Common To EEE, EIE & ICE)
123 pages
Aditya Borgohain Rollno.18
PDF
No ratings yet
Aditya Borgohain Rollno.18
15 pages
Assignment
PDF
No ratings yet
Assignment
5 pages
Poriyaan - CS3301 Data Structure-2-Mark-Question&Answer - Bin
PDF
No ratings yet
Poriyaan - CS3301 Data Structure-2-Mark-Question&Answer - Bin
23 pages
Text
PDF
No ratings yet
Text
9 pages
Doubly Linked List
PDF
No ratings yet
Doubly Linked List
39 pages
Assignment No 3
PDF
No ratings yet
Assignment No 3
12 pages
Dsa Assignment
PDF
No ratings yet
Dsa Assignment
5 pages
Implementing The General Linear List.: Implementation of Different Operations On Linked List
PDF
No ratings yet
Implementing The General Linear List.: Implementation of Different Operations On Linked List
10 pages
List ADT
PDF
No ratings yet
List ADT
70 pages
Mr.S.Habib Hussain, Ap/Cse, Mahalakshmi Engineering College, Trichy - 621 213
PDF
No ratings yet
Mr.S.Habib Hussain, Ap/Cse, Mahalakshmi Engineering College, Trichy - 621 213
23 pages
DSA Unit 2 - Question Bank
PDF
No ratings yet
DSA Unit 2 - Question Bank
11 pages
Data Structure
PDF
No ratings yet
Data Structure
8 pages
DSA2
PDF
No ratings yet
DSA2
11 pages
Cheat Sheet
PDF
No ratings yet
Cheat Sheet
2 pages
Data - Structures (1-5) 2&16 Marks
PDF
No ratings yet
Data - Structures (1-5) 2&16 Marks
21 pages
15forteen@data Structures VIVA Questions
PDF
No ratings yet
15forteen@data Structures VIVA Questions
8 pages
cs2201 Unit1 Notes PDF
PDF
No ratings yet
cs2201 Unit1 Notes PDF
16 pages
Linked List Sheet 2020 Answer
PDF
No ratings yet
Linked List Sheet 2020 Answer
5 pages
Data Structure
PDF
No ratings yet
Data Structure
35 pages
Linklist 1
PDF
No ratings yet
Linklist 1
29 pages
C Programming and Data Structures (R20 Syllabus JNTUA, Anantapuramu)
PDF
No ratings yet
C Programming and Data Structures (R20 Syllabus JNTUA, Anantapuramu)
8 pages
A QUEUE Is Logically A First in First Out (FIFO or First Come First Serve) Linear Data Structure
PDF
No ratings yet
A QUEUE Is Logically A First in First Out (FIFO or First Come First Serve) Linear Data Structure
4 pages
Data Structure Interview C Program: Questions To Create A Copy of A Linked List
PDF
No ratings yet
Data Structure Interview C Program: Questions To Create A Copy of A Linked List
11 pages