Coder Social home page Coder Social logo

vasipeycheva / data-structures-and-algorithms--2018-2019 Goto Github PK

View Code? Open in Web Editor NEW
9.0 9.0 1.0 14.1 MB

Lections and code from Data Structures and Algorithms course 2018-2019: VIP edition (the course is held by Vasilena, Ivan, Plamen)

C++ 93.31% C 6.69%

data-structures-and-algorithms--2018-2019's People

Contributors

hribo98 avatar ivanfilipov avatar pminev avatar vasipeycheva avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

alexherself

data-structures-and-algorithms--2018-2019's Issues

Returning 0 instead of throwing an exception

On line 130 of the file dynamicarrayfunctions.h in Practice_07--Sorting-Algorithms/, when you are given an invalid index you are returning 0. However, the return type of this method is const TYPE &. This can be a problem whenever the template class is used with something different from ints. The way to solve this issue is to simply throw an exception, just like you have done on line 139, for the same case.

Moreover, in the same method, when it is called with an appropriate index, you are returning arr[index]. The problem here is that there is no member of the class named arr. What you meant to write is probably return data[index], similar to the method below.

Calling the Same Method in a for-loop

In the file DynamicArrayAlgorithms.h on lines 26 and 30 you are calling a method, respectively First.getSize() and Second.getSize(), every time you iterate over the elements of the arrays. This is from the function merge().

Same goes for the next function, includes(). On line 44 you are calling the method Second.getSize() on every iteration of the loop.

The same problem exists on line 67 in the function filter().

All of this can be made faster by creating a new variable which will be assigned with the size you need. This way, you will be calling the method once, instead of numerous times.

SubNodes counting without using a bool variable

bool insert(node *& root, int data)
{

if (data == root->data)
	return false;

if (data < root->data)
{
	if (!root->left)
	{
		root->left = new node(data);
		root->subNodes++;
		return true;
	}

	if (insert(root->left, data))
	{
		root->subNodes++;
		return true;
	}
}
else
{

	if (!root->right)
	{
		root->right = new node(data);
		root->subNodes++;
		return true;
	}

	if (insert(root->right, data))
	{
		root->subNodes++;
		return true;
	}


}

return false;

}

An Additional if-statement

On the following line of code:

in the function insert_helper, the compiler will go over an additional if-statement.

The problem is that if element is greater than root->key, the code in the previous else-if statement will be executed. In other words, we shouldn't make the compiler check if element is smaller than root->key.

This can be fixed by turning the if-statement into an else-if statement.

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.