This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import annotations | |
from typing import TypeVar | |
T = TypeVar("T") | |
def binary_search(l: list[T], item: T) -> int: | |
""" | |
Utilise the binary search algorithm to find the index where a particular element would be stored. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
]from __future__ import annotations | |
from typing import TypeVar | |
T = TypeVar("T") | |
def merge(l1: list[T], l2: list[T], key=lambda x: x) -> list[T]: | |
""" | |
Merges two sorted lists into one larger sorted list, | |
containing all elements from the smaller lists. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# linked list item | |
class Node: | |
def __init__(self, data): | |
self.data = data | |
self.next = None | |
def getData(self): | |
return self.data | |
def getNext(self): |