Data Structures in Python: Singly Linked Lists -- Count Occurrences

preview_player
Показать описание
In this video, we investigate how to count the occurrence of nodes with a specified data element. We consider how one may solve this problem in both an iterative and recursive manner, and we code up the solution to both of these approaches in Python.

The software written in this video is available at:

Do you like the development environment I'm using in this video? It's a customized version of vim that's enhanced for Python development. If you want to see how I set up my vim, I have a series on this here:

If you've found this video helpful and want to stay up-to-date with the latest videos posted on this channel, please subscribe:
Рекомендации по теме
Комментарии
Автор

Yet another excellent video. Thank you.

davidrowlands
Автор

Excellent series. You've really made great efforts.

prachinainawa
Автор

Hi Lucid thanks for this awesome videos, I am self learning programmer, looking to go into backend development/Machine learning using Python and have set a target of 1 year for myself to be good enough for a junior developer role.
I had earlier struggled with really understanding the thought process like a real software engineer and realised I had to become grounded in Data structures and algorithms but I found learning that very boring and difficult.
Your videos have helped me greatly as I gradually become more comfortable with this software engineering space.
I am currently working through your data structures videos and hope to follow that up with the algorithms playlist.
What other resources/topics would you recommend for me to look into when I am done with your data structures and algorithm playlist.
Thanks

olayemiolatinwo
Автор

thanks!

I solved doing the following:


def count_all_occurences(self):
values = dict()
current_node = self.head
while current_node:
if current_node.data in values:
values[current_node.data] += 1
else:
values[current_node.data] = 1
current_node = current_node.next
return values

def count_occurences(self, data):
occurences = self.count_all_occurences()
return occurences[data]


any thoughts on my procedure?

mulhamjarjanazi
Автор

please rectify if i overlooked something


def count_occurn_iter(self, data):
o = dict()#bug
cur = self.head
while cur:
if cur.data not in o:
o[cur.data] = 1
else:
o[cur.data] += 1
cur = cur.next
try:
return o[data]
except:
return 0

anuraagsaraswat
Автор

Do you know how I can improve my ability to convert iterative programs to recursive ones? I tried coding this before watching the solution. I was able to do the iterative one without any difficulty. However, recursive solution i wasn't able to come up with. Thanks for these amazing videos!

anoubhav
Автор

can you help me getting occurrence of every node in one algorithm.?

debashishchakraborty
join shbcf.ru