GithubHelp home page GithubHelp logo

mvishiu11 / ads Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 1007 KB

This repository contains the implementation of some algorithms and data structures in C++. It is meant as a future reference for me and a learning resource for others.

License: MIT License

C++ 93.86% Batchfile 6.14%

ads's Introduction

-----------------------------------------------------

➤ Algorithms and Data Structures

This repository contains the implementation of some algorithms and data structures in C++, I have done for my Algorithms and Data Structures 2023/24 course at the Warsaw University of Technology. It is meant as a future reference for me and a learning resource for others. The code is not meant to be used in production. It is not optimized and it does not handle all possible edge cases. The code is meant to be used for learning purposes only.

WARNING: The code is not commented and this README is not complete as of yet and partly auto-generated. For more accurate information about programs, please refer to the corresponding pdfs of the tasks, that are provided.

-----------------------------------------------------

➤ Table of Contents

-----------------------------------------------------

➤ Lab0

Task 1 - Longest Increasing Subsequence (LIS)

Description

The task is to find the longest increasing subsequence of a given sequence of numbers. The subsequence does not have to be continuous. The program should print the length of the longest increasing subsequence and the subsequence itself. If there are multiple solutions, the program should print the one that is lexicographically smallest. The program should be implemented in O(n^2) time complexity and O(n) space complexity. Full description can be found in the corresponding pdf.

Solution

The solution is based on dynamic programming. The program uses an array of size n to store the length of the longest increasing subsequence ending at the i-th element of the sequence. The program also uses an array of size n to store the index of the previous element of the longest increasing subsequence ending at the i-th element of the sequence. The program iterates over the sequence and for each element it iterates over all previous elements to find the longest increasing subsequence ending at the i-th element. The program also keeps track of the index of the longest increasing subsequence ending at the i-th element. After the iteration, the program finds the longest increasing subsequence by iterating over the array of the length of the longest increasing subsequence ending at the i-th element of the sequence and finding the longest one. Then the program prints the length of the longest increasing subsequence and the subsequence itself by iterating over the array of the index of the previous element of the longest increasing subsequence ending at the i-th element of the sequence and printing the elements in reverse order.

Complexity

The time complexity of the solution is O(n^2) because the program iterates over the sequence and for each element it iterates over all previous elements. The space complexity of the solution is O(n) because the program uses two arrays of size n.

Usage

The program takes the sequence as an input from the standard input. The first line of the input should contain the length of the sequence. The second line of the input should contain the sequence. The program prints the length of the longest increasing subsequence and the subsequence itself.

Example

Input:

10
1 2 3 4 5 6 7 8 9 10

Output:

10
1 2 3 4 5 6 7 8 9 10

Task 2 - Implementation of a ArrayStack data structure

Description

The task is to implement a ArrayStack data structure. The data structure should be implemented using an array. The data structure should support the following operations: push, pop, top, size, empty. Full description can be found in the corresponding pdf.

Solution

The solution is based on an array. The data structure uses an array to store the elements. The data structure also uses an integer to store the index of the top element of the stack. The data structure supports the following operations: push, pop, top, size, empty. The push operation inserts an element at the top of the stack. The pop operation removes the top element of the stack. The top operation returns the top element of the stack. The size operation returns the number of elements in the stack. The empty operation returns true if the stack is empty and false otherwise.

Complexity

The time complexity of the push, pop, top, size, empty operations is O(1) because the operations do not iterate over the elements of the stack. The space complexity of the data structure is O(n) because the data structure uses an array of size n.

Usage

The program takes the input from the standard input. The first line of the input should contain the number of operations. The following lines should contain the operations. The operations should be in the following format: push x, pop, top, size, empty. The program prints the results of the operations.

Example

Input:

10
push 1  
push 2
push 3
top
size
empty
pop
pop
pop
pop

Output:

3
3
0
3
2
1
0

ads's People

Contributors

mvishiu11 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.