المملكة العربية السعودية وزارة التعليم العالي جامعة المجمعــة كلية العلوم بالزلفي Kingdom of Saudi Arabia Ministry of Higher Education Majmaah University Collage of Science at Al-Zulfi Final Exam First Semester 1435-1436H Course Name: Data-structures - Course Code: CSI312 - Section Number: 1 Time Allowed:120 minutes ) )برنامج تجسير حاسب آلي Date:-- / --/ 1436 H -- / -- / 2014 G. Number of Pages: 9 pages Student's Name:...................................................................................................... Student's ID: ............................................................................................................ Instruction: 1. Write your name and your academic identification number fully and clearly. 2. Use blue or black pen to answer, pencils only for drawing. 3. Books and notes are not allowed. 4. Students are not allowed to leave before the lapse of 30 minutes from the beginning of the exam. Learning Outcomes Knowledge 1.1 1.2 1.3 Cognitive Skills 1.4 2.1 2.2 2.3 Question Outcome covered I ………………..…………. II …………………..………. III …………………..………. IV …………………..………. V …………………..………. 2.4 Interpersonal Skills 3.1 3.2 Correction 3.3 3.4 Communication, Information Technology, Numerical 4.1 Verification Total 4.2 4.3 Faculty Member Psychomotor 5.1 5.2 Course coordinator Dr. Wael Khedr Revision Committee Name Final Mark : Signature / 40 Marks:…………………………………………………………………………… 2 نموذج 1 الصفحة 5.3 Question(1) : Multiple Choice Questions------------------------------------(10 marks) 1. Linked lists are best suited: 2. 3. 4. 5. 6. 7. a) For relatively permanent collections of data b) For when the size of the data structure is constantly changing c) For both of the above situation d) For none of the above situation Which of the following data structures are indexed structures? a) linear arrays b) linked lists c) both of above d) none of above The term "push" and "pop" is related to the ------------------a) Array b) Lists c) Stacks d) all of above A data structure where elements can be added or removed at either end but not in the middle a) Linked lists b) Stacks c) Queues d) Dequeue Which of the following data structure is not linear data structure? a) Arrays b) Linked lists c) Both of above d) None of above Stack data structure is also referred to as a _____ structure a) FIF0 b) LIFO c) NOFO d) FIFI Which is/are the application(s) of stack a) Function calls b) Large number Arithmetic c) Evaluation of arithmetic expressions d) All of the above 8. I/O buffers are good examples of constructs that use a ______. a) b) c) d) Stack Linked List Array Queue 2 الصفحة 9. ________ is a special type of Queue. a) Dequeue b) No queue c) Linked list d) Stack 10. Linked list is a _________ data-structure and Array is a __________ datastructure. a) Big, small b) Dynamic, static c) Right, wrong d) Easy, difficult 11. What will the following program print? int A[] = {1,2,3}; int* B = &A[0]; cout << ( A[2] > B[1] ? "Big" : "Small" ) ; a) Big b) Small c) Big Small d) Small Big 12. If the sequence of operations- Push(2), Push(3), Pop, Push(4), Push(5), Pop, Pop, Pop , Push(6), Pop are performed on a stack, the sequence of popped out values are? a) b) c) d) 5 , 4, 3, 2 2, 3 , 4, 5, 6 6, 5, 4, 6, 2 3 , 5 , 4, 2, 6 13. For a non-empty linked list, select the code that should appear in a function that adds a node to the end of the list. newNode is a pointer to the new node to be added and nodePtr is a pointer to the current last node. Each node contains a pointer next. a) nodePtr.next = newNode; nodePtr = newNode; b) nodePtr = newNode; nodePtr ->next = newNode; c) newPtr->next = NodePtr; class xxxxx nodePtr = newNode; { d) nodePtr->next = newNode; private: nodePtr = newNode; struct Node 14. The following statement represent the { int Value; describe data structure of a) b) c) d) Stack Single Linked list Double Linked list Static Queue Node *Next; Node* Last; }; Node *Ahead; }; 3 الصفحة 15. Allocate an array Y of real Scores with size n at memory can be done by a) b) c) d) Y= a new float[n]; Y= new float[n]; Y= new real [n]; int *y[n]; 16. To Release a block of data Y from the memory you must use keyword a) b) c) d) break Y[ ] ; new Y[ ] ; delete Y[ ] ; protected Y[ ] ; 17. To push number num onto the stack stackArray, you must use a ---- a) b) c) d) stackArray[++top] = num; num= stackArray[++top]; stackArray[top] = num; num=stackArray[top++]; 18. To inserts the value num at the rear of the dynamic queue--- a) b) c) d) rear->next = newNode; rear = newNode; top->next = newNode; top = newNode; rear = newNode; rear->next = newNode; top = newNode; top->next = newNode 19. To delete a node from a linked list requires------------------ a) b) c) d) previousNode = nodePtr->next; delete nodePtr; nodePtr= previousNode->next; delete nodePtr; previousNode->next = nodePtr->next; delete nodePtr; nodePtr->next= previousNode->next; delete nodePtr; 20. Insert the sequence { 100, 25, 30, 40, 50, 10} into linked list figure. A 4 الصفحة ANSWER ONLY THREE QUESTIONS FROM THE FOLLOWING: Question(2) : ( 10 Marks) State five functions that may be used to implement a static integer Queue. Also write definition of each function by using a flowchart or pseudo code C++. 5 الصفحة الصفحة 6 Question(3) : ( 10 Marks) Suppose you are asked to create a software for a filing system. The filing system is to be implemented in the order of the Last File in is the First File out. The filing system will contain main components as { Document ,Small File , and Large File}. a. What data-structure you would use to store the files and what advantage would the data-structure provide? (3 marks) b. Create a class (Abstract Data Type) for each component {Document , Small File , and Large File} with appropriate variables and operations. (at least 3 variables and 3 functions each) (7 marks) 7 الصفحة Question(4) : ( 10 Marks) Let Pseudo-code C++ of class Arrays , Please complete the definition all public functions below? class Arrays { private: int* arrayList; // pointer to array of a user defined size int sizeOfArray; // size of the array public: Arrays (int num); // constructor ~ Arrays ( ); // destructor void setValues( ); // Set values from user into the array void Insert( int num ); // to insert number into ordered list array void Sort(int& a[ ], int n); //to sort all elements of array by ascending order }; 8 الصفحة Question(5) : ( 10 Marks) A. Fill the binary search tree that results from inserting the integers { 57, 85, 35, 9, 47, 20, 26,99, 93, 10}starting with Root =57 and ending with 10. B. Write basis code C++ definition of binary tree node? C. What is the preorder traversal of your tree ? D. What is the postorder traversal of your tree? E. Redraw the above binary search tree after delete root node 57? 9 الصفحة