Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Philadelphia University Faculty of Information Technology Lecturer : Dr. Ali Fouad, Mr. Abdalrahman Obidat Coordinator : Dr. Ali Fouad Examination Paper Department of Software Engineering Internal Examiner : Dr. Maouche Mourad Object Oriented Data Structures (721211) Section: 1 Date: 22- 11- 2015 First Exam First Semester of 2015-2016 Time: 50 minutes Information for Candidates 1.This examination paper contains four questions, totaling 20 marks. 2.The marks for parts of questions are shown in round brackets. Advice to Candidates 1. You should attempt all questions. 2. You should write your answers clearly. I. Basic concepts Objective: The aim of the question in this part is to evaluate your knowledge and skills concerning with the basic concepts of array list and linked list data structures. Question1 (6 marks) Choose best Data structure (stack, unordered list, ordered list, queue, tree, binary tree, binary search tree, heap, hash table, graph, complete graph, directed graph) that fits each of the following descriptions: A) If the following elements are inserted to the data structure in this order (15, 20, 77, 60 and 40) these elements should be removed in the following order (15, 20, 77, 60 and 40) knowing that it is a linear data structure. Queue B) If the following elements are inserted to the data structure in this order (15, 20, 77, 60 and 40) these elements should be removed in the following order (40, 60, 77, 20 and 15) knowing that it is a linear data structure. Stack C) If the following elements are inserted to the data structure in this order (15, 20, 77, 60 and 40) these elements should be stored in the data structure in the following order (15, 20, 40, 60 and 77) knowing that it is a linear data structure. Ordered list D) If the following elements are inserted to the data structure in this order (15, 20, 77, 60 and 40) these elements should be stored in the data structure in the following order (15, 20, 77, 60 and 40) and you can choose an item to delete knowing that it is a linear data structure. Unordered list E) Binary tree where each node has value greater than the value of any node in its left sub tree and less than the value of any node in its right sub tree. BST F) Set of nodes and edges where each node is connected directly to all other nodes. Complete Graph II. Familiar Problem Solving Objective: The aim of the question in this part is to evaluate your knowledge to solve familiar problems in unsorted array list and sorted array list data structures. Question 2: (4 marks) Use List data structure class to write segment of code to create an empty list “list2” then use it to insert all numbers in “list1” with value > 10. List <integer> list2= new List<Integer>(); 1.5 mark Integer x = list.first(); While (x!=null){ 0.5 mark 1.5 mark If (x>10) List2.add(x); x = list.next(); 0.5 mark 0.5 mark 0.5 mark } Question3 (6 marks) Consider the following linked list L, where each node has a integer data part and reference variable next, P and F is also references. P F Write segment of code to do each of the following: A) Delete first node. L=L.next; 1 mark B) Delete node with data= 60. p.next=p.next.next; 1 mark C) Create new node with data = 15 then insert it as first node in the linked list. Node<Integer> n= new Node<Integer>(60,null); n.next = L; L=n; 0.5 mark 0.5 mark 0.5 mark D) Create new node with data = 65 then insert it between the node with data = 80 and node with data= 70. Node<Integer> n= new Node<Integer>(65 ,null); p.next = f.next; f.next=n; 0.5 mark 0.5 mark 0.5 mark III. Unfamiliar Problem Solving Objective: The aim of the questioning this part is to evaluate that student can solve familiar problems with ease and can make progress toward the solution of unfamiliar problems, and can set out reasoning and explanation in clear and coherent manner. Question4 (4 marks) Assume you have the following Node class for a List: class Node{ int data; Node next; Node(int data, Node next){ this.data = data; this.next = next; } } Write a method to create a new singly-linked list that is a copy of a sublist of an existing list which contains the nodes occupying positions low up through and including high of the list pointed to by head The prototype method is: Node Sublist(Node head, int low, int high) Answer: Node p=head; Node nhead; for (int i = 1; i<low; i++) p=p.next; if (low<=high) { nhead= new Node(p.data, null); f=head; p=p.next } for (int i = low ;i<high; i++) { f.next= new Node(p.data, null); f=f.next; p=p.next; } return nhead 1 mark 1.5 mark 1.5 mark