data-structures

Is it possible to have a tuple contain only one tuple without the comma?

Is it possible to have a tuple contain only one tuple without the comma? Question: Can I have a tuple that contains just one tuple (without any additional commas) like the following: ((0,1)) I know that if I do the following, this works (kind of): final_tuple = () input_tuple = (0,1) final_tuple = ((input_tuple,)) print(str(final_tuple)) …

Total answers: 1

Linked list problem (Leetcode) – understanding inputs

Linked list problem (Leetcode) – understanding inputs Question: I am starting to complete some Leetcode problems, having finished an online Data Structures and Algorithms course, but I’m struggling to understand what some of the input variables represent. I’ve included one of the solutions as an example. The problem gives me the head of a sorted …

Total answers: 1

How to represent graph's node/vertex as alphabetic or name value instead of numeric

How to represent graph's node/vertex as alphabetic or name value instead of numeric Question: This is the code I wrote for Graph structure, which works in the value passed in numeric class Graph: def __init__(self, nVertices): self.nVertices = nVertices self.adjList = [[]for i in range(nVertices)] def addEdge(self, v1, v2): self.adjList[v1].append(v2) self.adjList[v2].append(v1) def dfs(self, sv, visited): …

Total answers: 1

Binary search tree lazy deletion Python

Binary search tree lazy deletion Python Question: I’ve created a binary search tree class and I’m trying to get a grasp on how "lazy deletion" works. I’ve set a flag in order to show if a node has been removed. When I search for a value that I want to remove, self.removed would be marked …

Total answers: 1

Deletion in queue from front in Python

Deletion in queue from front in Python Question: I have written a program for implementaion of queue using Python. Insertion and display of the queue works fine. But I can’t delete element from front of queue. I have tried del keyword as well as pop method. In both the ways, the element is deleted from …

Total answers: 1

Understanding time/space complexity for Leetcode 1366

Understanding time/space complexity for Leetcode 1366 Question: I’ve solved leetcode 1366 but having some trouble approximating the proper time/space complexity. I’ve looked at the solutions tab but answers vary and I’m not sure if I buy some of them. Here is my code and the general algorithm – class Solution: def rankTeams(self, votes: List[str]) -> …

Total answers: 1

Linked List, can't acess the data from NEXT NODE

Linked List, can't acess the data from NEXT NODE Question: My problem is at the display function, I can’t access the value cur_node.data which is a reference to node.next.data. I’m new to python and I’m trying to learn Linked LISTS, this code is from an old VIDEO which is why it probably isn’t working My …

Total answers: 1