Giter Site home page Giter Site logo

hands-on-data-structures-and-algorithms-with-python-third-edition's Introduction

Hands-On Data-Structures-and-Algorithms-with-Python-Third-Edition-published-by-Packt

Hands-On Data Structures and Algorithms with Python – Third Edition

Download a free PDF

If you have already purchased a print or Kindle version of this book, you can get a DRM-free PDF version at no cost.
Simply click on the link to claim your free PDF.

https://packt.link/free-ebook/9781801073448

hands-on-data-structures-and-algorithms-with-python-third-edition's People

Contributors

anikets-cpu avatar packt-itservice avatar packtriannar avatar sonawane-karan26 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

hands-on-data-structures-and-algorithms-with-python-third-edition's Issues

Chapter 5 pop function wrong

In chapter 5 you recreate pop(). The code de-increment top by 1, then changing top value to 0. It needs to be switched like so.

def pop():
global top
if top == -1:
print("Stack Underflow")
else:
data[top] = 0
top = top - 1
return data[top+1]

(formatting is not being kept sorry for sloppy indents)

chapter 4 linked list code snippet in the book is wrong

class SinglyLinkedList:
    def __init__ (self):
        self.tail = None
        self.head = None
        self.size = 0
    def append_at_a_location(self, data, index): 
        current = self.head 
        prev = self.head 
        node = Node(data)
        count = 1
        while current:
            if count == 1:        
                node.next = current
                self.head = node
                print(count)
                return
            elif index == index:
                node.next = current 
                prev.next = node
                return
            count += 1
            prev = current
            current = current.next
        if count < index:
            print("The list has less number of elements")

this code snippet can't demo the concept of inserting new element at a given index. instead, it always insert the new element at the beginning of the list.

please correctify this error.

thanks

ZeroDivisionError is raised in interpolation search

With the current implementation of interpolation search, ZeroDivisionError raises.

Here is an example:

def nearest_mid(input_list, low_index, upper_index, search_value):
    mid = low_index + (
        (upper_index - low_index) / (input_list[upper_index] - input_list[low_index])
    ) * (search_value - input_list[low_index])
    return int(mid)


def interpolation_search(ordered_list, search_value):
    low_index = 0
    upper_index = len(ordered_list) - 1
    while low_index <= upper_index:
        mid_point = nearest_mid(ordered_list, low_index, upper_index, search_value)
        if mid_point > upper_index or mid_point < low_index:
            return None
        if ordered_list[mid_point] == search_value:
            return mid_point
        if search_value > ordered_list[mid_point]:
            low_index = mid_point + 1
        else:
            upper_index = mid_point - 1
    if low_index > upper_index:
        return None


list1 = [44, 60, 75, 100, 120, 230, 250]
print(interpolation_search(list1, 231))

output:

Traceback (most recent call last):
  File "", line 26, in <module>
    print(interpolation_search(list1, 231))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "", line 12, in interpolation_search
    mid_point = nearest_mid(ordered_list, low_index, upper_index, search_value)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "", line 3, in nearest_mid
    (upper_index - low_index) / (input_list[upper_index] - input_list[low_index])
    ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ZeroDivisionError: division by zero

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.