0% found this document useful (0 votes)
29 views2 pages

DSA - Lab 1

Uploaded by

ayesha batool
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 (0 votes)
29 views2 pages

DSA - Lab 1

Uploaded by

ayesha batool
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/ 2

DSA - Lab 1 and Homework 1

Question 1 - Create a class AutoGrowingArray with the following functionalities as follow:


AutoGrowingArray(); 10 points
// Initially the array should be of Size 0 and capacity 1, then increment every time by 1.

// AutoGrow Array by increasing the size by 1 at each insertion


T operator [](int index) const;
T& operator [](int index);
friend ostream& operator << (ostream& out,const AutoGrowArray & Other);
~AutoGrowingArray();
void PushBack(T Value);

Question 2: Create a class Vector with the following functionalities as follow:


Vector(); 15 points void PushBack(T Value);
// // Initially the array should be of Size 0 and Capacity 1 and then increment every time by 1 and if the capacity is full i.e.
Size==Capacity it should resize by the factor of 2. This is the same implementation which is given in STL library called
#include <vector> in C++
T operator [](int index)const;
T& operator [](int index);
friend ostream& operator << (ostream& out,const Vector & Other);
~Vector();

Question 3: Create a class ArrayList with the following functionalities as


follow: 5 points

ArrayList();
void PushBack(T Value);
// // Initially the array should be of Size 0 and Capacity 2 and then increment Size every time by 1 and if the capacity is full
i.e. Size==Capacity it should resize by the factor of 1.5. This is the same implementation which is given in Java generics
library called Arraylist.

T operator [](int index)const;


T& operator [](int index);
friend ostream& operator << (ostream& out,const ArrayList & Other);
~ArrayList();
EXPERIMENT
20 points

Using this function creates a 2 MB file. And Use the above three implementations and load both the files (please NEVER output
the loaded data onto the screen as it will be two many characters, and console Write them down in another output file with
the following names “OutputGA.txt”, “OutputVector.txt”. “OutputArraylist.txt”, and measure the time taken in seconds for
each experiment using time(0) function.

This experiment must be done and screenshots should be attached in the submission.

LeetCode Questions related to vector arrays


Solve the following problems on leetcode. Each question carries 10 points.

1. https://leetcode.com/problems/how-many-numbers-are-smaller-than-the-current-number/
2. https://leetcode.com/problems/remove-element/
3. https://leetcode.com/problems/search-a-2d-matrix/
4. https://leetcode.com/problems/remove-duplicates-from-sorted-array/
5. https://leetcode.com/problems/maximum-subarray/
6. https://leetcode.com/problems/first-bad-version/
7. https://leetcode.com/problems/first-missing-positive/description/

You might also like