0% found this document useful (1 vote)
139 views3 pages

DS Assignment1

This document provides instructions for an assignment on data structures and algorithms. It reminds students to do their own original work. It includes 3 parts: 1) Asymptotic notation questions proving big-O estimates for various functions. 2) Implementing array utility methods like finding maximum/minimum values and swapping elements. 3) Implementing linked list and node classes with methods like adding/removing nodes, checking size, and duplicating in reverse order. Students are instructed to submit zipped solution files by the given due date.

Uploaded by

Loyalty
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
139 views3 pages

DS Assignment1

This document provides instructions for an assignment on data structures and algorithms. It reminds students to do their own original work. It includes 3 parts: 1) Asymptotic notation questions proving big-O estimates for various functions. 2) Implementing array utility methods like finding maximum/minimum values and swapping elements. 3) Implementing linked list and node classes with methods like adding/removing nodes, checking size, and duplicating in reverse order. Students are instructed to submit zipped solution files by the given due date.

Uploaded by

Loyalty
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Reminder: Own your work

CPS 212: Data Structures & Algorithms

Assignment 1
Due Date: 2nd November, 2019

Instructions: Please answer all questions. All files to be submitted should be


zipped and send to sangolfred@gmail.com. The zip file name should be your
FullName and MatNo.

Answer all questions. Each Part carries 20 marks.

Part 1 (Asymptotic Notation)


Below you find a list of functions that could appear as functions describing the running
time of algorithms:

a. Prove the following 5x4 − 37x3 + 13x − 4 = O(x4 ). You must find the c and n0.
b. Give a big-O estimate for each of these functions and prove your answer.
(i) 3n + n3 + 4
(ii) 1 + 2 + 3 + · · · + n + 3n2

Note: For Part 1 send me a scan copy of solution done on paper

Part 2 (Arrays)
Implement in Java the class ArrayUtility, which offers basic operations over one-
dimensional and two-dimensional arrays. All methods must be implemented as class
methods (i.e., static methods). The signature of the methods in the ArrayUtility class are
the following:

1. public static int findMax(int[] A, int i, int j): returns the maximum value occurring in
the array A between position i and j.

2. public static int findMaxPos(int[] A, int i, int j): returns the position of the maximum
value in the array A between position i and j.

3. public static int findMin(int[] A, int i, int j): returns the minimum value in the array A
between position i and j.

4. public static int findMinPos(int[] A, int i, int j): return the position of the minimum
value in the array A between position i and j.

1
Reminder: Own your work

5. public static void swap(int[] A, int i, int j): swaps the elements in position i and j in the
array A.

6. Object[] concatenate(Object[] a, Object[] b)


returns an array containing all of a[] followed by all of b[]

7. double innerProduct(double[] x, double[] y)


// returns the algebraic inner product (the sum of the component wise products) of the two
given arrays as (algebraic) vectors

8. double[][] outerProduct(double[] x, double[] y)


// returns the algebraic outer product of the two given arrays as (algebraic)
vectors: p[i][j] = a[i]*b[j]

Part 3 (LinkedList)
Implement the Link (Node) and Linkedlist class with the following method
implementations:

NB: Your LinkedList class should implement the List interface (available in java
library)

LinkedList:
public LinkedList(){
head = new Node(null); //head is the same as first
size = 0;

Methods:
a. public boolean isEmpty();

// returns true if the list is empty, false otherwise

b. public int size();

// returns the number of items in the list

2
Reminder: Own your work

c. public void add(Object item);

// adds an item to the list


// precondition: none
// postcondition: item is added at the end of the list

d. public void add(int index, Object item);

// adds an item to the list at the given index


// precondition: none
// postcondition: item is added at the given index;
// the indices of following items are increased by 1.

e. public void remove(int index);

// removes the item from the list that has the given index
// precondition: none
// postcondition: removes the first item in the list whose equal method
// matches that of the given item

f. public List duplicateReversed();

// creates a duplicate of the list with the nodes in reverse order


// precondition: none
// postcondition: returns a copy of the linked list with the nodes in
// reverse order

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy