CS141
https://www.seu.edu.sa/sites/ar/SitePages/images/logo.png
College of Computing and Informatics
Question One
Learning Outcome(s):
LO4: Demonstrate dynamic data structures such us linked lists, stacks and queues, and binary trees.
1 Marks
Show all the steps of the following data set when it being sorted with Insertion sort algorithm and calculate the performance of it.
Then, show all the steps of finding the element 7 using the Binary search.
7
13
9
2
11
22
Question Two
Learning Outcome(s):
LO4: Demonstrate dynamic data structures such us linked lists, stacks and queues, and binary trees.
1.5 Marks
Write a java program to obtain the following statements:
1. Create a linkedlist named “fruit” with these elements: “orange”, “apple” “banana”, and “pear”.
2. Add new element “grape” after the element “apple”.
3. Display all element of the list.
Note: Please use the in-built Java library class”LinkedList” and interface“ListIterator”
Question Three
Learning Outcome(s):
Design and implement programs using object oriented programming concepts such as encapsulation, inheritance, polymorphism, abstract classes and methods.
1 Marks
Given the class Node below. We have a linked list with head node “A”. Write the code to remove the node “C” in the following linked list.
public class Node {
public String element;
public Node next;
}
head
Node
next: null
element: D
Node
Node
Node
next:
element: C
element: B
next:
next:
element: A
Question Four
1.5 Marks
Learning Outcome(s):
Demonstrate dynamic data structures such us linked lists, stacks and queues, and binary trees.
The selection sort algorithm is a simple sorting algorithm based on the idea of finding the minimum in an unsorted array and then putting it in its correct position in an ascending order. It starts by searching for the minimum element in the array and then swapped with the element that is currently located at the first position. A temporary variable is used to do the swap.
A. Write a java class called SelectionSortNoTemp that sorts an array using selection sort. Do not use a temporary variable when you swap two elements.
B. Modify your answer in ‘A’ to sort the array in descending order.