Assignment 2
Assignment 2
Spring 2020
Assignment #2
Instructor: Mohammad Asad Abbasi
Assigned: 29 November, 2019
Deadline: 01 January, 2020, 4:30pm
Submission Instructions:
Any information outside the lecture notes and text book should be cited.
You shall submit solutions to the email address [email protected].
The subject line of email should include Data Structures assignment 2, student name, roll
number and section. Example (Data Structure assignment 2 (Fahad Ahmed, 113, A)).
Late submission will be penalized at 10% of total assignment marks per day.
Question # 1
int count = 0;
int N = a.length;
Arrays.sort(a);
Suppose that it takes 1 second when N= 3500. Approximately how long will it take when N =
35,000?
Question # 2
Write a program to create link list of integer type data and insert new element at first, last and
any intermediate position of the list.
Question # 3
Write a program to delete element at first, last and any intermediate position of the link list.
Question # 4
Suppose that p, q, and r are all references to nodes in a linked list with 15 nodes. The variable p
refers to the first node, q refers to the 8th node, and r refers to the last node. Write a few lines of
code that will make a new copy of the list. Your code should set THREE new variables called x,
y, and z so that: x refers to the first node of the copy, y refers to the 8th node of the copy, and z
refers to the last node of the copy.
Question # 5
Question # 6
Question # 7
Suppose each node of a STACK contains the following information, in addition to required
pointer field:
Give the structure of node for the linked stack in question. TOP is a pointer which points to the
topmost node of the STACK. Write the following functions.
ii) POP() - To remove a node from the stack and release the memory.
Question # 8
Question # 9
Question # 10
Give the necessary declaration of a linked list implemented queue containing float type values.
Also, write a user-defined function to delete a float type number from the queue.
Question # 11
Show how to implement a queue using two stacks. What is the worst-case runtime complexity of
the dequeue method?
Question # 12
Write an Insertion Sort algorithm for integer key values. However, the input is a stack (not an
array), and the only variables that your algorithm may use are a fixed number of integers and a
fixed number of stacks. The algorithm should return a stack containing the records in sorted
order (with the least value being at the top of the stack). Your algorithm should be Θ(n 2) in the
worst case.
Question # 13
Write a program that generates 20 random numbers and stores them in an array and sorts them
using the Bubblesort algorithm.
Question # 14
(a) Alphabetize the above list using an insertion sort. Show your work.
(b) Alphabetize the above list using a bubble sort. Show your work. How many complete
passes are necessary for the bubble sort to ensure the list is sorted?
(c) Alphabetize the above list using a selection sort. Show your work.