Problem Solving with Algorithms and Data Structures

Few chapter wise pickings from Problem Solving with Algorithms and Data Structures by Brad Miller, David Ranum.

  • Algorithm, a step-by-step list of instructions for solving any instance of the problem that might arise. Algorithms are finite processes that if followed will solve the problem. Algorithms are solutions.
  • Computer science can be thought of as the study of algorithms. However, we must be careful to include the fact that some problems may not have a solution. Although proving this statement is beyond the scope of this text, the fact that some problems cannot be solved is important for those who study computer science. We can fully define computer science, then, by including both types of problems and stating that computer science is the study of solutions to problems as well as the study of problems with no solutions.
  • A Python variable is created when a name is used for the first time on the left-hand side of an assignment statement. Assignment statements provide a way to associate a name with a value.
  • A Python variable is created when a name is used for the first time on the left-hand side of an assignment statement.
  • split will be very useful for processing data. split will take a string and return a list of strings using the split character as a division point. In the example, v is the division point. If no division is specified, the split method looks for whitespace characters such as tab, newline and space.

 

Although I know the following figures, I feel like adding these to this blog post.plot

 

 

list

 

Dict.PNG

 

  • In some rare cases the contains, get item, and set item operations can degenerate into 𝑂(𝑛) performance
  • Like the robots of Asimov, all recursive algorithms must obey three important laws:
    1. A recursive algorithm must have a base case.
    2. A recursive algorithm must change its state and move toward the base case.
    3. A recursive algorithm must call itself, recursively.
  • Sierpinski Triangle.
  • JSON syntax is based around three simple data types. The first is a Name-Value pair which in a programming language could be realised as an object, record, struct, dictionary, hash table, keyed list, or associative array. A name-value pair looks as follows:
    "first_name" : "Jacob"
    The second type is the JSON Object. A JSON Object is a collection of name-value pairs or Arrays encased in curly brackets.
    { "first_name":"Jacob" , "last_name":"Bellamy" }
    Lastly, we have the JSON Array. A JSON Array roughly corresponds to a list in python. A JSON array is a list of values encased in square brackets. For example:
    {"courses": ["Compsci 101", "Compsci 105", "Compsci 107"]}
  • Python provides us with a very powerful function to use when creating an iterator. The function is called yield. yield is similar to return in that it returns a value to the caller. However, yield also takes the additional step of freezing the state of the function so that the next time the function is called it continues executing from the exact point it left off earlier. Functions that create objects that can be iterated are called generator functions.

 

#python, #reading