Data Structures Through C. Student Workbook

Similar documents
A6-R3: DATA STRUCTURE THROUGH C LANGUAGE

INSTITUTE OF AERONAUTICAL ENGINEERING

FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- MARCH, 2012 DATA STRUCTURE (Common to CT and IF) [Time: 3 hours

Table of Contents. Chapter 1: Introduction to Data Structures... 1

CS301 - Data Structures Glossary By

Course Name: B.Tech. 3 th Sem. No of hours allotted to complete the syllabi: 44 Hours No of hours allotted per week: 3 Hours. Planned.

DATA STRUCTURE : A MCQ QUESTION SET Code : RBMCQ0305

MID TERM MEGA FILE SOLVED BY VU HELPER Which one of the following statement is NOT correct.

FINALTERM EXAMINATION Fall 2009 CS301- Data Structures Question No: 1 ( Marks: 1 ) - Please choose one The data of the problem is of 2GB and the hard

End-Term Examination Second Semester [MCA] MAY-JUNE 2006

Data Structures Through C. Student Handout Book

PROGRAMMING IN C++ (Regulation 2008) Answer ALL questions PART A (10 2 = 20 Marks) PART B (5 16 = 80 Marks) function? (8)

ASSIGNMENTS. Progra m Outcom e. Chapter Q. No. Outcom e (CO) I 1 If f(n) = Θ(g(n)) and g(n)= Θ(h(n)), then proof that h(n) = Θ(f(n))

1 P a g e A r y a n C o l l e g e \ B S c _ I T \ C \

R13. II B. Tech I Semester Supplementary Examinations, May/June DATA STRUCTURES (Com. to ECE, CSE, EIE, IT, ECC)

R10 SET - 1. Code No: R II B. Tech I Semester, Supplementary Examinations, May

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING B.E SECOND SEMESTER CS 6202 PROGRAMMING AND DATA STRUCTURES I TWO MARKS UNIT I- 2 MARKS

Data Structures Question Bank Multiple Choice

CS8391-DATA STRUCTURES QUESTION BANK UNIT I

FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- OCTOBER, 2012 DATA STRUCTURE

DYNAMIC MEMORY ALLOCATION AND DEALLOCATION

1. Attempt any three of the following: 15

Question Bank Subject: Advanced Data Structures Class: SE Computer

A6-R3: DATA STRUCTURE THROUGH C LANGUAGE

EC8393FUNDAMENTALS OF DATA STRUCTURES IN C Unit 3

Department of Computer Science and Technology

E.G.S. PILLAY ENGINEERING COLLEGE (An Autonomous Institution, Affiliated to Anna University, Chennai) Nagore Post, Nagapattinam , Tamilnadu.

CS8391-DATA STRUCTURES

DATA STRUCTURES AND ALGORITHMS

DATA STRUCTURES AND ALGORITHMS

Reg. No. : Question Paper Code : 27157

CS 8391 DATA STRUCTURES

CS DATA STRUCTURES AND ALGORITHMS

R10 SET - 1. Code No: R II B. Tech I Semester, Supplementary Examinations, May

& ( D. " mnp ' ( ) n 3. n 2. ( ) C. " n

DS ata Structures Aptitude

Types of Data Structures

Data Structure. IBPS SO (IT- Officer) Exam 2017

MLR Institute of Technology

Algorithms and programs, basic idea of pseudo-code.algorithm efficiency and analysis, time and space analysis of algorithms order notations.

Prepared By: Ms. Nidhi Solanki (Assist. Prof.) Page 1

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified)

9. The expected time for insertion sort for n keys is in which set? (All n! input permutations are equally likely.)

MIDTERM EXAMINATION Spring 2010 CS301- Data Structures

17CS33:Data Structures Using C QUESTION BANK

O(n): printing a list of n items to the screen, looking at each item once.

Fundamentals of Data Structure

Code No: R Set No. 1

Visit ::: Original Website For Placement Papers. ::: Data Structure

DEEPIKA KAMBOJ UNIT 2. What is Stack?

GUJARAT TECHNOLOGICAL UNIVERSITY COMPUTER ENGINEERING (07) / INFORMATION TECHNOLOGY (16) / INFORMATION & COMMUNICATION TECHNOLOGY (32) DATA STRUCTURES

logn D. Θ C. Θ n 2 ( ) ( ) f n B. nlogn Ο n2 n 2 D. Ο & % ( C. Θ # ( D. Θ n ( ) Ω f ( n)

( ) ( ) C. " 1 n. ( ) $ f n. ( ) B. " log( n! ) ( ) and that you already know ( ) ( ) " % g( n) ( ) " #&

Bachelor Level/ First Year/ Second Semester/ Science Full Marks: 60 Computer Science and Information Technology (CSc. 154) Pass Marks: 24

Multiple Choice. Write your answer to the LEFT of each problem. 3 points each

Preface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS

) $ f ( n) " %( g( n)

Computer Science E-22 Practice Final Exam

Test 1 Last 4 Digits of Mav ID # Multiple Choice. Write your answer to the LEFT of each problem. 2 points each t 1

Basic Data Structures (Version 7) Name:

Lecture 26. Introduction to Trees. Trees

Answers. 1. (A) Attempt any five : 20 Marks

APJ ABDUL KALAM TECHNOLOGICAL UNIVERSITY THIRD SEMESTER B.TECH DEGREE EXAMINATION, JULY 2017 CS205: DATA STRUCTURES (CS, IT)

Draw a diagram of an empty circular queue and describe it to the reader.

a) State the need of data structure. Write the operations performed using data structures.

PESIT Bangalore South Campus Department of MCA Course Information for

INSTITUTE OF AERONAUTICAL ENGINEERING (Autonomous) Dundigal, Hyderabad

Cpt S 122 Data Structures. Course Review Midterm Exam # 1

D. Θ nlogn ( ) D. Ο. ). Which of the following is not necessarily true? . Which of the following cannot be shown as an improvement? D.

COSC 2007 Data Structures II Final Exam. Part 1: multiple choice (1 mark each, total 30 marks, circle the correct answer)

n 2 ( ) ( ) Ο f ( n) ( ) Ω B. n logn Ο

Bioinformatics Programming. EE, NCKU Tien-Hao Chang (Darby Chang)

PROGRAMMING IN C AND C++:

8. Write an example for expression tree. [A/M 10] (A+B)*((C-D)/(E^F))

Question And Answer.

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

NET/JRF-COMPUTER SCIENCE & APPLICATIONS. Time: 01 : 00 Hour Date : M.M. : 50

( ) + n. ( ) = n "1) + n. ( ) = T n 2. ( ) = 2T n 2. ( ) = T( n 2 ) +1

3 The L oop Control Structure

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

Lecture Notes. char myarray [ ] = {0, 0, 0, 0, 0 } ; The memory diagram associated with the array can be drawn like this

Adapted By Manik Hosen

12 Abstract Data Types

CP2 Revision. theme: dynamic datatypes & data structures

VALLIAMMAI ENGINEERING COLLEGE

Summer Final Exam Review Session August 5, 2009

Data Structures in C++ Using the Standard Template Library

S.E. Sem. III [INFT] Data Structures & Analysis. Primitive Linear Non Linear

Cpt S 122 Data Structures. Data Structures

DATA STRUCTURE. Exclusive for IACE Students iacehyd.blogspot.in Ph: /422 Page 1

( ) D. Θ ( ) ( ) Ο f ( n) ( ) Ω. C. T n C. Θ. B. n logn Ο

The time and space are the two measure for efficiency of an algorithm.

Introduction p. 1 Pseudocode p. 2 Algorithm Header p. 2 Purpose, Conditions, and Return p. 3 Statement Numbers p. 4 Variables p. 4 Algorithm Analysis

About this exam review

( ) n 3. n 2 ( ) D. Ο

Course Review for Finals. Cpt S 223 Fall 2008

1) What is the primary purpose of template functions? 2) Suppose bag is a template class, what is the syntax for declaring a bag b of integers?

COMP 250 Fall recurrences 2 Oct. 13, 2017

UCS-406 (Data Structure) Lab Assignment-1 (2 weeks)

( ). Which of ( ) ( ) " #& ( ) " # g( n) ( ) " # f ( n) Test 1

Transcription:

Data Structures Through C Student Workbook

Contents Lecture 1: C Revision I 01 Importance of data structures Data types in C Instructions and its types The decision control instruction Working of logical operators Different types of loops Difference between break, continue and exit Case control instruction Lecture 2: C Revision II 03 Pointers and their usage Function call by value and by reference Arrays and their working Lecture 3: Searching 05 Operations performed on an array What are algorithms Important features of an algorithm Conventions to be followed while writing an algorithm Linear search and Binary search Lecture 4: Searching and Frequency count 07 Analyzing an algorithm Rate of increase for growth rate with respect to Big Oh notation Lecture 5: Analysis of Searching Method 09 Tools to calculate time complexity Cases to be considered while analyzing an algorithm Analysis of Linear search and Binary search Lecture 6: Hashing 11 Hashing techniques: o Division method o Mid-Square method o Folding method o Digit analysis method Linear and Quadratic probing i

Lecture 7: Sorting 13 Selection sort and its analysis Bubble sort and its analysis Radix sort Lecture 8: Sorting and Recursion 15 Insertion sort Recursive functions Lecture 9: Quick Sort 17 Splitting mechanism Quick sort algorithm Quick sort program Lecture 10: Structures 19 Defining and using structures Array of structures Copying structure variables Nested structures Passing structure elements Passing structures Lecture 11: Structures and Polynomials 21 Polynomial representation Passing array of structures General operations on polynomials Lecture 12: Two Dimensional Arrays 23 Using two dimensional arrays Saddle point of an array Lecture 13: Sparse Matrices 25 Sparse matrices Passing arrays 3 tuple conversion Lecture 14: Transpose of Sparse Matrices 27 Transpose of a sparse matrix Lecture 15: Addition of Sparse Matrices 29 Addition of sparse matrices Lecture 16: Multiplication of Sparse Matrices 31 Matrix multiplication ii

Multiplication of sparse matrices Lecture 17: Storage 33 Storage - two dimensional arrays 3 dimensional arrays 4 dimensional arrays n - dimensional arrays Lecture 18: Dynamic memory allocation 35 Limitations of arrays Dynamic memory allocation Steps involved in memory allocation Lecture 19: Linked Lists 37 Memory leaks Linked lists Creation of linked lists Lecture 20: Operations on Linked Lists I 39 Appending a new node to a link list Adding a new node at the beginning of a linked list Adding a new node at a specified position in a linked list Deleting a node from a linked list Deleting all the nodes in a list Lecture 21: Operations on Linked Lists II 41 Arranging the elements in a linked list in ascending order Sorting the elements in a linked list Lecture 22: Operations on Linked Lists III 43 Reversing a linked list Merging two linked lists Lecture 23: Operations on Linked Lists IV 45 Concatenating two linked lists Addition of polynomials using linked lists Lecture 24: Circular Linked Lists 47 Circular linked lists Adding a new node to a circular list Deleting an existing node from a circular list Counting the nodes of a circular linked list Displaying the nodes in a circular linked list iii

Lecture 25: Doubly Linked Lists 49 Doubly linked lists Common operations on a doubly linked list Lecture 26: Sparse Matrices as Linked Lists I 51 Representing sparse matrices in the form of linked lists Lecture 27: Sparse Matrices as Linked Lists II 53 Add new node to linked Lists Display contents of Linked List Delete all nodes in the Linked List Program to implement sparse matrices as linked lists Lecture 28: Recursive LL 55 Recursive count( ) Recursive compare( ) Recursive copy( ) Recursive append( ) Lecture 29: Linked Lists Using Unions 57 What are unions Declaring unions Using unions Generalized linked lists Lecture 30: Generalized Linked Lists 59 Copying generalized linked lists Depth of generalized linked lists Comparing generalized linked lists Lecture 31: Stacks 61 Stack and its utilities Program to implement stack as an array Lecture 32: Stack as a Linked List 63 Program to implement stack as a linked list Lecture 33: Stack Expressions 65 Different form of expressions Lecture 34: Stack Operations 67 Infix to Postfix conversion Lecture 35: Postfix 69 Evaluation of Postfix form iv

Lecture 36: Infix To Prefix 71 Infix to Prefix conversion Lecture 37: Postfix To Prefix 73 Evaluation of Prefix form Postfix to Prefix conversion Lecture 38: Postfix To Infix 75 Postfix to Infix conversion Lecture 39: More Conversions 77 Prefix to Postfix conversion Prefix to Infix conversion Lecture 40: Queue I 79 Queue Program to implement queue as an array Lecture 41: Queue II 81 Limitations of queue Circular queue Lecture 42: Deque and Priority Queue 83 Deque Program to implement deque Priority queue Lecture 43: Trees 85 What are trees Tree terminology Strictly and complete trees Lecture 44: Tree Traversal 87 Preorder, Postorder and Inorder traversal Reconstruction of trees Lecture 45: Binary Search Trees I 89 Representing trees using arrays Linked representation of trees Binary search trees Lecture 46: Binary Search Trees II 91 Traversing of trees using Inorder, Preorder and Postorder Non recursive Inorder traversal of trees Non recursive Preorder traversal of trees v

Non recursive Postorder traversal of trees Comparison of two trees Lecture 47: Binary Tree 93 Successor and predecessor Insertion of a node in a binary search tree Deleting an existing node from a binary search tree Searching a node in a binary search tree Lecture 48: Threaded Binary Tree 95 Threaded binary trees Representation of threaded binary trees Inserting a node in a threaded binary tree Traversing the threaded binary tree in inorder Lecture 49: Heap 97 Heap Creation of a heap Heap sort Lecture 50: AVL Trees and B Tree 99 Program to create a heap AVL tree 2-3 tree B tree Lecture 51: Graphs 101 Graphs Terminology associated with graphs Representation of graphs Adjacency list Lecture 52: Adjacency Multilist 103 Adjacency matrices Adjacency multilist Orthogonal representation of graphs Lecture 53: Depth First Search 105 Depth first search Program to implement depth first search algorithm Lecture 54: Breadth First Search 107 Breadth first search vi

Program to implement breadth first search algorithm Lecture 55: Spanning Tree 109 What is a spanning tree Cost of spanning tree Kruskal s algorithm to determine minimum cost spanning tree Lecture 56: Dijkstra s Algorithm 111 Dijkstra s algorithm to determine minimum cost spanning tree AOV network Lecture 57: Memory Management I 113 Memory management First fit algorithm Best fit algorithm Lecture 58: Memory Management II 115 Next fit algorithm Lecture 59: Garbage Collection 117 Garbage Collection Marking algorithm Compaction Lecture 60: File Organization 119 Files File Organization vii

Data Structures Through C C Revision-I 1 C Revision-I (a) C supports three primary data types - int, char and float. (b) The result of condition1 && condition2 is true, if both the operands are true, otherwise false. (c) The output of condition1 condition2 is false, if both the operands are false, otherwise true. (d) There are three methods by way of which we can repeat a part of a program. They are: Using a for statement Using a while statement Using a do-while statement (e) The do-while tests the condition after having executed the statements within the loop at the least once. [A] Fill In The Blanks: (a) printf( ) and scanf( ) are whereas functions such as add( ) and delete( ) are. (b) The function is conveyed information through. (c) If the function returns no value then its declaration precedes the keyword. [B] What will be the output of the following: (a) main( ) { int a [5] = { 5,1,15,20,25 } ; int i, j, k = 1, m ; i = ++a [1] ; j = a [1]++ ; m = a [ i++] ; printf ( %d, %d, %d, i, j, m ) ; } (b) main( ) { static int count = 5 ; printf ( "\ncount = %d", count-- ) ; if ( count!= 0 ) main( ) ; } [D] Attempt the following: (a) Write a program to calculate the sum of first 10 terms of the series: 1/1! + 2/2! + 3/3! + 4/4!

Data Structures Through C C Revision-II 3 C Revision-II (a) Data Structures is the way to organize the data and the operations performed on the data. (b) In a call by value the value of each of the actual arguments in the calling function is copied into corresponding formal arguments of the called function. (c) In a call by reference the addresses of actual arguments in the calling function are copied into formal arguments of the called function. (d) A variable that can hold multiple values is known as an array. (e) The array elements are stored at adjacent memory locations. [A] Fill In The Blanks: (a) static int a [10] ; sets all elements of array to. (b) Array of pointers contain. (c) In the declaration int *arr [100], arr acts as. (d) The format specifier used to access the address of a variable is. [B] What will be the output of the following: (a) main( ) { struct gospel { int num ; char mess1 [50] ; char mess2 [50] ; } m ; m.num = 1 ; strcpy ( m.mess1, "If all that you have is hammer" ) ; strcpy ( m.mess2, "Everything looks like a nail" ) ; /* assume that the strucure is located at address 1004 */ printf ( "\n%u %u %u", &m.num, m.mess1, m.mess2 ) ; } (b) main( ) { int i = 4, j = -1, k = 0, w, x, y, z ; w = i j k ; x = i && j && k ; y = i j && k ; z = i && j k ; printf ( "\nw = %d x = %d y = %d z = %d", w, x, y, z ) ; }

4 C Revision-II Data Structures Through C [D] Attempt the following: (a) Implement sieve of Eratosthenes as per the following logic: Step- 1 Fill an array num[100] with numbers from 1 to 100. Step- 2 Starting with the second entry in the array, set all its multiples to step zero. Step- 3 Proceed to the next non-zero element and set all its multiples to zero. Step- 4 Repeat step 3 till you have set up the multiples of all the non-zero elements to zero. Step- 5 At the conclusion of step 4, all the non-zero entries left in the array would be prime numbers, so print out these numbers. (b) Write a program that will print out all the rotations of a string typed into it. For example, the rotations of the word "space" are: space paces acesp cespa espac

Data Structures Through C Searching 5 Searching (a) An Array is a finite collection of similar elements stored in adjacent memory locations. (b) The steps to solve a problem is known as an algorithm. (c) In linear search method, the element is sequentially searched in the list. (d) In binary search method, to search an element we compare it with the element present at the center of the list. [A] State True or False: (a) A data structure is said to be linear if its element form a sequence. (b) Binary search always requires the list of elements be in sorted order. (c) In linear search and binary search the list is always sorted. [B] Fill In The Blanks: (a) and are the types of algorithms. (b) While writing an algorithm we enclose the abbreviated description for the step within. (c) Important features of the algorithm are,,,, and. (d) Each algorithm is given a name to identify which is written in.

Data Structures Through C Searching and Frequency Count 7 Searching and Frequency Count (a) When sum of cubes of each digit of a number is the number itself it is said to be an Armstrong number. (b) The number of operations performed by an algorithm is directly proportional to the time taken to execute the algorithm. [A] State True or False: (a) While analyzing recursive algorithms we need to determine how many times the loop is executed. (b) If the algorithm s complexity is a combination of a two terms, we can safely ignore the slower growing term as per the rate of increase table. (c) In linear search and binary search the list is always sorted. [B] Fill In The Blanks: (a) Traversing an array means. (b) Accomplishing a task in finite number of steps is called as an. (c) The time complexity for an iterative algorithm is determined by calculating the work done in the. [C] Write algorithms and programs for the following: (a) To reverse a given string. (b) To get the biggest and smallest element in the given array.

Data Structures Through C Analysis of Searching Methods 9 Analysis of Searching Methods (a) Based on the order algorithms can be grouped into three categories: Big Omega ( f ) Big Oh O ( f ) Big Theta ( f ) (b) There are two average-cases for a linear search algorithm. The first assumes that the search is always successful and the other assumes that the value being searched will sometimes not be found. (c) The maximum divisions required for binary search is log 2 ( N+1 ). [A] True or False: (a) Big theta represents a class of functions that grow no faster than f. (b) Rate of growth is dominated by largest term in the equation. (c) Hashing is a sorting technique. [B] Fill in the blanks: (a) An algorithm on its order can be categorized as, and. (b) Function to measure the time complexity for an algorithm is of machine architecture. (c) is dominated by largest term in an equation.

Data Structures Through C Hashing 11 Hashing (a) Hashing Functions are: Division Mid Square Folding Digit Analysis (b) The formula to evaluate a hash value in Linear probing is ( f ( x ) + i ) % b where: f ( x ) is the hash value of the element obtained before linear probing, i is the counter ranging between one to number of buckets, and b is the total number of buckets. (c) The formula to evaluate a hash value in quadratic probing is ( f ( x ) + i2 ) % b and ( f ( x ) - i2 ) % b where: f ( x ) is the hash value of the element obtained before quadratic probing, i is the counter ranging between one to number of buckets, and b is the total number of buckets. [A] True or False: (a) When two identifiers hash into the same bucket it is called as Collision. (b) Under mid square method for hashing we always calculate the binary equivalent of the number. (c) The number of digits for hash value should always be 4 in Digit analysis method. (d) Each bucket in the hash table can have several slots. [B] Fill in the blanks: (a) Collision Handling Techniques are and. (b) is hashing technique, which performs division. (c) The average case analysis of linear search is. (d) The worst case for binary search is. (e) are used as the hash value in mid square method. [C] Match the Following: (a) Division of Array (1) Compile time memory allocation. (b) Static memory allocation (2) Rehashing. (c) Dynamic Memory allocation (3) Binary search

12 Hashing Data Structures Through C (d) Collision handling (e) Complexity measurement [D] Write short notes: (a) Quadratic probing (b) Halving nature of binary search (c) Big Oh notation (d) Cases in analysis (4) Big Oh Notation (5) Run time memory allocation

Data Structures Through C Sorting 13 Sorting (a) To arrange the elements of a list in a particular order (ascending or descending) is called as Sorting. (b) The elements compared in bubble sort are always adjacent. (c) Under radix sort the elements are sorted using queues. The number of queues is equivalent to the base of the elements. [A] Fill in the blanks: (a) The elements compared in bubble sort are always. (b) The frequency count for selection sort and bubble sort is. (c) The number of queues in radix sort depends on. [B] What will be the output of the following programs: (a) main( ) { int i ; for ( i = 0 ; i <= 50000 ; i++ ) printf ( "\n%d", i ) ; } (b) int i = 0 ; main( ) { printf ( "\nmain s i = %d", i ) ; i++ ; val( ) ; printf ( "\nmain's i = %d", i ) ; val( ) ; } val( ) { i = 100 ; printf ( "\nval's i = %d", i ) ; i++ ; }

Data Structures Through C Sorting & Recursion 15 Sorting & Recursion (a) Insertion sort is implemented by inserting a particular element at the appropriate position. (b) Recursion means a function that calls itself. Any function can be called recursively. [A] Fill in the blanks: (a) Recursion means a function that calls. (b) If no condition is preceded with the recursive call then it becomes an. (c) Recursive algorithms are also called as algorithms. (d) To calculate the complexity for a divide and conquer algorithm the complexity for,, and is required to be known. (e) Recursion provides an elegant solution to the program but recursive function. [B] What will be the output of the following programs: (a) main( ) { int x, y, s = 2 ; s *= 3 ; y = f ( s ) ; x = g ( s ) ; printf ( "\n%d %d %d", s, y, x ) ; } int t = 8 ; f ( int a ) { a += -5 ; t -= 4 ; return ( a + t ) ; } g ( int a ) { a = 1 ; t += a ; return ( a + t ) ; } (b) main( ) { int i, j ; for ( i = 1 ; i < 5 ; i++ ) { j = g ( i ) ; printf ( "\n%d", j ) ;

16 Sorting & Recursion Data Structures Through C } } g ( int x ) { static int v = 1 ; int b = 3 ; v += x ; return ( v + x + b ) ; } [C] Attempt the following: (a) A positive integer is entered through the keyboard, write a program to obtain the prime factors of the number. Modify the function suitably to obtain the prime factors recursively. (b) Write a recursive function to obtain the first 20 numbers of a Fibonacci sequence. In a Fibonacci sequence the sum of two successive terms gives the third term. Following are the first few terms of the Fibonacci sequence: 1 1 2 3 5 8 13 21 34 55 89...

Data Structures Through C Quick Sort 17 Quick Sort (a) Quick sort works on the splitting mechanism or the divide and conquer mechanism. (b) Quick sort is also known as partition exchange sort. (c) One of the elements is considered as the pivot element and the sort aims at bringing this pivot to a position such that one array has elements less than the pivot and the other array has elements greater than the pivot. (d) The pivot element is not necessarily the first element in the list. (e) The best case for quick sort is when the list is divided each time in approximately two equal halves. (f) Worst case time complexity for quick sort is O ( n 2 ) that is similar to bubble and insertion sort. (g) The best case time complexity is O ( log 2 n ). (h) Quick sort is better to insertion and bubble sort in average case. [A] State True or False: (a) The pivot element in quick sort is always the middle element in the list. (b) Each pass in quick sort yields the pivot element to its final position in the list. (c) In quick sort the list is rearranged in every pass such that all elements smaller than the pivot are moved before it and all elements larger than the pivot are moved after it. (d) The number of comparisons made in worst case for quick sort is similar to radix sort and insertion sort. (e) Swapping the elements in average case reduces 2n 2 inversions in comparison to bubble sort and insertion sort. (f) Time complexity of quick sort in average case is n 2 and worst case is n log n. (g) All sorting work in quick sort is done on the way back up in the recursive process. (h) Quick sort is also known as partition exchange sort. [B] Fill In The Blanks: (a) In the function quicksort( ), a condition is checked whether is greater than. If the condition is satisfied then only the array will be into two parts, otherwise, the control will simply be returned. (b) The loop is executed within the split( ) function that checks whether the indexes p and q. (c) When the control returns to the function quicksort( ) are made to function quicksort( ). (d) The efficiency of the quick sort method can be improved by,, and.

18 Quick Sort Data Structures Through C [C] Attempt the following: (a) If original list for quick sort is 6, 2, 4, 7, 1, 3, 8, 5 give the output produced by hand execution. (b) If original list for quick sort is 15, 4, 10, 8, 6, 9, 16, 1, 7, 3, 11, 14, 2, 5, 12, 13 give the output produced by hand execution.

Data Structures Through C Structures-I 19 Structures-I (a) Instead of taking different arrays for different types of data, all the data items can be grouped together into one data type called structure. (b) A structure is a collection of dissimilar elements. (c) A structure is declared using struct keyword. (d) Following the keyword struct, is the name of the structure or tag. Within the braces structure members / elements are declared. (e) The structure elements are stored in contiguous memory locations. [A] Point out the errors, if any: (a) Look at the declarations below and point out the errors. struct time { int hours ; int minutes ; int seconds ; } t ; struct time *tt ; tt = &t ; printf( %d, tt.seconds); (b) Look at the code snippet below and point out the errors. main( ) { struct student { char name[20] ; int age; } ; struct student s1 = { Rahul, 10} ; struct student s2, s3 ; s2.name = s1.name ; s2.age = s1.age ; s3 = s1 ; printf ( %s %d,s3.n,s3.a); } [B] State True or False: (a) All structure elements are stored in contiguous memory locations. (b) An array should be used to store dissimilar elements, and a structure to store similar elements. (c) In an array of structures, not only are all structures stored in contiguous memory locations, but also the elements of individual structures are also stored in contiguous locations.

20 Structures-I Data Structures Through C (d) Nested structures are not allowed. [C] Fill In The Blanks: (a) The structure elements can be accessed by using the and operators. (b) If the base address of an array of structures is passed to a function, it would be collected in a. (c) If a structure pointer is to be used to access the structure elements, the operator needs to be used. (d) In the declaration of a structure the keyword is followed by the of the structure.

Data Structures Through C Structures-II 21 Structures-II (a) On incrementing a structure pointer, it is incremented by the sizeof the struct. (b) All the members of one structure can be copied into another by simple assignment. (c) A structure can be nested within another structure. (d) If a structure is passed by reference, then the structure elements can be accessed by using the -> (arrow) operator. [A] Attempt the following: (a) Create a structure named india with structure elements as cityname, population, tot_literate. Now create a variable city that contains 50 elements of type india. Populate it with values and display only those citynames where literacy is 80% or more. (b) Write a menu driven program which displays following menu: sort by Salary sort by Designation After selecting 1 st option, list should be displayed accordingly. After selecting 2 nd option list should be displayed but a subtotal of salary should also be displayed after each designation change. Fields to be displayed are name, designation, basic, hra, conveyance, salary. [Designations could be exec, mgr, sec, etc.]. (c) Create a structure called employee with data members as name, date_of_joining and salary. Write a program that accepts a date and displays a list of those employees whose tenure is 3 or more than 3 years from accepted date.

Data Structures Through C 2D Arrays 23 2D Arrays (a) If a lot of elements from a matrix have a value 0 then the matrix is known as a sparse matrix. (b) A common way of representing non-zero elements of a sparse matrix is the 3-tuple forms. [A] State True or False: (a) If a lot of elements from a matrix have a value other than 0 then the matrix is known as a sparse matrix. (b) There is a precise definition of when a matrix is sparse and when it is not.

Data Structures Through C Sparse Matrices 25 Sparse Matrices (a) In 3-tuple form each non-zero element is stored in a row, with the 1 st and 2 nd element of this row containing the row and column in which the element is present in the original matrix. (b) The 3 rd element in this row stores the actual value of the non-zero element. [A] Pick up the correct alternative for each of the following questions: (a) A matrix is called sparse when (1) Most of its elements are non-zero. (2) Most of its elements are zero. (3) All of its elements are non-zero. (4) None of the above. (b) A sparse matrix can be lower-triangular matrix (1) When all the non-zero elements lie only on the leading diagonal. (2) When all the non-zero elements lie above leading diagonal. (3) When all the non-zero elements lie below leading diagonal. (4) Both (2) and (3). [B] State True or False: (a) A sparse matrix can be represented using a linked list. (b) When addition or multiplication of sparse matrices is performed, it is not possible to predict the size of the resultant matrix. (c) Tridiagonal matrix is the one in which the non-zero elements are placed below or above the leading diagonal.

Data Structures Through C Transpose Of Sparse Matrices 27 Transpose of Sparse Matrices (a) There are two ways in which information of a 3-tuple can be stored: Arrays Linked List (b) In both representations information about the non-zero elements is stored. [A] Fill In The Blanks: (a) matrix is the one in which the non-zero elements are placed below or above the leading diagonal. (b) A common way of representing non-zero elements of a sparse matrix is the forms. (c) The number of columns in the 3-tuple form would always be. (d) In the 3-tuple form, the 0 th column stores the number, the 1 st column stores the number and the 2 nd column stores the value of. [B] Attempt the following: (a) Write a program to obtain the transpose of a matrix.

Data Structures Through C Addition Of Sparse Matrices 29 Addition of Sparse Matrices (a) As the number of non-zero elements in a sparse matrix may vary, it would be efficient to use a linked list to represent it. (b) A sparse matrix, which is also a square matrix, can fall in the following categories: Diagonal: Where the non-zero elements are stored on the leading diagonal of the matrix. Tridiagonal: Where the non-zero elements are placed below or above the leading diagonal. Lower Triangular: Where the non-zero elements are placed below the leading diagonal. Upper Triangular: Where the non-zero elements are placed above the leading diagonal. [A] Attempt the following: (a) Write a program to subtract two sparse matrices implemented as an array. (b) Write a program to multiply two sparse matrices implemented as an array.

Data Structures Through C Multiplication Of Sparse Matrices 31 Multiplication of Sparse Matrices (a) The prerequisite for matrix multiplication is that row number for one of the matrix is similar to column number for another matrix. (b) Since the array elements are stored in adjacent memory locations any element of the array can be accessed, once the base address of the array and number of rows and columns present in the array is known. [A] State True or False: (a) C language permits Row Major arrangement as well as the Column Major arrangement. (b) Once the base address of the array and number of rows and columns present in the array is known, we can access the array elements easily. (c) For an array a[m][n] as per Row Major arrangement the address of element a[i][j] would be Base address + j * m + i. [B] Fill In The Blanks: (a) The syntax used to declare a 2D array includes two subscripts, of which one specifies the number of and the other specifies the number of of the array. (b) Arr[3][4] is an array containing rows and columns. (c) When a 2D array is stored in the memory, the array elements are stored in memory locations. (d) The two possible arrangements of elements in the memory are arrangement and the arrangement.

Data Structures Through C Storage 33 Storage (a) When a 2D array gets stored in memory, all its elements are stored linearly. (b) There are two possible arrangements of elements in memory Row Major arrangement and Column Major arrangement. (c) In general for an array a[m][n] as per Row Major arrangement the address of element a[i][j] would be Base address + i * n + j. (d) For an array a[m][n] as per Column Major arrangement the address of element a[i][j] would be Base address + j * m + i. (e) C language permits only a Row Major arrangement. [A] Attempt the following: (a) Build an array called chess to represent a chessboard. Use 0 for black and 1 for white boxes. (b) A square matrix is called symmetric if for all values of i and j, a[i][j] = a[j][i]. Write a program, which verifies whether a given 3 x 3 matrix is symmetric, or not. (c) Find the location of the element a[1][2][2][1] from a 4D integer array a[4][3][4][3] if the base address of the array is 1002.

Data Structures Through C Dynamic Memory Allocation 35 Dynamic Memory Allocation (a) The size of the array remains fixed or static. (b) We can dynamically allocate memory through the malloc( ) function. (c) If there are lots of global variables used in a program, then the loader may fail in loading them. (d) If too many local variables are present in our program then it may cause stack overflow. [A] State True or False: (a) The size of an array can be changed dynamically. (b) Linked list is used to store similar data. (c) All nodes in the linked list must always be in non-contiguous memory locations. (d) It is necessary that the link part of the last node in a linked list must contain NULL.

Data Structures Through C Linked Lists 37 Linked Lists (a) In a linked list, each element points to the next element. (b) Each element of the linked list is called a node. (c) Each node consists of two parts viz., the data and the link to the next node. (d) A linked list can hold integers, floats, strings or even multiple data types. [A] Attempt the following: (a) Write a program to add a new node at the end of the linked list. (b) Write a program to find number of nodes in a linked list. (c) Write a program to erase all the nodes of a linked list. (d) Write a program to copy one linked list into another.

Data Structures Through C Operations on Linked Lists-I 39 Operations on Linked Lists I (a) Linked list is a very common data structure often used to store similar data in memory. (b) Linked list is a collection of elements called nodes, each of which stores two items of information an element of the list and a link. (c) The elements of a linked list are not constrained to be stored in adjacent locations. (d) A linked list can grow and shrink in size during its lifetime. [A] State True or False: (a) There is no maximum size of a linked list. (b) The individual elements of a linked list are dispersed in memory. [B] Attempt the following: (a) Write a program to list the current directory in alphabetical order using a linked list. Hints: Use standard library functions findfirst( ) and findnext( ) in Turbo C to read the directory entries. Define a structure struct node, which contains the standard structure struct ffblk defined in file "dos.h" as data part, and add another element next as link to the next node. When all the directory entries are read and stored in the linked list, sort the linked list and then display the sorted linked list.

Data Structures Through C Operations on Linked Lists-II 41 Operations on Linked Lists-II (a) As nodes (elements) of a linked list are stored at different memory locations it hardly happens that we fall short of memory when required. (b) Unlike arrays, while inserting or deleting the nodes of the linked list, shifting of nodes is not required. (c) The order of the elements of linked list is maintained by explicit links between them. (d) Various types of operations can be performed on a linked list. For example, adding new nodes at the beginning, at the end or in the middle of the linked list, displaying and counting the nodes of the linked list, deleting a node form the linked list, deleting all the nodes in the linked list, sorting the elements in the list etc. [A] State True or False: (a) The elements of a linked list must be in a sorted order. (b) Sorting of the elements of the linked list can be performed by keeping the data in the nodes intact and just by readjusting the links between the nodes. [B] Attempt the following: (a) Write a program that reads the name, age and salary of 10 persons and maintains them in a linked list sorted by name. (b) There are two linked lists A and B containing the following data: A: 3, 7, 10, 15, 16, 9, 22, 17, 32. B: 16, 2, 9, 13, 37, 8, 10, 1, 28. Write a program to create: A linked list C that contains only those elements that are common in linked list A and B. A linked list D that contains all elements of A as well as B ensuring that there is no repetition of elements.

Data Structures Through C Operations on Linked Lists-III 43 Operations on Linked Lists III (a) All elements of a linked list can be accessed by first setting up a pointer pointing to the first node in the list and then traversing the entire list using this pointer. (b) Concatenation of two linked lists means appending one list at the end of the other. [A] State True or False: (a) In a linked list, if we lose the location of the first node then it is as good as having lost the entire linked list. (b) Polynomials cannot be stored using a linked list. [B] Attempt the following: (a) There are two linked lists A and B containing the following data: A: 7, 5, 3, 1, 20 B: 6, 25, 32, 11, 9 Write a function to combine the two lists such that the resulting list contains nodes in the following elements: 7, 6, 5, 25, 3, 32, 1, 11, 20, 9 You are not allowed to create any additional node while writing the function.

Data Structures Through C Operations on Linked Lists-IV 45 Operations on Linked Lists IV (a) Some of the operations that are carried out on linked lists can be easily implemented using recursion. (b) Polynomials can also be represented using linked lists. (c) It is possible to carry out various polynomial operations like polynomial addition etc using the linked lists. [A] Attempt the following: (a) Create two linked lists to represent the following polynomials: 9 x 3 + 3 x 2 + 15 x + 3 13 x 3 + 7 x 2 + 22 x + 9 Write a function add( ) to add these polynomials and print the resulting linked list.

Data Structures Through C Circular Linked Lists 47 Circular Linked Lists (a) In a circular linked list, if we begin at a given node and traverse the entire list, we ultimately end up at the starting point. (b) A circular linked list can be used to represent a stack and a queue. (c) A circular linked list has no knowledge about where the previous node lies in memory. [A] State True or False: (a) If a pointer p points to a node in a linked list, we cannot reach any of the nodes that precede the node to which p is pointing. (b) If a pointer p is pointing to one of the nodes in a circular linked list, then moving the pointer to the next node would cause a memory leak.

Data Structures Through C Doubly Linked Lists 49 Doubly Linked Lists (a) In a doubly linked list, along with the address of next node, the address of the previous node in the linked list is also stored in each node of the linked list. (b) In a doubly linked list, we can traverse the list in the forward as well as in the backward direction from a given intermediate node in the list. (c) While adding a new node to a doubly linked list, both the links to the previous node as well as the next node have to be set. [A] State True or False: (a) Doubly linked list facilitates movement from one node to another in either direction. (b) A doubly linked list will occupy less space as compared to a corresponding singly linked list. (c) If we were to traverse from last node to first node it would be easier to do so if the linked list is singly linked instead of doubly linked. (d) In a structure used to represent the node of a doubly linked list it is necessary that the structure elements are in the order backward link, data, forward link. [B] Attempt the following: (a) Write a program to add a new node to a doubly linked list. (b) Write a program to count the nodes present in a doubly linked list. (c) Write a program to delete an existing node from a doubly linked list. (d) Write a program to add a node at the beginning of a doubly linked list. (e) Write a program to add a node at a specified position in a doubly linked list.

Data Structures Through C Sparse Matrices as Linked List-Is 51 Sparse Matrices as Linked Lists I (a) When we carry out addition or multiplication of sparse matrix using the 3-tuple array representation, it is not possible to predict beforehand how many elements in the resultant matrix would be non-zero. (b) Instead of an array, we can represent the sparse matrix in the form of a linked list. (c) In the linked list representation a separate list is maintained for each column as well as each row of the matrix. (d) A node in a list stores the information about the non-zero element of the sparse matrix. (e) The head node for a column list stores the column number, a pointer to the node, which comes first in the column, and a pointer to the next column head node. [A] Pick up the correct alternative for the following: (a) In the linked representation of a sparse matrix the head node for a column list stores (1) A pointer to the next column head node. (2) A pointer to the first node in column list. (3) Column number. (4) All of the above. [B] Fill In The Blanks: (a) If a particular column list is empty then the field down of the column head node would be. (b) If a row list is empty then the field of the row head node would be empty. (c) A node in a list stores the information about the element of the sparse matrix. (d) The information stored in this special node is used for.

Data Structures Through C Sparse Matrices as Linked Lists-II 53 Sparse Matrices as Linked Lists-II (a) Similarly, a head node for a row list stores, a pointer to the node, which comes first in the row list, and a pointer to the next row head node. (b) A node stores the row number, column number and the value of the non-zero element of the sparse matrix. (c) The node also stores a pointer to the node that is immediately to the right of it in the row list as well as a pointer to the node that is immediately below it in the column list. (d) In addition to this a special node is used to store the total number of rows, total number of columns, a pointer to the first row head node and a pointer to the first column head node. (e) The information stored in this special node is used for traversing the list. [A] Attempt the following: (a) Write a program to build a sparse matrix as a linked list. (b) Write a program that provides functions for following operations on a sparse matrix represented as a linked list: (i) Store an element when the row number, column number and the value are provided. (ii) Retrieve an element for given row and column number of the matrix.

Data Structures Through C Linked List Using Recursion 55 Linked List Using Recursion (a) In C, it is possible for the functions to call themselves. (b) A function is called 'recursive' if a statement within the body of a function calls the same function. (c) Recursion is also called 'circular definition'. (d) Recursion is the process of defining something in terms of itself. [A] Fill In The Blanks: (a) A function is called if a statement within the body of a function calls the same function. (b) is also called 'circular definition'. [B] Attempt the following: (a) Using recursion write a program to find number of nodes in a linked list that represents a polynomial.

Data Structures Through C Linked List Using Unions 57 Linked List Using Unions (a) Unions are derived data types, the way structures are. (b) Both structures and unions are used to group a number of different variables together. (c) A union offers a way for a section of memory to be treated as a variable of one type on one occasion, and as a different variable of a different type on another occasion. (d) The union elements are accessed exactly the same way in which the structure elements are accessed, using a. operator. (e) When a two-byte number is stored in memory, the low byte is stored before the high byte. [A] What will be the output of the following programs: (a) main( ) { } (b) main( ) { } union { int i[2] ; long l ; } u ; u.i[0] = 0x50 ; u.i[1] = 0x45 ; printf ( "\n%lu", u.l ) ; union a { int i1 ; int i2 ; char s[4] ; } ; union a m ; strcpy ( a.s, "AAA" ) ; printf ( "\n%s", a.s ) ; printf ( "\n%u %u", a.i1, a.i2 ) ; [B] State True or False: (a) We can t assign different values to the different union elements at the same time. (b) When a two-byte number is stored in memory, the high byte is stored before the low byte.

58 Linked List Using Unions Data Structures Through C (c) A union variable occupies as much data as what a corresponding structure variable would occupy, elements of both remaining same. (d) Union provides us a way to look at the same memory locations in more than one way, which a structure cannot. (e) It is possible to have nested unions. (f) A union in a structure, or a structure in a union is not allowed. [C] Fill In The Blanks: (a) The union elements are accessed using a operator. (b) We can access the elements of the union in a structure using the operator twice.

Data Structures Through C Generalized Linked List 59 Generalized Linked List (a) We can t assign different values to the different union elements at the same time. (b) Just as one structure can be nested within another, a union too can be nested in another union. (c) There can be a union in a structure, or a structure in a union. (d) The depth of the empty generalized list is defined to be zero. [A] Fill In The Blanks: (a) When a two-byte number is stored in memory, the byte is stored before the byte. [B] Attempt the following: (a) Using recursion write a program to copy one polynomial represented as a linked list into another. (b) Using recursion write a program to add a new node at the end of the linked list.

Data Structures Through C Stacks 61 Stacks (a) A Stack is a data structure in which addition of new element or deletion of an existing element always takes place at the same end. [A] Fill in the blanks: (a) A stack is a data structure in which addition of new element or deletion of an existing element always takes place at an end called. (b) The data structure stack is also called structure.

Data Structures Through C Stacks As Linked List 63 Stacks As Linked List (a) The arithmetic expressions can be written in three forms: Infix Postfix Prefix (b) While writing an arithmetic expression, the operator symbol is usually placed between two operands. This is called as infix notation. [A] Pick up the correct alternative for each of the following questions: (a) Adding an element to the stack means (1) Placing an element at the front end. (2) Placing an element at the top. (3) Placing an element at the rear end. (4) None of the above. (b) Pushing an element to a stack means (1) Removing an element from the stack. (2) Searching a given element in the stack. (3) Adding a new element to the stack. (4) Sorting the elements in the stack. (c) Popping an element from the stack means (1) Removing an element from the stack. (2) Searching a given element in the stack. (3) Adding a new element to the stack. (4) Sorting the elements in the stack.

Data Structures Through C Stack Expressions 65 Stack Expressions (a) While evaluating an infix expression usually the following operator precedence is used: Highest priority: Exponentiation ( $ ) Next highest priority: Multiplication ( * ) and Division ( / ) Lowest priority: Addition ( + ) and Subtraction ( - ) [A] Fill in the blanks: (a) In notation the operators precedes the two operands. (b) In notation the operator follows the two operands. [B] Transform the following infix expressions into their equivalent postfix expressions: (a) ( A - B ) * ( D / E ) (b) ( A + B ^ D ) / ( E - F ) + G

Data Structures Through C Stack Operations 67 Stack Operations (a) In prefix notation the operator comes before the operands. (b) In postfix notation, the operator follows the operands. [A] Write programs for the following: (a) Copying contents of one stack to another.

Data Structures Through C Postfix 69 Postfix (a) While evaluating postfix expression, the expression is scanned from left to right. [A] True or False: (a) Stack is of fixed size. (b) The expressions within a pair of parentheses are always evaluated earlier than other operations. (c) Every character of the infix expression to be converted to postfix expression is scanned from right to left. (d) If character scanned is an operand, then it is directly added to the target expression.

Data Structures Through C Infix To Prefix 71 Infix To Prefix (a) While evaluating prefix expression, the expression is scanned from right to left. [A] Fill in the blanks: (a) A stack is generally implemented with two basic operations:. (b) The place where stacks are frequently used is. (c) The used in an arithmetic expression represent the operations like addition, subtraction, multiplication, division and exponentiation. (d) While evaluating an infix expression, the highest priority operator is. (e) In postfix to prefix conversion, the expression in postfix form is scanned from.

Data Structures Through C Postfix To Prefix 73 Postfix To Prefix (a) In the conversion from postfix to prefix, while concatenating the operator with the two elements popped from the stack, the concatenation should be of the form operator s2 s1 where s1 is the first popped element and s2 is the 2 nd popped element. [A] Transform the following infix expressions into their equivalent prefix expressions: (a) ( A - B ) * ( D / E ) (b) A * ( B + D ) / E - F * ( G + H / K )

Data Structures Through C Postfix To Infix 75 Postfix To Infix (a) In the conversion from postfix to infix, while concatenating the operator with the two elements popped from the stack, the concatenation should be of the form s2 operator s1 where s1 is the first popped element and s2 is the 2 nd popped element. [A] Transform each of the following postfix expression to infix: (a) A B - C + D E F - + $ (b) A B C D E - + $ * G F * -

Data Structures Through C More Conversions 77 More Conversions (a) The expression in prefix form to be converted to postfix form is scanned from left to right. (b) The expression in prefix to be converted to infix form is scanned from right to left. [A] True or False: (a) In prefix to infix conversion, we scan the expression from right to left.

Data Structures Through C Queue-I 79 Queue I (a) Queue is a linear data structure that permits insertion of new element at one end and deletion of an element at the other end. (b) The first element that gets added into the queue is the first one to get removed from the list. [A] True or False: (a) Queue is a non-linear data structure. (b) The first element that gets added into the queue is the last one to get removed from the list. (c) Queue permits insertion of new element at one end and deletion of an element at the other end. [B] Choose the correct alternative for the following: (a) Queue is a (1) Linear data structure. (2) Non-linear data structure. (3) Both (1) and (2). (4) None of the above. (b) The end at which a new element gets added to a queue is called (1) Front. (2) Rear. (3) Top. (4) Bottom. (c) The end from which an element gets removed from the queue is called (1) Front. (2) Rear. (3) Top. (4) Bottom. (d) Queue is also called (1) Last-In-First-Out data structure. (2) First-In-Last-Out data structure. (3) First-In-First-Out data structure. (4) Last-In-Last-Out data structure. [C] Write programs for the following: (a) Write a program to add elements to a queue implemented as a circular linked list. (b) Write a program to delete elements from a queue implemented as a circular linked list.

Data Structures Through C Queue-II 81 Queue II (a) In the implementation of queue there is a possibility that the queue is reported as full, even though in actuality there might be empty slots at the beginning of the queue. (b) A priority queue is a collection of elements where the elements are stored according to their priority levels. (c) The order in which the elements should get added or removed is decided by the priority of the element. [A] True or False: (a) Deque is a generalization of both a stack and a queue. (b) Queue can be represented only as linked lists. [B] Fill in the blanks: (a) The word is a short form of double-ended queue. (b) A is a collection of elements where the elements are stored according to their priority levels.

Data Structures Through C Deque & Priority Queue 83 Deque & Priority Queue (a) The circular queue would be reported as full only when all the slots in the array stand occupied. (b) The word deque is a short form of double-ended queue. (c) Deque is a data structure in which items can be added or deleted at either the front or rear end, but no changes can be made elsewhere in the list. [A] True or False: (a) The circular queue would be reported as full as soon as we reach the end of the array. (b) If there are elements with the same priority, then the element added first in the queue would get processed. [B] Fill in the blanks: (a) The would be reported as full only when all the slots in the array stand occupied. (b) The element with a priority is processed before any element of priority. [C] Write programs for the following: (a) Write a program to copy one queue to another when the queue is implemented as a linked list. (b) Write a program to implement priority queue as an array.

Data Structures Through C Trees 85 Trees (a) Trees and graphs are non-linear data structures. (b) In a tree structure, each node may point to several other nodes, which in turn may point to several other nodes. (c) Forest is a set of several trees that are not linked to each other in any way. [A] State True or False: (a) A binary tree whose non-leaf nodes have left and right child is a complete binary tree. (b) The number of nodes attached to a particular node in a tree is called the degree of the node. (c) Trees and graphs are non-linear data structures. [B] Fill in the blanks: (a) is a set of several trees that are not linked to each other in any way. (b) The children of a node are called as.

Data Structures Through C Tree Traversal 87 Tree Traversal (a) The number of nodes connected to a particular node is called the degree of a particular node. (b) A complete binary tree of depth d is a strictly binary tree in which all the leaves of the tree are at the same level d. (c) The methods of binary tree traversal are in-order traversal, pre-order traversal and post-order traversal. [A] State True or False: (a) While traversing a non-empty binary tree in pre-order traversal, we first visit the root, then the right sub tree and lastly the left sub tree. (b) If every non-leaf node in a binary tree has non-empty left and right sub-trees, the tree is termed a strictly binary tree. [B] Fill in the blanks: (a) The methods of binary tree traversal are traversal, traversal and traversal. (b) The root of the tree has level. (c) The of a binary tree is the maximum level of any leaf in the tree. [C] Answer the Following: (a) Give the pre-order, post-order and in-order traversal steps of the following tree. (b) Write a program to represent a binary tree using an array.