Higher National Diploma in Information Technology. First Year Second Semester Examination IT 2003-Data Structure and Algorithm.

Similar documents
I g) I!~!Y.tTE OF ADVANcrD TECHNOLOGICAL EDUCATION (Establil t>&d In tha Ministry of Higher Education, vida In Act No. 29 of 1995)

Revision Statement while return growth rate asymptotic notation complexity Compare algorithms Linear search Binary search Preconditions: sorted,

CS 216 Exam 1 Fall SOLUTION

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

CS301 - Data Structures Glossary By

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

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

Linked Lists. Linked list: a collection of items (nodes) containing two components: Data Address (link) of the next node in the list

Linked Lists. Linked list: a collection of items (nodes) containing two components: Data Address (link) of the next node in the list

Ch. 17: Linked Lists. Introduction to Linked Lists

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

! Determine if a number is odd or even. ! Determine if a number/character is in a range. - 1 to 10 (inclusive) - between a and z (inclusive)

1 Short Answer (7 Points Each)


MIDTERM EXAMINATION Spring 2010 CS301- Data Structures

CSE 332 Autumn 2013: Midterm Exam (closed book, closed notes, no calculators)

Chapter4: Data Structures. Data: It is a collection of raw facts that has implicit meaning.

Chapter 20: Binary Trees

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

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

Section I B COMPUTER SCIENCE SOLUTION

l Determine if a number is odd or even l Determine if a number/character is in a range - 1 to 10 (inclusive) - between a and z (inclusive)

DATA STRUCTURES AND ALGORITHMS

12 Abstract Data Types

CSCE 2014 Final Exam Spring Version A

8. Binary Search Tree

Lecture 2 Arrays, Searching and Sorting (Arrays, multi-dimensional Arrays)

4.1 COMPUTATIONAL THINKING AND PROBLEM-SOLVING

Frequently asked Data Structures Interview Questions

CSE 373 Spring 2010: Midterm #1 (closed book, closed notes, NO calculators allowed)

! Determine if a number is odd or even. ! Determine if a number/character is in a range. - 1 to 10 (inclusive) - between a and z (inclusive)

Department of Computer Science and Technology

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

CS-301 Data Structure. Tariq Hanif

MLR Institute of Technology

Introduction to Computer Science Midterm 3 Fall, Points

9. Heap : Priority Queue

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

MAHARASHTRASTATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified)

COMP Data Structures

Data Abstractions. National Chiao Tung University Chun-Jen Tsai 05/23/2012

1. Write step by step code to delete element from existing Doubly Linked List. Suppose that all declarations are done

! A data structure representing a list. ! A series of nodes chained together in sequence. ! A separate pointer (the head) points to the first

! Determine if a number is odd or even. ! Determine if a number/character is in a range. ! Assign a category based on ranges (wind speed)

Object Oriented Programming COP3330 / CGS5409

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

CSE 373 Autumn 2010: Midterm #1 (closed book, closed notes, NO calculators allowed)

Tables, Priority Queues, Heaps

Summer Final Exam Review Session August 5, 2009

Chapter 17: Linked Lists

DHANALAKSHMI COLLEGE OF ENGINEERING Tambaram, Chennai DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING

Types of Data Structures

CS 8391 DATA STRUCTURES

CP2 Revision. theme: dynamic datatypes & data structures

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

Searching, Sorting. Arizona State University 1

Part I: Short Answer (12 questions, 65 points total)

ECE250: Algorithms and Data Structures Midterm Review

Dynamic Data Structures. John Ross Wallrabenstein

double d0, d1, d2, d3; double * dp = new double[4]; double da[4];

Arrays. Week 4. Assylbek Jumagaliyev

! A data structure representing a list. ! A series of dynamically allocated nodes. ! A separate pointer (the head) points to the first

Chapter 17: Linked Lists

INSTITUTE OF AERONAUTICAL ENGINEERING

Dynamic Data Structures

Arrays and Linked Lists

AE52/AC52/AT52 C & Data Structures JUNE 2014

Programming II (CS300)

Introduction to Data Structures and Algorithms

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

calling a function - function-name(argument list); y = square ( z ); include parentheses even if parameter list is empty!

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

CSE 332 Spring 2013: Midterm Exam (closed book, closed notes, no calculators)

DELHI PUBLIC SCHOOL TAPI

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

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

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

Objective Questions for Online Practical Exams under CBCS Scheme Subject: Data Structure-I (CS-113)

CS Sorting Terms & Definitions. Comparing Sorting Algorithms. Bubble Sort. Bubble Sort: Graphical Trace

Data Structures Question Bank Multiple Choice

Q1 Q2 Q3 Q4 Q5 Q6 Total

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

// array initialization. void main() { cout<<b[4]<<endl; cout<<b[5]<<endl; } Output is 9

Abstract Data Type: Stack

Linked List. April 2, 2007 Programming and Data Structure 1

CS8391-DATA STRUCTURES QUESTION BANK UNIT I

CS 270 Algorithms. Oliver Kullmann. Binary search. Lists. Background: Pointers. Trees. Implementing rooted trees. Tutorial

DEEPIKA KAMBOJ UNIT 2. What is Stack?

CSE 332 Winter 2015: Midterm Exam (closed book, closed notes, no calculators)

CS 2412 Data Structures. Chapter 10 Sorting and Searching

2016 Spring COP 3502 Final Exam. Date: 4/28/2016. Name:

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

Name: I. 20 II. 20 III. 20 IV. 40. CMSC 341 Section 01 Fall 2016 Data Structures Exam 1. Instructions: 1. This is a closed-book, closed-notes exam.

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

Operations on Heap Tree The major operations required to be performed on a heap tree are Insertion, Deletion, and Merging.

BEng (Hons) Telecommunications. Examinations for 2016 / Semester 2

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?


Transcription:

Higher National Diploma in Information Technology First Year Second Semester Examination-2013 IT 2003-Data Structure and Algorithm Answer Guide (01) I)What is Data structure A data structure is an arrangement of data in a computer's memory or even disk storage. II)a)What are the differences between linear and nonlinear data structures Linear Linear data structures organize their data elements in a linear fashion, where data elements are attached one after the other. Linear data structures are very easy to implement, since the memory of the computer is also organized in a linear fashion Non Linear data elements are not organized in a sequential fashion. Difficult to implement when comparing linear method (02x2= 04marks) b)give suitable two(2) examples for each of the data structuring methods Linear Eg. Array,Linked List,Stack,Queue Non Linear multidimensional arrays, trees and graphs III)Without data structures methods also we can implement the programs. Then, what are the advantages of using data structures methods Data structures organize data more efficient programs. More complex applications demand more calculations. (02x3=06 marks) IV)a)What is an abstract data type An abstract data type is a mathematical set of data, along with operations defined on that kind of data (03marks) b)give two examples for abstract data type

int: it is the set of integers (up to a certain magnitude), with operations +, -, /, *, % double: it s the set of decimal numbers (up to a certain magnitude), with operations +, -, /, * (01x2=02 marks) (02) I)What are the advantages and disadvantages of an array data structure method advantages Quick insert Disadvantages Slow search, Slow delete, fixed size (02x2=04 marks) II)Write down the program to store vowels in an array and printing them Method1 #include<iostream.h> #include<conio.h> int main() char vowels [5]; vowels[0] = 'a' ; vowels[1] = 'e' ; vowels[2] = 'i' ; vowels[3] = 'o' ; vowels[4] = 'u' ; cout<<"element 0 = "<<vowels[0]<<endl; cout<<"element 1 = "<<vowels[1]<<endl; cout<<"element 2 = "<<vowels[2]<<endl; cout<<"element 3 = "<<vowels[3]<<endl; cout<<"element 4 = "<<vowels[4]<<endl; return 0; Method2 #include<iostream.h> #include<conio.h> int main() char vowels[5] = 'a','e','i','o','u' ;

for (int i=0; i<=4; i++) cout<<"element "<< i<<" = " <<vowels[i]<<endl; return 0; (For any of the method 06 marks) III)Write down the algorithm to deleting element from an array Firstly,you find the element that you want to delete and find the index. So, just set the value of that cell to 0 (or NULL). If you mean to get rid of that element, you'd need to shift all the ones to the right of that element one to the left: (04 marks) IV)a)What is a multi dimensional array Multidimensional arrays can be described as "arrays of arrays". For example, a bidimensional array can be imagined as a bidimensional table made of elements, all of them of a same uniform data type. b)how do you insert the following data to a two dimension array(write down the program code) 5 3 2 8 4 1 int twodmatrix [ 2][ 3]; int twodmatrix [2 ][3 ] = 5,3,2,8,4,1 ; (04 marks) (03 ) I)What is a Linked list A linked list consists of nodes of data which are connected with each other. Every node consist of two parts data and the link to other nodes. The nodes are created dynamically. (04 marks) II)Draw the structural diagrams for the following tasks. a)initialize the list

b)insert a new element into an empty list c)insert Second element d)insert Rear e)delete an element

III)What are the advantages of Linked list Quick insert Quick delete Memory not waste IV)What are the output of the following code segments #include <iostream.h> #include "FloatList.h class FloatList private: // Declare a structure for the list struct ListNode float value; struct ListNode *next; ; ListNode *head; // List head pointer public: FloatList(void) // Constructor head = NULL; ~FloatList(void); // Destructor void appendnode(float); void displaylist(void); ; void FloatList::appendNode(float num) ListNode *newnode, *nodeptr; // Allocate a new node & store num newnode = new ListNode; newnode->value = num; newnode->next = NULL; // If there are no nodes in the list // make newnode the first node if (!head) head = newnode; else // Otherwise, insert newnode at end // Initialize nodeptr to head of list

nodeptr = head; // Find the last node in the list while (nodeptr->next!=null) nodeptr = nodeptr->next; // Insert newnode as the last node nodeptr->next = newnode; void FloatList::displayList(void) ListNode *nodeptr; nodeptr = head; while (nodeptr) cout << nodeptr->value << endl; nodeptr = nodeptr->next; void main(void) FloatList list; // Build the list list.appendnode(2.5); list.appendnode(7.9); list.appendnode(12.6); list.displaylist( ); Output 2.5 7.9 12.6 (04) I) There are two ways for implement a stack. What are them

Array (Static) based and linked list (dynamic) based. II)Illustrate the diagrammatical representations for the following operations of a stack a)empty stack b)push(a) c) Push(b) already (a) value in a stack d)pop() already (a) value and (b) value in a stack II)Implement the stack algorithm for the following functions in a stack a)push(item) Push(item) If (stack is full) print stack over flow else Increment top ; Stack [top]= item;

b)pop( ) Pop() If( stack is empty) print stack under flow else Decrement top c)display( ) Display() If ( stack is empty) print no element to display else for i= top to 0 step -1 Print satck[i]; (05) I) Describe the FIFO and LIFO with examples FIFO is First in First Out method. Eg:-Queue LIFO is Last in First Out method. Eg:-Stack II)Write down the definition of Queue A queue is an ordered collection of items from which items may be deleted at one end ( called front of the queue) and into which items may be inserted at the other end (called the rear of the queue) III)Draw the array implementations of the queue for the following tasks. a)enqueue(a) b)enqueue(b) already (A) enqueued

c)dequeue() already (A) and (B) in the queue d)dequeue() (01x4=04 marks) IV)Write down the program code for the following functions in the queue a) Insert item to a queue void insert(int x) if(rear > 4) cout <<"queue over flow"; rear=-1; return; queue[++rear]=x; cout <<"inserted" <<x; b) Delete an item from a queue void delet() if(front==rear)

cout <<"queue under flow"; return; cout <<"deleted" <<queue[++front]; c) Display items in a queue void display() if(rear==front) cout <<" queue empty"; return; for(int i=front+1;i<=rear;i++) cout <<queue[i]<<" "; (06) I) List down different types of trees Binary tree General tree Binary search trees AVL trees (any 3 give 03 marks) II)Define the following terms related to the tree with a example

a)degree of a tree:- The number of sub tree of a node is called its degree. Degree=3 b)height of a tree:- The maximum depth of a leaf node. Height=3 c)path of a tree :-Connection of edges connecting two nodes Path from A H =AD,DH (02x3=06 marks) III)Write down the definition for the binary tree and draw the complete binary tree and mark the left sub tree and right sub tree A binary tree is a finite set of nodes that is either empty or consists of a root and two disjoint binary trees called the left subtree and the right subtree.

(05 marks) IV)a)What is a binary search tree Binay search tree is a binary tree with following property. All the nodes having less values than the root are in the left side,and the Nodes having larger values than the root are in the right side b)insert the following data set into a binary search tree 25,6,21,18,17,5,3,18,25,6,18,17,5,7,9 (04 marks) (07) I)What is meant by sorting Arranging things into ascending or descending order is called sorting. i.e. Sorting is the process of arranging items in order. II)a)Describe selection sort method and sort the following unordered data set using

selection sort method 15,6,10,5,3,8 In terms of an array A, the selection sort finds the smallest element in the array and exchanges it with A[0]. Then, ignoring A[0], the sort finds the next smallest and swaps it with A[1] and so on. b)write down the swap method(function)regarding to the selection sort private void swap(int one, int two) long temp = a[one]; a[one] = a[two]; a[two] = temp; III)a)Write down the algorithm for Bubble Sort Beginning at the last element in the list Compare each element with the previous element in the list. If an element is less than its predecessor, swap these two element. To completely sort the list, you need to perform this this process n-1 times on a list of length n b)following list consist of the original unsorted data elements. Sort these data set using bubble sort method. 44,55,12,42,94,18,06,67 Original -> 44,55,12,42,94,18,06,67 Pass 1 -> 06,44,55,12,42,94,18,67 Pass 2 -> 06,12,44,55,18,42,94,67 Pass 3 -> 06,12,18,44,55,42,67,94

Pass 4 -> 06,12,18,42,44,55,67,94 Pass 5 -> 06,12,18,42,44,55,67,94 Pass 6 -> 06,12,18,42,44,55,67,94 Pass 7 -> 06,12,18,42,44,55,67,94 Sorted file->06,12,18,42,44,55,67,94 IV)a)What is meant by Big-Oh notation Provides an upper bound for the function f b)write down the order for following functions 7n-2 7n-2 is O(n) 3n 3 +20n 2 +5 3n 3 + 20n 2 + 5 is O(n 3 ) (04 marks) (08) I)Define the terms Best, Worst and Average cases Best case: Find at first position. Cost is 1 compare. Worst case: Find at last position. Cost is n compares. Average case: (n+1)/2 compares IF we assume the element with value K is equally likely to be in any position in the array. (02x3=06 marks) II )Write down the algorithm for Binary Search The elements of the list must be arranged in ascending (or descending) order. The target value is always compared with the middle element of the remaining search range. We must have random access to the elements of the list (an array or ArrayList are OK). (04 marks) III)a)What is a sequential search Examines each element of a list in sequence until it finds the target value or reaches the end of the list. b)find the efficiency of a sequential search in Best case, Worst case and average case Best case O(1) Locate desired item first Worst case O(n) Must look at all the items Average case O(n)

Must look at half the items O(n/2) is still O(n) (02x3=06 marks) IV)If you have two algorithm called A and B,find the faster algorithm TA (N)=1000N TB(N)=N 2 Running Times of Algorithm A and B TA(N) = 1000 N = O(N) TB(N) = N 2 = O(N 2 ) A is asymptotically faster than B!