Search found 58 matches

by Phantom
8 years ago
Forum: Algorithms
Topic: DFS
Replies: 2
Views: 3050
Gender: None specified

DFS

Here an example of DFS in Python: def DFS(graph, pos): marks = [False] * len(graph) marks[pos] = True for i in __DFS(graph, pos, marks):yield i def __DFS(graph, pos, marks): for i in graph[pos]: if not marks[i]: marks[i] = True yield i for j in __DFS(graph, i, marks):yield j #Example: graph = [[3], ...
by Phantom
8 years ago
Forum: Algorithms
Topic: BFS
Replies: 2
Views: 3114
Gender: None specified

BFS

Here an example of BFS in Python(my implementation): def BFS(graph, pos): queue, mark = [pos], [False] * len(graph) mark[pos] = True while queue: act = queue.pop(0) for i in graph[act]: if not mark[i]: queue.append(i) mark[i] = True yield i #Example: graph = [[3], [0, 2, 5], [3, 4], [1, 0], [5, 3], ...
by Phantom
8 years ago
Forum: Other languages
Topic: Python
Replies: 36
Views: 33524
Gender: None specified

Re: Python

Is very easy answering that question, and at the same time, is very large. In few words I can say you that Python have a very simple syntax (more than Java, C, C++, C#, …) seem pseudo code. You do many things in less code. Is a language very simple and less dense than Java. This language is complex ...
by Phantom
8 years ago
Forum: Problem set
Topic: 1201 - Select Your Ropes
Replies: 3
Views: 671
Gender: None specified

Re: 1201 - Select Your Ropes

Please... Some body can explain me this exercise??... Because I cannot understand it very well yet... I suppose...
I thought the output in this exercise must be:
3
20

I have got only Wrong Answers in this foolish.
by Phantom
8 years ago
Forum: Other languages
Topic: Ruby
Replies: 23
Views: 21085
Gender: None specified

Ruby IDE´s

In my computer I have Windows 7 and Ubuntu 12.04 (Linux), and in the two operative systems I use the same IDE (I mean I have the versions for Linux and for Windows) to program in Ruby, Java, C, C++ and Python. For the first 4 languages mentioned, I use Netbean 6.8 and PyCharm 2.5 for program in Pyth...
by Phantom
8 years ago
Forum: Other languages
Topic: Python
Replies: 36
Views: 33524
Gender: None specified

Decorator

No, you use the “@” only to say that you are using that function as a decorator. The problem in the decorator is that they receives another function, and return a new one, and that new function is the function that will replace the old one. You must understand only that, and you will understand deco...
by Phantom
8 years ago
Forum: Other languages
Topic: Python
Replies: 36
Views: 33524
Gender: None specified

Re: Python

Ok, as always... You always learn something new with me!! :D See the decorators as a function that transforms other functions. For example, @staticmethod, or... If you want a property with "get" only, you can do this: @property def Prop(self): ----"""This is an example of a "get" of a property""" #D...
by Phantom
8 years ago
Forum: Other languages
Topic: Ruby
Replies: 23
Views: 21085
Gender: None specified

Re: Ruby

In the previous post I wrote how you can read variables from the keyboard in ruby, but, fine, I´ll repat it. In Ruby you read with "gets" and the string have methods to convert to "int" or to other types: For example, to convert a string to int: pepe = "45" pepe = pepe.to_i #Now pepe is equal to 45(...
by Phantom
8 years ago
Forum: Algorithms
Topic: Binary Search Tree
Replies: 1
Views: 2668
Gender: None specified

Binary Search Tree

Here is my implementation of a Binary Search Tree in Python. You can post your implementation in another language or… if you want… A AVL or Black Red Tree or... a B-Tree!! My Binary Search Tree is a normal BST…: class ABB(object): ----def __init__(self, value=None, __father=None): --------self.__lef...
by Phantom
8 years ago
Forum: Algorithms
Topic: HEAP
Replies: 1
Views: 2928
Gender: None specified

HEAP

Here is my implementation of a HEAP in Python. You can post your implementation in another language or… if you want… A Fibonacci HEAP!! My HEAP is the normal HEAP…: class Heap: ----def __init__(self): --------self.Values, self.Count = [], 0 ----def __HeapifyTop(self, pos): --------fatherPos = int((p...

Go to advanced search