mightypy.data_structures package#

Module contents#

mightypy.dsa#

class BST[source]#

Bases: object

insert(val)[source]#
traverse(order='level')[source]#
class BinaryTree[source]#

Bases: object

property height#
insert(val)[source]#

Level order insertion.

https://en.wikipedia.org/wiki/Breadth-first_search

Parameters:

val (Any) – value of the node in tree.

invert()[source]#
traverse(order='in', method='stack')[source]#

Tree traversal operation

Parameters:

order (str, optional) – order in which the tree will be traversed. Defaults to “in”. Options available - “level”,”in”,”pre”,”post”

Raises:

ValueError – If wrong order is passed. only “level”,”in”,”pre”,”post” is allowed

Returns:

Values of tree nodes in specified order

Return type:

values (list)

class LinkedList[source]#

Bases: object

append(value)[source]#

Insert at the end.

Parameters:

value (object) – Value to insert in linked list

push(value)[source]#

Push at the begining.

Parameters:

value (object) – Value to push to list

traverse()[source]#

Traverse the linked list.

Returns:

linked list values

Return type:

node_values (list)

Binary search algorithm

Parameters:
  • arr (List[Union[int,float,str]]) – array list to search

  • ele (Union[int, float, str]) – element to search

Returns:

result of bianry search

Return type:

Union[Tuple[bool, int], Tuple[bool, None]]

Linear search algorithm

Parameters:
  • arr (List[Union[int,float,str]]) – array list to search

  • ele (Union[int, float, str]) – element to search

Returns:

result of linear search

Return type:

Union[Tuple[bool, int], Tuple[bool, None]]