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)
438 views
35 pages
CS3353 Question Bank
Question bank of c programming and data structures
Uploaded by
alfiya118
AI-enhanced title
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 CS3353 Question bank For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
0 ratings
0% found this document useful (0 votes)
438 views
35 pages
CS3353 Question Bank
Question bank of c programming and data structures
Uploaded by
alfiya118
AI-enhanced title
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 CS3353 Question bank For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
Download
Save CS3353 Question bank For Later
You are on page 1
/ 35
Search
Fullscreen
MET ENGINEERING COLLEGE 83353 - C PROGRAMMING AND DATA STRUCTURES QUESTION BANK SYLLABUS UNIT. C PROGRAMMING FUNDAMENTALS (8+1 SKILL) Data Types — Variables — Operations — Expressions and Statements ~ Conditional Statements ~ Functions ~ Recursive Functions — Arrays ~ Single and Multi-Dimensional Arrays, UNITIL_C PROGRAMMING - ADVANCED FEATURES (8+1 SKILL) Structures — Union ~ Enumerated Data Types ~ Pointers: Pointers to Variables, Arrays and Functions ~ File Handling — Preprocessor Directives. UNIT IIT LINEAR DATA STRUCTURES (8+1 SKILL) ‘Abstract Data Types (ADTs) - List ADT — Array-Based Implementation ~ Linked List ~ Doubly- — Stack ADT — Implementation of Stack — Applications Queue ADT -Priority Queues — Linked Lists — Circular Linked List Queue Implementation — Applications. UNIT IV NON-LINEAR DATA STRUCTURES ‘Tree Traversals — Expression Trees ~ Binary Search Tree ~ Hashing ~ Hi bing — Double Hashing — Rehas! ‘Trees ~ Binary Trees — lash Functions — ‘Separate Chaining ~ Open Addressing — Linear Probing Quadratie Prot UNIT V SORTING AND SEARCHING TECHNIQUES Insertion Sort — Quick Sort - Heap Sort — Merge Sort -Lincar Search ~ Binary Search,TALS 3 FUNDAM! UNIT I- C PROGRAMMI Conditional Statements jons and Statement bles ~ Operations ~ Expr Je and Multi-Dimensional Arrays. Data Types ~ Vat ~ Recursive Functions — Arrays — PART A 1. Define programming paradigm. Programming paradigm is a style or way of programming. The are procedural, functional, object-oriented, logic programming. Some of the programming languages are Y Fortran VY Cobol Vv Basic Pascal vc 2. Give two examples for assignment statements. Syntax for assignment : variable = expres x=100; yratb; 3. Distinguish between character and string, Character String Teis a single character Itis a sequence of characters, ji, | Teis enclosed by single quotes. Itis enclosed by double quotes: iii, | Example : ‘C” Example : “Computer™ 4, What are keywords? Give an example UV Keywords are reserved words, they have standard and predefined meaning. W Keywords cannot be used as normal identifiers, Y Example : auto, break, char, continue, ese, if, switeh, struct, uniWha 5. What do you mean by variables in ‘C* ? ‘A variable isan identifier tat is used to represent some specified type of information, Syntax data_type variable_name; Example : int marks; 6. Identify the use of ternary or cor ional operator.worst evaluates the fst expression 1th Y ssis known as conditional oper condition is true otherwise the seeand expression iy evaliated, Syntax; condition? expt s exp? : What is mean by Operators preeeilence and associatively 2 The precedence is used to determine how an expression involving more than one operator is evaluated, W The operator at higher level of precedence is evaluated first, The ADAS rule, evaluation is based on PEI VW The operator of same precedence evahnated from either fom left to right or right to left depending on level is known ay associativity, S. What is a compilation process? ‘Compiler converts souree code into executable code, It ineltdes o Preprocessor VY Compilation 9, Vow to create enumeration constants ? ata type. Enumerated data type numerated data type is a user defined a list of identifiers also called ay symbolic numeric helps in ereatiny constants of type int used to create enumeration constant, enum keywon! i walue 0); Example Syntax : enum identifier{valuel, value2, enum holidays{sun, sat): 10. Differentiate between an expression amd a statement in C. No. Fapression ‘Statements 7 | Expression consists of operators and operands, 2 Example: Assignment statement beat77y | Example:11, Discover the meaning of C pre-processor 1. The preprocessor contains any operations in the processing language, i will be 12, Differen transformed first. V Inclusion of header file on V Macro expans W Conditional compi V Line control W Dingnosti ) 1¢ switeh ‘The preprocessing language consists of No. Nested if i. | The switeh() can test only constant val The ican evaluate relational or logical expressions, Tn switeh() ease nested ican be used. In nested if statements, s can be used witeh() case 13, Summarize the various types of C operators. 14, What is a global y U Arithmetic operators Relational operators V Logical operators V Increment or decrement operators VY Conditional or Termary operators Binvise operators Special operators (sizeof, & and * , .a inble? Global variables are declared at the begi inside any part of the program. 10; main() { print” falue of a : Yul".a); >) inyg ofthe program and it can be used4 15, Differentiate break and continue statement. No Break Continue 7, fakes the control to outside of [Takes control to the beginning of the lhe loop loop. ii, litused in both Tooping and It is used only in looping |switch statements. statements. 16. List out the features of Arrays. V An array is used to represent a collection of elements of same data type. U The elements in an array can be accessed by usin the base address. V The elements are stored in continuous memory locations, The starting memory location is known as the array name and it is known as the base address ( index ) of the array. 17. Define a float array of size 5 and assign 5 values to it. main( ) t float a[5] = 26.9, 32.4, 84.2, 20.0, 78.1}; } 18. Identify the main elements of an array declaration. V Arrays are declared like variable declaration but the array declaration has size of the array. Syntax: jata_type array_name{size]; {oR} data_type array_namefarray_size] ist_of_values}; Example for array declaration = it marks{6]; 19. Point out an example code to express two dimensional array. V Atwo dimensional array is created by speci ing its row and column size. Examples : int matrix(2}[2 int a[3][2}: 20. How to create a two dimensional array? “Two dimensional array's are stored in a row-column matrix, where the left index indicates the row and right matrix indicates the column. Syntax : data_type array_name{row_size}[{column_size}:Example : int mat{3][3}; 21. What are the different ways of initializing array? Values can be assigned to an array by normal declaration otherwise they hold garbage values. U Arrays can be initialized in following two ways : At compile time At Run time 22, What is the use of \0" and *%s"? W ‘\0"is the escape sequence for null character itis automatically added at the end of the string. V ‘%s? is a format specifier for string. It is used in scanf{ ) and printf() functions to get the string input or to print string output. 23, Define Multi-dimensional array. U Multi-dimensioned arrays have two or more index values which specify the element in the array. Declaration: int m1[10][10}; static int m2[2][2] = { {0,1}, {2,3} }s 25. What is the difference between an array and p | No. Array Pointer “Array allocates space Pointer is explicitly assigned to automatically. point to an allocated space ii, | Weeannot be resized Teean be resized using realloc Tt cannot be reassigned Pointers can be reassigned, i inter ni he ‘Size offarray name) gives the | Sizeof(pointer name) returns d number of bytes occupied by the | number of bytes used to store the pointer variable. array. 26, What is a function? W Function is a set of instruY Self contained block Performs a speeitic task V. Used to avoid redundancy of code 27 What is the need for funetions? VY Toreduce the complerity of large progeny, Y Vo increase the rendability V Toaehie reusability V TVoavoid redundancy of code 28, What are the uses of pointer Saves Memory Space Used for dynamic memory allocation Y Faster execution V Used to pass array of values to a funtion as a single argument 29, Define typedet. V The typedef keyword enables the programmer to create a new data type name by using an existing data type. V By using typedef, no new data is ereated, rather an alternate name is given to a known data type, Syntax: typedet existing_data_type new_dats_type: 30. What is an Address operator & Indirection operator? V Address operator: & -used to assign the address to a pointer variable, Referencing operator indirection operator : *- Dereferencing operator is used to access the value at the pointer variableEx: int a=S; int speak: printf(“ed",*(p)): 31. Compare actual parameter & formal argument Actual argument: Specified in the function call statement. Used to supply the input values to the function either by copy or reference Formal argument: Specified in the function definition statement. It takes either copy of address of the actual arguments 32. What is a function prototype? WV Function prototype is a function declaration statement. Syntax : retur_type function_name( st) Example: int factorial(int) parameters, 33. Differentiate call by value and call by reference. Call by value: The values of the variables are passed by the calling function to the called function. Call by reference: The addresses of the variables are passed by the cal g function to the called function. 34. List the header files in *C’ language.
contains standard 1/0 functions V
contains character handling functions
contains general utility functions Y
contains string manipulation functions
contains mathematical functions V time h> contains time manipulation functions 35. What are the steps in writing a function in a program? Function Declaration (Prototype declaration): W Every user-defined functions has to be declared before the main() Function CallingsThe user-defined functions can be called inside any functions like main(), userdefined function, etc. Function Definition: The function definition block is used to define the user-defined functions with statements. 36. State the advantages of user defined functions over pre-defined func n. V Auser defined func n allows the programmer to define the exact function of the module as per requirement. This may not be the case with predefined function, It may or may not serve the desired purpose completely. V Auser defined function gives flex! ity to the programmer to use optimal programming instructions, which is not possible in predefined function. 37. Write the syntax for pointers to structure. Struct § t char datatypel; int datatype2; float datatype3; ‘ Struct S *sptr //sptr ia pointer to structure S 38. Writ the advantages and disadvantages of recursion. Recursion makes program elegant and cleaner. All algorithms can be defined recursively which makes it easier to visualize and prove. Ifthe speed of the program is vital then, you should avoid using recursion Recursions usm more memory and are generally slow. Instead, you can use loop. 39, What is meant by Recursive function? Ifa function calls itself again and again, then that function is called Reeursive function. Example: void recursion() recursion(); /* function calls itself */ } int main() { recursion(); }UNIT Il- C PROGRAMMING - ADVANCED FEATURES Structures ~ Union — Enumerated Data Types ~ Pointers: Pointers to Variables, File Handling — Preprocessor Directives. 1. Compare arrays and structures, ‘Arrays Arrays and Functio PARTA Structures ‘An array is a collection of data items of ssame data type. Arrays ean only be declared. [A structure is a collection of data items of differe [lata types, Structures can be declared and define There is no keyword for arrays. [The keyword for structures is struct. ‘An array cannot have bit fields. |A structure may contain bit fields. ‘An array name represents the ‘address of the starting element. JA structure name is known as tag. It is a [Shorthand notation of the declaration. 2. Difference between structure and union. Structure inion Every member has its own memory. [ATI members use the same memory. The keyword used is struct. [The Keyword used is union. ‘All members occupy separate memory location, hence different interpretations of the same memory location are not possible. Consumes more space compared to union [Difrerent interpretations for the same jmemory location are possible. ‘onservation of memory is possible 3. Define Structure in CC Structure is a collection of different data types which are grouped together and each element in a C structure is called member. Ifyou want to access structure members in C, structure variable should be declared. Many structure variables can be declared for same structure and memory will be allocated for each separately. 4. How to Declare a members in Structure? A struct in C programming language is a structured (record) type[!] that aggregates a fixed set of labeled objects, possibly of different types, into a single object. The syntax for a struct declaration in C is: syntax : struct tag_name { type attribute; type attribute2; wl % 5, How to define a union in C. ‘To define a union, you must use the union statement in very similar was as you did while defining structure. The union statement defines a new data type, with more than ‘one member for your program. The format of the union statement is as follows: union [union tag] member definition; member definition; member definition: } fone or more union variables]; 6. What is the use of “typedef”? It is used to create a new data using the existing type. ‘Syntax: typedef data type name; Example: typedef int hours: hours hrs;/* Now, hours can be used as new datatype */ 7. Write the syntax for pointers to structure. Struct S ( char datatypel; int datatype2; float datatypes; hStruct S *sptr; //spte ia pointer to structure self referential data structure . vt cues A self referential data structure is essentially a structure definition which includes at Teast one member that is a pointer to the structure of its own kind. A chain of such structures can thus be expressed as follows. struct name { member 1; member 2; struct name *pointer; 4b 9. Why files are needed? ‘When a program is terminated, the entire data is I lost. Storing in a file will preserve data even if the program terminates. four 10. Enlist the File Operations. In C, you can perform four major operations on the file, either text or binary: 1. Creating a new file 2. Opening an existing file 3. Closing a file 4, Reading from and wi iting information to a file Working with files When working with files, you need to declare 8 pointer of type file, Thi i is needed for communication between the file and piouam HEE ape segation 11, How to open a file? Opening a file is performed usin, header file: fopen() ‘The syntax for opening a file in standard ig the library function in the "stdio.h"" VO is: pe = fopen("fileopen","mode") 12. List the opening modes in standard 1/0 IFthe Gite dos eae eS Not exist, open r pen for reading. Feturns NULL. ae ro [Open for reading in binary If the file does not exist, Fopenty |node. feturns NULL. ; IF the file exists, its contents are W [Open for writing, verwritten, If the file does not exist, it will be lereated,_ If the file exists, its contents are wb [Open for writing in binary loverwritten. If |mode. the file does not exist, it will be created. [Open for append. ie, Datais A ladded to If the file does not exists, it will be lend of file. [reated. JOpen for append in binary ab ~ (node: ie, lithe file does not exists, it pata is added to end offile. —f**H* v__per for both reading and Ii the file does not exist. fopen() hvriting. returns NULL. ren for both reading and Pe writing a 8 lirthe file does not exist, fopen() |binary mode. feturns NULL. lif the file exists, its contents are w+ |Open for both reading and loverwritten. If writing. lthe file does not exist, it will be created. lif the file exists, its contents are woe [Open for both reading and lovervriten. IF Iran aa the file does not exist, it will be inary mode. lreated. “ Open for both reading and Iif the file does not exists, it will be be lappending. lcreated. na JOpen for both reading and lirthe file does not exists, it will be ab+ pending reated. lin binary mode. 13. How to close a file? ‘The file (both text and binary) should be file is performed usin} pointer associated wih file to be closed 14. What are two main ways a file can be organized? “The data are placed inthe file in a sequence like beads on ‘one after another. To reach a particular ‘Sequential Access — ‘string, Data are processed in sequence, closed after reading/writing. Closing a 2 library function flose().fetose pt Pu is the fileit e read. item of data, all the data that proeseds is ieee Sete iene oie Random Aecess — The data are placed in 2 et location in the file assigned to each data item. Data are Linea BY order, A particular item of data can be reached by going directly to it, looking at any other data. 15. What is file? Afile is a semi-permanent, named collection of data. A File is usually stored on magnetic media, such as a hard disk or magnetic tape. Semi-permanent means that data saved in files stays safe until it is deleted or modified - Named means that a particular collection of data on a disk has a name, like mydata.dat and access to the collection is done by using its name. 16. Write the functions for random access file processing. - What is a function in C? Explain the ste 5. feeek() 6. ftello, 7. rewind() PART B UNITI PROGRAMMING FUNDAMENTALS List the different data types available in C. Explain the different types of operators available in C, Describe the various looping statements used in C with suitable examples. Explai about various decision making statements available in C with illustrative programs. Write a\C program to solve the quadratic equation and to find a Factorial of a given number. ‘What is an array? Discuss how to initialize a one dimensional and two dimensional arrays with suitable example? ps in writing a function in C program with Example, . Classify the function prototypes with example C program for each, . What is recursion? Write a C program to find the factorial using recursion PART B. UNIT II - C PROGRAMMING - ADVANCED FEATURES What is @ structure? Create a structure with data members of various types and SESoN tuo structure variables, Write a program to read data into these and print the same. Justify the need for structured data type. Write @ C program to store the employee information usin, Particular employee using Employee number. Wg structure and search a Define and declare a nested structure to store date, which including day, monthand yes 4, Explain about pointers and write the use of pointe 5, Explain the concept of pi in arrays with suitable example, by value and pass by reference, Write a © progratn to swap the content of two variables using pass by reference. 6. Explain about files and with it types of file processin NUT IILLINEAL rRUCT Abstract Data ‘Types (ADI Circular Linked List ~ Stack ADT ~ Implementation of Stack ~ Applications ~Queus ADT -Prierity Ques: - Queue Implementation — Applications. ) ~ List ADT — Array-Based Implementation ~ Linked List - Dovbly No. Question What is a data structure? © A data structure is a method for organizing and storing data which would allow efficient data retrieval and usage. © Addata structure is a way of organizing data that considers not only the items stored, but also thei relationships to each other. } Why do we need data structures? © Data structures allow us to achieve an important goal: component reuse. © Once data structure has been implemented, it can be used various applications. in and agein in 3. | List some common data structures. © Stacks Queues Lists Trees Graphs Tables 4 | How data structures are classified? Data structures are classified into two categories based on how the dats items are operated: i. Primitive data structure ii, Non-Primitive data structure a. Linear data structure b. Non-linear data structureLinear data structure Non-linear data structure Data are arranged in linear or | Data are not arranged in linear sequential manner manner | Every items is related to ts | Every item fs attached with previous many other | and next item items sms cannot be traversed Data items ean be traversed in | Dat a ina single run, single run, Implementation is eas Implementation is difficult. = array, stack, queue, | Example: tree, graph Differentiate linear and non-linear data structure. Define ADT (Abstract Data Type) An abstract data type (ADT) is a set of operations and mathematical abstractions . which can be viewed as how the set of operations is implemented. Objects like lists, sets and graphs, along with their operation, can be viewed as abstract data types, just as integers, real numbers and Booleans. e ‘Mention the features of ADT. a. Modularity Divide program into small functions Easy to debug and maintain i. Easy to modify b. Reuse i. Define some operations only once and reuse them in future ¢. Easy to change the implementation Define List ADT A list is a sequence of zero or more elements of a given type. The list is represented as sequence of elements separated by comma. A1, A2, A3....AN ‘Where N>0 and A is of type element What are the ways of implementing linked list? The list can be implemented in the following ways: i, Array implementation 10 ii, Linked-list implementation i Cursor implementation10 What are the types of linked lists? There are three types ily linked li ii, Doubly linked list Circularly linked lis Ww Tow the singly linked lists can be represented? Each node has wo elements i, Data ii, Next head data next How the doubly linked list ean be represented? prev data next Doubly linked list is a collection of nodes where nodes are connected by forwarded and backward link. Each node has three fields 1. Address of previous node 2. Data 3. Address of next node. What are benefits of ADT? a, Code is easier to understand b. Implementation of ADT can be changed without requiring changes to the program that uses the ADT. 4 ed list can be represented as circular linked list? ‘When singly lin \ked list, all the nodes are connected with forward links to the next Ina singly nodes in the list. The last node has a next field, NULL. In order to plement the circularly linked. lists from singly linked lists, the last node’s next field is connected to the first node. Ge ti es— ircular linked list? 15] When doubly linked list can be represented as cae ee Ina doubly linked list, all nodes are connected wit a tks, the e c : it ir linked lists fr¢ next and previous nodes respectively. In order to implement oot eee fo doubly linked lists, the first node's previous field is connected to the nd the last node’s next field is connected to the first node. a(t | Ll 16 | Where cursor implementation can be used? The cursor implementation of lists is used by many languages such as BASIC and FORTRAN that do not support pointers. The two important features of the cursor implementation of linked are as follows: © = The data are stored ina collection of structures. Each structure contains data and a index to the next structure. * Anew structure ean be obtained from the system's global memory by a call wo cursor Space array. 17 | List down the applications of List. a. Representation of polynomial ADT. b. Used in radix and bubble sortir is Sar onl AAT filesystem, the metadata ofa large file is organized asa linked list oF Tarentis | og unPle memory allocator use a free list of unused memory regions, basically a linked list with the list pointer inside the free memory itself : 18 ‘What are the advantages of linked list? a. Save memory space and easy to maintain b. Itis possible to retrieve the element at a particular index ¢- Itis possible to traverse the list in the order of increasing index. & Its possible to change the element at a particular index toa different value without affecting any other elements, ‘Mention the demerits of linked list a. Itis not possible to go backwards through the list 'b, Unable to jump to the beginning of list from the end. alIO] The polynomial equation can be represented with linked listas follows: Coetticient Exponent Next nade link struct polynomial A int coefticientsint exponentsstruct polynontial tent, } 1 | What are the operations performed in ‘The following operations ean be performed on a list i. Insertion a. Insert at beginning bb. Insert at end . Insert atter specific node 4. Insert before specific node . Deletion a. Delete at beginning b. Delete at end ¢. Delete atter speviti d. Delete before spe iii, Merging c node ie node Tmplementation of lists? © Fast, random cess of elements © Memory efficient — very less amount of memory is required Demerits moved. Insertion and deletion operations are very slow since the elements should be © Redundant memory space — difficult to estimate the size of array,23. | What is a circular linked list? Acircular linked list is a special type of linked list that supports traversing from th end of the list to the beginning by making the last node point back to the head of the list.What are the advantages in the ray implementation of li 8, Print list operation ean be carried out at the linear time by, Bind Kith operation takes a constant time ‘What is the need for the header? Meader of the linked list is the first element in the ls elements in the list. It points to the firs data clement of the list. List three examples that uses tin ed List? and it stores the number of a, Polynomial ADT DR adix sort ¢. Multi List out the different ways to implement the list? 1. Atray Based Implementation 2. Linked list Implementation Singly linked, ii. Doubly linked list iii, Cursor based linked list Write the routine for insertion operation of siny Void Insert (BlementType y linked {Position TmpCell; TmpCell=malloc(sizeotistruct Node)); it{tmpCelt==NULL) EatalEeror("Out of space!!! TrnpCellElemen } 2 TpCell >Next or} ‘Advantages of Array over Linked List. \, Array has a specific address for each element stored in it and thus we ean access any memory directly As we know the pos a on of the middle element and other elements are easily ible too, we can easily perform BINARY SEARCH in array. Disadvantages of Array over Linked List. L 30 Total number of elements need to be mentioned or the memory allocation needs to be done at the time of array creation The size of array, once mentioned, cannot be inereased ‘of elements entered exceeds the size of the array ARRAY OVEI EXCEPTION occurs,3 : Linked List over Array. sie tate seen seeot the list doesn’t need to be mentioned at the beginning of the program, Reds 2. As the linked list doesn't have a size limit, we can (elements) and increasing 0 on adding new nodes the size of the list to any extent. 32. | Disadvantages of Linked List over Array. . a a: ~ Nodes do not have their own address. Only the address of the first node is stored and in order to reach any node, we need to traverse the whole list from beginning to the desired node. . 2. Asall Nodes don’t have their particular address, BINARY SEARCH cannot be performed PARTB 1 Explain the various operations of the list ADT with examples: 2 Write the program for. array implementation of lists 3 Write a C program for linked list implementation of list 4 Explain the operations of singly linked lists Explain the operations of doubly linked lists Explain the operations of circularly linked lists f i Stack ADT ~ Implementation of Stack ~ Applications -Queue ADT: Applications. S No. v ‘Explain the steps involved in insertion and deletion nto a singly and doubly linked Wat UNIT TT LINEAR DATA STRUCTURES-STACKS, QUEUES Priority Queue: Queue Implementation Question Define Stack {A stack is an ordered list in which all j one end cat i ordered list in which al insertion LIPO Cac te oe OP: isan abstract datatype mt tanner. ‘Pe and based on the princi ind deletions are made at leotWhat are the operations of the stack? CreateStack/ InitStack(Stack) ~ creates an empty stack bs, Push(ltem) ~ pushes an item on the top of the stack ¢. Pop(ltem) ~ removes the top most element from the stack d. Top(Stack) — retums the first element from the stack «e. Istimpty(Stack) returns true if the stack is empty Write the routine to push a element into a stack. Push(litement X, Stack $) { UsPull(S) { Error(“Full Stack”); } else S—+Array[ +48 TopOfStack]=X; 4 7 | How the operations performed on linked list implementation of stack? 4. Push and pop operations at the head of the list. bb. New nodes should be inserted at the front of the list, so that they become the top of the stack. ¢. Nodes are removed from the front(top) of the stack. 3 | What are the applications of stack? The following arc the applications of stacks + Evaluating arithmetic expressions + Balancing the parenthesis «Towers of Hanoi . + Funetion calls Trée traversal 6 What are the methods to implement stack in C? ‘The methods to implement stacks are: © Array based @ Linked list based 7 Tow the stack is implemented by linked list? It involves dynamically allocating memory space at run time while performing stack operations. Since it consumes only that much amount of space is required for holding its data clements , it prevents wastage of memory space. struct stack int clement; struct stack *next; top; | Write the routine to pop a element from a stack. int pop() { ifllop>=NULL) { printf\n Stack is empty.\n");getch()sexit(1),) else {int temp; (emp=top-velement; toptop—mnext; return temp; 3)9 | Define quese. This 2 finene dame seroctare that muimeins a list of elements such FIFO - Firs In First Out principle 10 | What are the operations of a queme? The operations of 2 queve sre BEmD ost © ine) \ © deked o Gsind Tl | Write the routine to insert a element onto a qrene_ 72 | What are the tepes of queue? lowing are the types of queue: © Double ended queve © Circular queve ] jority queve | Define double ended queue ‘@ Iris a special type of queve that sllows insertion and deletion of elements both Ends. | @ Itisalso termed as DEQUE. Osetia beeen | = ween Odeon j Froet Sear TS | What are the methods to implement queue in C2 The methods to implement queues are: ©) Amay based @ Linked list based | | | |[15 | How the queue is implemented by linked list? Itis based on the dynamic memory management techniques which allow allocation and De-allocation of memory space at runtime. Insert operation It involves the following subtasks: 1. Reserving memory space of the size of'a queue clement in memory 2. Storing the added value at the new location 3. Linking the new element with existing queue 4, Updating the rear pointer Delete operation It involves the following subtasks: 1. Checking whether queue is empty 2. Retrieving the front most element of the queue 3. Updating the front pointer 4, Returning the retrieved value 16 | Write the routine to delete a element from a queue int del) JULL) /*checking whether the queue is empty*/ {return(-9999);} else {i= front—element;front = front—next;return is} 3 17_| What are the applications of queue? The following are the areas in which queues are applicable a. Simulation b. Batch processing in an operating systems c. Multiprogramming platform systems d. Queuing theory ¢. Printer server routines £. Scheduling algorithms li g. V0 buffer requests disk scheduling , CPU scheduling 18 | Define circular queue ‘A Circular queue is a queue whose start and end locations are logically connected with ‘each other. That means the start location comes after the end location. 0 front19 ‘What are push and pop operations? + Push — adding an element to the top of stack ‘ + Pop ~ removing or deleting an element from the top of stacl 20 What are enqueue and dequeue operations? * Enqueue - adding an element to the queue at the rear end Ifthe queue is not full, this function adds an element to the back of the queue, else it prints “OverFlow”, void enqueue(int 1 Queue is full Printf(“OverFlow\n”); else queue[rear] = element; Gueue[], int element, int& rear, int arraySize) {if(rear = arraySize) // Add the element to the back reart+; pt Ply. this function removes the element from the front of the auene, else it prints “UnderFlow”. void dequeueint queue[], int& fror iffron 7 Queue is empty printf(“UnderFlow\n”); else { queueffront] = 0; Delete the front element front-+; 3 Distinguish between stack and queue, ‘STACK QUEUE Insertion at one en other end front. Insertion and deletion ‘are made at one end, id rear and deletion at ‘The element inserted last would be ‘The element inserted first would be T| removed first. So LIFO structure. temoved first. So FIFO structure Full stack condition: If(top= Full stack condition: Trea “=Maxsize) Maxsize) Physically and Logically full stack Logically full. Phy vsically may or may not be full 24 | How do you test for an empty queue? post for an empty queue, we have to check whether READ-HEAD where REAR is a Gummy nena the last node ina queue and HEAD ie, Pointer that pointer to the or an empy era e286 Of aray implementation ot caciee the condition to be for an empty queue is READ
top == S>bottom; } ly need to check whether top and bottom 30 31 What are the features of stacks? © Dynamic data structures Do not have a fixed size Do not consume a fixed amount of memory Size of stack changes with ‘each push() and pop() operation. Each push() and pop() operation increases and decreases the size of the stack by 1, respectively. Write a routine for IsEmpty condition of queue. Ifa queue is empty, this function returns ‘true’, else it returns ‘false’. bool isEmpty(int front, int rear) { return (front } rear); Explain Stack ADT and its operations Explain array based implementation of stacks Explain linked list implementation of stacks Explain queue ADT Explain array based implementation of queues6 Explain linked list implementation of queues UNIT IV NON-LINEAR DATA STRUCTURES, Tees ~ Binary Trees ~ Tree Traversals ~ Expression Trees ~ Binary Search Tree No Question 1 | Define non-linear data structure Data structure which is capable of expressing more complex relationship than tha of physical adjacency is called non-linear data structure. 2 [Define tree? Aree is a data structure, individual data items. 3 | Define lea? which represents hierarchical relationship between Ina directed tree any node which has out degree o is called a terminal node or 2 leaf. Explain the representations of priority queue. Using Heap structure, Using Linked List List out the steps involved in deleting a node from a binary search tree. 1. thas no right hand child node t>r =z 2. thas a right hand child but its right hand child node has no left sub tree torel==2 3.thas a right hand child node and the right hand child node has a left hand child node teroii=z Convert the infix expression (A-B/C)*(D/E-F) into a postfix. Postfix: ABC/-DE/F-* ‘What are the steps to convert a general tree into binary tree? * use the root of the general tree as the root of the binary tree * determine the first child of the root. This is the lefimost node in the general tree at the next level insert this node. The child reference of the parent node refers to this node continue finding the first child of each parent node and insert it below the parent node with the child reference of the parent to this node. when no more first children exist in the path . Just used, move back to the parent of the last node entered and repeat the above process. In other words, determine the firs sibling of the last node entered, 8 he complete the tree for all nodes. In order to locate where the node fits you must search for the a first child at that level and then follow the siblin; references to anil where the next sities | be inserted. The children of any sibling node can be inserted by locating the parent and t%<2What bs ® | dirceted tree is an aeyelie di all other What by called on et 2,4 3 Vr Ina directed tree if the order What are TY | What is meant by traversing? ie first child. Then the above process is repeated, imeant by directed tree? aph which has one node called its root with in degree o while nodes have in degree I a ordered tree 13 of the nodes at cach level is prescribed then such a tree is dered tree, applications of binary (ree? inary tree is used in data processing. ile index schemes Hicrarchica! database ma agement system /ersinyg a tree means pros essing it in such a way, that each node is vi ted only once. 12) What a a, Pre-o b, tn-or The different types of traversing are |_|, Ponder waverly postfix form of expression 3 re the different types of traversing? order traversal-yields prefix form of expression, der traversal-yields infix form of expression. a. Line b. Link ‘What are the two methods of binary tree implementation? “Two methods to implement a binary tree are sar representa ion, ced representation Bal subtree Ta | What is a balance factor ‘AVL trees? ice factor of a node is defined to be the difference between the height of the node's left and the height of the node's right subtree. 15. | What i ‘The node to be inserted travel down the appropriate branch track along the way of the deepest fevel node on the branch that has a balance factor of +1 or -1 is called pivot node. is meant by pivot node? 16 Wi ‘The form tt (is the length of the path in a tree? uth of the path is the number of edges on the path. In a tree there is exactly one path root to each node, avi 17 Define expression trees? nodes contain operators. of an expre’ jion tree are operands such as constants or variable names and the other that the the right 9 18 | What is mer it by binary search tree? Binary Search tre is a binary tree in which each internal node x stores an element such element stored in the left sub tree of x are less than or equal to.x and elements stored in i sub tree of x are greater than or equal 0.x. ree Rey Array 1 hed ‘What is the various representation of a binary (ree? resentation jepresentation list representatis20 List the application of tree. (i) Electrical Circuit ii) Folder structure 8. Binary tree is used in data processing, b. File index schemes £. Hierarchical database management system Define binary tree and give the binary tree node structure. aes a aS a 7-\ cay Give the pre & postfix form of the expression + Coy, Se, e Define complete binary tree? ‘Acomplete binary tree of depth ds the strictly binary tree all of whose are at level d. i Detine Tree. Explain the tee “aversals with algorithms and examples, ‘Construct an expression fee me for the expression (@ Fb ey NG" e+ 8) Give the oumputs when you atety Preorder, inorder and Postorder traversals Expla eh tree ADT in detail binary Mashing ~ Nash Funet Quadratic Probing ~ Double Hashin S Open Addressing ~L, ~Rehashing, feparate Chain Question ‘semtifier and computes the omen SmPMeS the address of thay ‘entities in the hash 2° [What is the need for hashing? ‘suse t perfor insertions dtetons and find in constant a stant average time,ash function? Mesh ‘uion takes an identifier and computes the address of that identifier ‘= tre using some function. List out the different types of hashing functions? The different types of hashing functions are, a. The division method b. The mind square method c. The folding method . Multiplicative hashing e. Digit analysis, ‘What are the problems in hashing? a, Collision b. Overflow 6 ‘What are the problems in hashing? ‘When two keys compute in to the same location or address in the ash table tarsus 2 the hashing function then itis termed collision. ‘Compare the various hashing techniques. ‘Technique Load Factor | Separate chaining - close tol Open Addressing - —_—_should not exceed 0.5 | Rehashing - reasonable load factor | Define collision in hashing. ‘When two different keys or identifiers compute into the same location or address in the hasit table through any of the hashing functions, then it is termed Collision Define Double Hashing. Double Hashing is a collision-resolution technique used in open addressing catsgory. In double hashing, we apply a second hash function to x and probe at 2 distance of kash? (x). hash? (x)... , and so on. i 10 | What are applications of hashing? ‘The applications of hashing are, } ‘© Compliers use hash table to keep track of declared variables on source cod urce code. ‘© Hash table is useful for any graph theory problem, where the nodes have real names instead of numbers. eed Hash tables are used in programs that play games. Online spelling checkers use hashing. What are the collision resolution methods? The following are the collision resolution methods ‘© Separate chaining. © Open addressing © Multiple hashing Define separate chaining Itis an open hashing Ie. fi a Pe ing technique. A pointer field is added to each record loeatiom, when overflow occurs; this pointer is set to point to overflow blocks 2 ths low bloc! ii ‘method, the table can never overflow, since the linked lists are sated wus lc ans , , since is linked lists are only ext va keys.3 What is open addressing? esolve th Open addressing is alo called closed hashing, which is an alternative f ee a Collisions with linked lists. In this hashing system, ifa collision aecurs, alterna are tired until an empty cell is found There are three strategies in open auddressing: © Linear probing © Quadratic probing © Double hashing 14] What is Rehashing? ethe table is close to full, the search time grows and may become equal to the table size When the load factor exceeds a certain value (e.g. greater than 0.5) we do Rehashing: Build a second table twice as large as the original and rehash there all the keys of the original table, Rehashing is expensive operation, with running time O(N) However, once done, the new hash table will have good | performance. 15 | What is Extendible Hashing? Used when the amount of data is too large to fit in main memor N records in total to store, M records in one disk block The problem: in ordinary hashing several disk blocks may be examined to find an element - a time consuming process. Extendible hashing: no more than two blocks are examined. Fy and external storage is used. PART Explain hashing Explain open addressing and its types detail about separate chaining. ERE Explain Rehashing in detail Explain Extendible hashing in detail, Insertios UNIT V SORTING AND SEARCHING TECHNIQUES 1n Sort — Quick Sort — Heap Sort ~ Merge Sort -Linear Search Define so ~ Binary Search, ing ranges the numerical and alphabetical data present ina lst in a specific order or sequence. There are a number of sortin, available, The algorithms can be chosen based on the fo © Size of the data structure © Algorithm efficiency Sorti i techniques owing factors Programmer's knowledge of the t 2 © Internal sorting, © External sorting, 3” [What do you mean by internal and external sorting? ‘An internal sorts any data sorting process that takes flac en the main memory of a computer. This is possibl tirely within, Mention the types of sorting : | | | fe whenever the sorted is small enough to all be held in the main mens nn" (Me (ata ts in memory, bcTiaternal sorting is a term for a class of sorting ‘algorithins that can handle massive amounts of data, External sorting is required wh being sorted do not fit into the main memory of a computing device (usually KAM) and instead they must reside in the slower external memory (usually a ht’ How the insertion sort is done with the array? It sorts a list of elements by inserting each successive clement in the drive). - previously sorted Sub list, Consider an array to be sorted A{1]A[2},----Al0} a Pass 1: Al2] is compared with Af1] and placed them in sorted order {an appropriate ]. Pave 2: ATS] is compared with both A[1] and A[2] and inserted place. This makes A[}], A[2] A[3] as a sorted sub arr fc, Pass nel: Afn] is compared with each efement in the sub array ALU, A (2) A [n-t] and inserted at an appropriate position JT is insertion sort? How many passes are required for the elements be sorted ? ng of the simplest sorting algorithms isthe insertion sort, Insertion sort const of Nel passes For pass PL through N-I insertion sort ensues thatthe elements if positions 0 through P-1 are in sorted order .It makes use of the fact that elements 19 position 0 through P-1 are already known to be in sorted order Tanction in C for insertion sort ? Write the int N) void insertionsort(clementtype Al}. ‘ int j, p; elementtype tmp: for(p=1 sp
0 && af j-} } eum dedalilablds Tort and quiek sort? Merge sort quick oF vpivide and conquerstratesy Divide and conquer strategy 2. Partition by position Partition by value___ Mention some methods for in quick sort? 1. Choosing first element 2. Generate random number 3. Median of three Thoosing the pivot elemen Fant sean in quick sort? | Wharare the three cases that arise during The efi to Fight seam in quick so ‘Vand j erass each other 2 Vana do not cross each out Vand points the same posto Waatisthengarar eternal sory nto memory. So extemal sorting Neral sorting is required WEEE the input necessary where the program is toe IaFES too large to fi= Ti | What is sorting? . . Sorting is the process of arranging the given items in a logical order. Sorting is an example where the analysis can be precisely performed. 2 | What is merge sort? The merge sort algorithm is a classic divide conquer strategy. The problem is divided into Iwo arrays and merged into single array 13] What docs internal sorting mean? Internal sorting is a process of sorting the data in the main memory 14 | What are the various factors to be considered in deciding a sorting algorithm? Factors to be considered in deciding a sorting algorithm are, Programming time Executing time for program Memory or auxiliary space needed for the programs environment. 15 | Ts the heap sort alw better than the quick sort? No. the heap sort does not perform better than the quick sort. Only when array is nearly sorted to begin with the heap sont al such a case, the quick deteriorates to i Igorithm gains an advantage. In its Worst performance of O (n2), 16 |Name some of the external sorting methods, [Some of the external sorting methods are, 1. Polyphone sorting 2. Oscillation sorting 3. Merge sorting data with integer keys by grouping keys by the indivi which share the same significant position 17 | Define searching Searching refers to determining whether an or not. If the clement is present, the search considered as an unsuccessful search. The choi following factors 4. Order of elements in the list Le., random or sorted b. Size of the list Mention the types of searching v The types are © Linear search #_Binary vearch 19 | What is meant by linear search? Linear search or sequential search is a method for that consists of checking every one of its element the desired one is fournd idual digits element is present in S considered as suc, ice of @ searching tec 8 given list of elements ‘cessful, otherwise it is hnique is based on finding a particular vatuc i one ata sence ne and in sequence, until20 | What is binary search For binary search, the array should be arranged in ascending or descending order. In each step, the algorithm compares the search key value with the middle element of the array. If the key match, then a matching clement has been found and its index, or Po: returned. n, is. Otherwise, if the search key is less than the middle element, then the algorithm repeats its action on the sub-array to the left of the middle element or, if the search key is greater, on the sub-array to the right. PARTB lExplain the sorting algorithms |Explain the searching algorithms 3 Write a C program to sort the elements using quick sor, insertion and merge sort. Tite a © program to perform searching operations using linear and binary search,
You might also like
CD3291 Data Structurres and Algorithm Lab Manual
PDF
No ratings yet
CD3291 Data Structurres and Algorithm Lab Manual
84 pages
DDM Lab Manual
PDF
100% (1)
DDM Lab Manual
80 pages
CS3301 - DS Unit 1 New
PDF
100% (1)
CS3301 - DS Unit 1 New
23 pages
cs8261 Lab Manual
PDF
100% (2)
cs8261 Lab Manual
44 pages
C Record CORRECTED
PDF
100% (1)
C Record CORRECTED
40 pages
Cs3362 C Programming and Data Structures Lab Ece
PDF
No ratings yet
Cs3362 C Programming and Data Structures Lab Ece
105 pages
CS3251 Programming in C - IQ 1 - by WWW - Notesfree.in
PDF
100% (1)
CS3251 Programming in C - IQ 1 - by WWW - Notesfree.in
7 pages
AL3391 AI UNIT 2 NOTES EduEngg
PDF
No ratings yet
AL3391 AI UNIT 2 NOTES EduEngg
24 pages
Ui&ux .New
PDF
100% (1)
Ui&ux .New
35 pages
CS3591 Computer Networks Lab Manual Finalized
PDF
No ratings yet
CS3591 Computer Networks Lab Manual Finalized
67 pages
CS 3353 C Programming and Data Structure QB
PDF
No ratings yet
CS 3353 C Programming and Data Structure QB
7 pages
CS3353 Unit 2
PDF
No ratings yet
CS3353 Unit 2
26 pages
CP4292 Syllabus
PDF
No ratings yet
CP4292 Syllabus
4 pages
Python Record
PDF
No ratings yet
Python Record
35 pages
cs3401 Algorithms Lab Manual Final
PDF
No ratings yet
cs3401 Algorithms Lab Manual Final
43 pages
CCW331 BA IAT 1 Set 1 & Set 2 Questions
PDF
No ratings yet
CCW331 BA IAT 1 Set 1 & Set 2 Questions
19 pages
GE3151 Problem Solving and Python Programming Lecture Notes 2
PDF
No ratings yet
GE3151 Problem Solving and Python Programming Lecture Notes 2
158 pages
UNIT 1 - CS3401-Algorithms
PDF
No ratings yet
UNIT 1 - CS3401-Algorithms
22 pages
CCS366 - Software Testing and Automation UNIT IV
PDF
No ratings yet
CCS366 - Software Testing and Automation UNIT IV
48 pages
Oop Lesson Plan Cs3391 Jec
PDF
No ratings yet
Oop Lesson Plan Cs3391 Jec
4 pages
CSE 6th Semester - Web Application Security - CCS374 - Question Bank and Important 2 Marks Questions With Answer
PDF
No ratings yet
CSE 6th Semester - Web Application Security - CCS374 - Question Bank and Important 2 Marks Questions With Answer
22 pages
Question Paper - AI (Feb 1)
PDF
No ratings yet
Question Paper - AI (Feb 1)
2 pages
Syllabus GE3151 PROBLEM SOLVING AND PYTHON PROGRAMMING 3 0 0 3
PDF
No ratings yet
Syllabus GE3151 PROBLEM SOLVING AND PYTHON PROGRAMMING 3 0 0 3
2 pages
Java Week 7 Solutions (Nptel)
PDF
No ratings yet
Java Week 7 Solutions (Nptel)
2 pages
Ad3311 Set 1
PDF
No ratings yet
Ad3311 Set 1
2 pages
Ex - No:2 Develop A Lexical Analyzer To Recognize A Few Patterns in C Aim: Algorithm
PDF
No ratings yet
Ex - No:2 Develop A Lexical Analyzer To Recognize A Few Patterns in C Aim: Algorithm
7 pages
CS3401 Questions
PDF
No ratings yet
CS3401 Questions
2 pages
Array Implementation of List
PDF
No ratings yet
Array Implementation of List
22 pages
DSA Lab Syllabus
PDF
No ratings yet
DSA Lab Syllabus
1 page
Unit I - QB
PDF
100% (1)
Unit I - QB
3 pages
Ad3251 Unit 2 Notes Edu Engg
PDF
No ratings yet
Ad3251 Unit 2 Notes Edu Engg
35 pages
Lab Manual
PDF
No ratings yet
Lab Manual
59 pages
CS8691 AI CO-PO Mapping
PDF
No ratings yet
CS8691 AI CO-PO Mapping
6 pages
Compiler Design MCQ - Javatpoint
PDF
No ratings yet
Compiler Design MCQ - Javatpoint
1 page
Data Structures Design - AD3251 - Important Questions With Answer - Unit 1 - Abstract Data Types
PDF
No ratings yet
Data Structures Design - AD3251 - Important Questions With Answer - Unit 1 - Abstract Data Types
15 pages
Cs3461 Operating Systems Laboratory L T P C
PDF
No ratings yet
Cs3461 Operating Systems Laboratory L T P C
1 page
AL3452-OS Manual
PDF
No ratings yet
AL3452-OS Manual
125 pages
Distributed-Computing Notes
PDF
No ratings yet
Distributed-Computing Notes
108 pages
AL3452 OS Lab Manual
PDF
No ratings yet
AL3452 OS Lab Manual
85 pages
CS3461 Set 1
PDF
No ratings yet
CS3461 Set 1
3 pages
Compiler Design Lab Manual
PDF
No ratings yet
Compiler Design Lab Manual
36 pages
Al3411 Artificial Intelligence and Machine Learning Laboratory L T P C
PDF
No ratings yet
Al3411 Artificial Intelligence and Machine Learning Laboratory L T P C
11 pages
CP4252 Machine Learning Lab Manual
PDF
No ratings yet
CP4252 Machine Learning Lab Manual
37 pages
UNIT 5 - CS3401-Algorithms
PDF
No ratings yet
UNIT 5 - CS3401-Algorithms
9 pages
UNIT 1 C PRogramming Fundamentals
PDF
No ratings yet
UNIT 1 C PRogramming Fundamentals
43 pages
Question Bank - OS
PDF
No ratings yet
Question Bank - OS
6 pages
Ds Unit 1 Data Structures
PDF
No ratings yet
Ds Unit 1 Data Structures
27 pages
IT3401 Web Essential Lab
PDF
No ratings yet
IT3401 Web Essential Lab
51 pages
cs3451 Ios Unit III Notes
PDF
No ratings yet
cs3451 Ios Unit III Notes
31 pages
Al3452 Os Notes
PDF
No ratings yet
Al3452 Os Notes
280 pages
Lab Record-Cs3401 Algorithms
PDF
No ratings yet
Lab Record-Cs3401 Algorithms
79 pages
Oose Unit 5
PDF
No ratings yet
Oose Unit 5
118 pages
Dbms
PDF
No ratings yet
Dbms
99 pages
CS3353 Unit2
PDF
No ratings yet
CS3353 Unit2
51 pages
CS3271 NEW C Programming Lab Manual
PDF
No ratings yet
CS3271 NEW C Programming Lab Manual
40 pages
Os Lab Manual
PDF
No ratings yet
Os Lab Manual
54 pages
Anna University Notes
PDF
No ratings yet
Anna University Notes
153 pages
Cs3353 Foundations of Data Science L T P C 3 0 0 3
PDF
No ratings yet
Cs3353 Foundations of Data Science L T P C 3 0 0 3
2 pages
Object Oriented Programming - CS8391
PDF
No ratings yet
Object Oriented Programming - CS8391
9 pages
CS 3353 Question Bank
PDF
No ratings yet
CS 3353 Question Bank
10 pages
Software Testind and Automation - Course File
PDF
No ratings yet
Software Testind and Automation - Course File
17 pages
Updated Ethical Hacking QB
PDF
No ratings yet
Updated Ethical Hacking QB
35 pages
1.vision Mision
PDF
No ratings yet
1.vision Mision
3 pages
CS3353 QB
PDF
No ratings yet
CS3353 QB
30 pages
231CS324-OS-CPU Scheduling Algorithms Roleplay
PDF
No ratings yet
231CS324-OS-CPU Scheduling Algorithms Roleplay
6 pages